{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import torch\n", "from torch import nn\n", "import torch.nn.functional as F\n", "from datasets import load_dataset\n", "import fastcore.all as fc\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "import torchvision.transforms.functional as TF\n", "from torch.utils.data import default_collate, DataLoader\n", "import torch.optim as optim\n", "import pickle\n", "%matplotlib inline\n", "plt.rcParams['figure.figsize'] = [2, 2]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Found cached dataset mnist (/Users/arun/.cache/huggingface/datasets/mnist/mnist/1.0.0/9d494b7f466d6931c64fb39d58bb1249a4d85c9eb9865d9bc20960b999e2a332)\n", "100%|██████████| 2/2 [00:00<00:00, 69.76it/s]\n" ] } ], "source": [ "dataset_nm = 'mnist'\n", "x,y = 'image', 'label'\n", "ds = load_dataset(dataset_nm)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI4AAACOCAYAAADn/TAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAIsUlEQVR4nO3df2yU9R0H8PfHtrQroFJBVrGjHVRAweHWCASCJBuumiXOLAyYWTbjQiYy58Y2fmzZ5oILJgsJMjSRrCsmig7mAjFsZBIlLkNGdeBgrOWnWqnFwkDmUNrrZ3/0bPu59cfTz3P33NPr+5WQu89zd32+MW+/z/eeu+dzoqogGqgrsj0AGpwYHHJhcMiFwSEXBodcGBxyCRUcEakWkXoROSYiK9M1KIo/8Z7HEZE8AA0A5gNoBLAfwGJV/Wf6hkdxlR/itbcCOKaqJwBARJ4FcBeAXoMzTAq1CMND7JKidhH/blHVManbwwRnHIC3u9WNAGb09YIiDMcM+XyIXVLU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OOTC4JBLpJ9Vich7AN4EMBqAv09IZnFs1nhVHZO6MdLgdO5UpK6nD87igGMLhocqcmFwyCVbwXkyS/sNgmMLICtrHBr8eKgil0iDIyLVIlIvIsdEJKvtbUWkRkTOiMihbtti0bt5MPSWjiw4IpIHYCOAOwDcCGBxsl9yttQCqE7ZFpfezfHvLa2qkfwDMAvArm71KgCrotp/L2MqB3CoW10PoDR5vxRAfTbH121c2wHMj9P4ojxUjQPwdre6MbktTmLXuzmuvaWjDE5PfQT5lq4P3t7SUYgyOI0AyrrV1wM4HeH+gwjUuzkKYXpLRyHK4OwHUCkiFSIyDMAidPRKjpOPezcDWezdHKC3NJDt3tIRL/LuBNAA4DiAH2d5wbkFHT9u0oqO2fA+ANeg493K0eRtSZbGNgcdh/E3ABxI/rszLuNTVZ45Jh+eOSYXBodcGBxyYXDIhcEhFwaHXBgccmFwyOV/atVD7hyCzrEAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "def transform_ds(b):\n", " b[x] = [TF.to_tensor(ele) for ele in b[x]]\n", " return b\n", "\n", "dst = ds.with_transform(transform_ds)\n", "plt.imshow(dst['train'][0]['image'].permute(1,2,0));" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(torch.Size([1024, 1, 28, 28]), torch.Size([1024]))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bs = 1024\n", "class DataLoaders:\n", " def __init__(self, train_ds, valid_ds, bs, collate_fn, **kwargs):\n", " self.train = DataLoader(train_ds, batch_size=bs, shuffle=True, collate_fn=collate_fn, **kwargs)\n", " self.valid = DataLoader(train_ds, batch_size=bs*2, shuffle=False, collate_fn=collate_fn, **kwargs)\n", "\n", "def collate_fn(b):\n", " collate = default_collate(b)\n", " return (collate[x], collate[y])\n", "\n", "dls = DataLoaders(dst['train'], dst['test'], bs=bs, collate_fn=collate_fn)\n", "xb,yb = next(iter(dls.train))\n", "xb.shape, yb.shape" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "class Reshape(nn.Module):\n", " def __init__(self, dim):\n", " super().__init__()\n", " self.dim = dim\n", " \n", " def forward(self, x):\n", " return x.reshape(self.dim)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "# model definition\n", "def linear_classifier():\n", " return nn.Sequential(\n", " Reshape((-1, 784)),\n", " nn.Linear(784, 50),\n", " nn.ReLU(),\n", " nn.Linear(50, 50),\n", " nn.ReLU(),\n", " nn.Linear(50, 10)\n", " )" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "train, epoch:1, loss: 0.2640, accuracy: 0.7885\n", "eval, epoch:1, loss: 0.3039, accuracy: 0.8994\n", "train, epoch:2, loss: 0.2368, accuracy: 0.9182\n", "eval, epoch:2, loss: 0.2164, accuracy: 0.9350\n", "train, epoch:3, loss: 0.1951, accuracy: 0.9402\n", "eval, epoch:3, loss: 0.1589, accuracy: 0.9498\n", "train, epoch:4, loss: 0.1511, accuracy: 0.9513\n", "eval, epoch:4, loss: 0.1388, accuracy: 0.9618\n", "train, epoch:5, loss: 0.1182, accuracy: 0.9567\n", "eval, epoch:5, loss: 0.1426, accuracy: 0.9621\n" ] } ], "source": [ "model = linear_classifier()\n", "lr = 0.1\n", "max_lr = 0.1\n", "epochs = 5\n", "opt = optim.AdamW(model.parameters(), lr=lr)\n", "sched = optim.lr_scheduler.OneCycleLR(opt, max_lr, total_steps=len(dls.train), epochs=epochs)\n", "\n", "for epoch in range(epochs):\n", " for train in (True, False):\n", " accuracy = 0\n", " dl = dls.train if train else dls.valid\n", " for xb,yb in dl:\n", " preds = model(xb)\n", " loss = F.cross_entropy(preds, yb)\n", " if train:\n", " loss.backward()\n", " opt.step()\n", " opt.zero_grad()\n", " with torch.no_grad():\n", " accuracy += (preds.argmax(1).detach().cpu() == yb).float().mean()\n", " if train:\n", " sched.step()\n", " accuracy /= len(dl)\n", " print(f\"{'train' if train else 'eval'}, epoch:{epoch+1}, loss: {loss.item():.4f}, accuracy: {accuracy:.4f}\")\n", " " ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "tags": [ "exclude" ] }, "outputs": [], "source": [ "with open('./mlp_classifier.pkl', 'wb') as model_file:\n", " pickle.dump(model, model_file)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "def cnn_classifier():\n", " ks,stride = 3,2\n", " return nn.Sequential(\n", " nn.Conv2d(1, 8, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.BatchNorm2d(8),\n", " nn.ReLU(),\n", " nn.Conv2d(8, 16, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.BatchNorm2d(16),\n", " nn.ReLU(),\n", " nn.Conv2d(16, 32, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.BatchNorm2d(32),\n", " nn.ReLU(),\n", " nn.Conv2d(32, 64, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.BatchNorm2d(64),\n", " nn.ReLU(),\n", " nn.Conv2d(64, 64, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.BatchNorm2d(64),\n", " nn.ReLU(),\n", " nn.Conv2d(64, 10, kernel_size=ks, stride=stride, padding=ks//2),\n", " nn.Flatten(),\n", " )" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "def kaiming_init(m):\n", " if isinstance(m, (nn.Conv1d, nn.Conv2d, nn.Conv3d)):\n", " nn.init.kaiming_normal_(m.weight)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "train, epoch:1, loss: 0.1096, accuracy: 0.9145\n", "eval, epoch:1, loss: 0.1383, accuracy: 0.9774\n", "train, epoch:2, loss: 0.0487, accuracy: 0.9808\n", "eval, epoch:2, loss: 0.0715, accuracy: 0.9867\n", "train, epoch:3, loss: 0.0536, accuracy: 0.9840\n", "eval, epoch:3, loss: 0.0499, accuracy: 0.9896\n", "train, epoch:4, loss: 0.0358, accuracy: 0.9842\n", "eval, epoch:4, loss: 0.0474, accuracy: 0.9893\n", "train, epoch:5, loss: 0.0514, accuracy: 0.9852\n", "eval, epoch:5, loss: 0.0579, accuracy: 0.9886\n" ] } ], "source": [ "model = cnn_classifier()\n", "model.apply(kaiming_init)\n", "lr = 0.1\n", "max_lr = 0.3\n", "epochs = 5\n", "opt = optim.AdamW(model.parameters(), lr=lr)\n", "sched = optim.lr_scheduler.OneCycleLR(opt, max_lr, total_steps=len(dls.train), epochs=epochs)\n", "\n", "for epoch in range(epochs):\n", " for train in (True, False):\n", " accuracy = 0\n", " dl = dls.train if train else dls.valid\n", " for xb,yb in dl:\n", " preds = model(xb)\n", " loss = F.cross_entropy(preds, yb)\n", " if train:\n", " loss.backward()\n", " opt.step()\n", " opt.zero_grad()\n", " with torch.no_grad():\n", " accuracy += (preds.argmax(1).detach().cpu() == yb).float().mean()\n", " if train:\n", " sched.step()\n", " accuracy /= len(dl)\n", " print(f\"{'train' if train else 'eval'}, epoch:{epoch+1}, loss: {loss.item():.4f}, accuracy: {accuracy:.4f}\")\n", " " ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "tags": [ "exclude" ] }, "outputs": [], "source": [ "with open('./cnn_classifier.pkl', 'wb') as model_file:\n", " pickle.dump(model, model_file)" ] }, { "cell_type": "markdown", "metadata": { "tags": [ "exclude" ] }, "source": [ "#### commit to .py file for deployment" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "exclude" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[NbConvertApp] WARNING | pattern 'mnist.ipynb' matched no files\n", "This application is used to convert notebook files (*.ipynb)\n", " to various other formats.\n", "\n", " WARNING: THE COMMANDLINE INTERFACE MAY CHANGE IN FUTURE RELEASES.\n", "\n", "Options\n", "=======\n", "The options below are convenience aliases to configurable class-options,\n", "as listed in the \"Equivalent to\" description-line of the aliases.\n", "To see all configurable class-options for some , use:\n", " --help-all\n", "\n", "--debug\n", " set log level to logging.DEBUG (maximize logging output)\n", " Equivalent to: [--Application.log_level=10]\n", "--show-config\n", " Show the application's configuration (human-readable format)\n", " Equivalent to: [--Application.show_config=True]\n", "--show-config-json\n", " Show the application's configuration (json format)\n", " Equivalent to: [--Application.show_config_json=True]\n", "--generate-config\n", " generate default config file\n", " Equivalent to: [--JupyterApp.generate_config=True]\n", "-y\n", " Answer yes to any questions instead of prompting.\n", " Equivalent to: [--JupyterApp.answer_yes=True]\n", "--execute\n", " Execute the notebook prior to export.\n", " Equivalent to: [--ExecutePreprocessor.enabled=True]\n", "--allow-errors\n", " Continue notebook execution even if one of the cells throws an error and include the error message in the cell output (the default behaviour is to abort conversion). This flag is only relevant if '--execute' was specified, too.\n", " Equivalent to: [--ExecutePreprocessor.allow_errors=True]\n", "--stdin\n", " read a single notebook file from stdin. Write the resulting notebook with default basename 'notebook.*'\n", " Equivalent to: [--NbConvertApp.from_stdin=True]\n", "--stdout\n", " Write notebook output to stdout instead of files.\n", " Equivalent to: [--NbConvertApp.writer_class=StdoutWriter]\n", "--inplace\n", " Run nbconvert in place, overwriting the existing notebook (only\n", " relevant when converting to notebook format)\n", " Equivalent to: [--NbConvertApp.use_output_suffix=False --NbConvertApp.export_format=notebook --FilesWriter.build_directory=]\n", "--clear-output\n", " Clear output of current file and save in place,\n", " overwriting the existing notebook.\n", " Equivalent to: [--NbConvertApp.use_output_suffix=False --NbConvertApp.export_format=notebook --FilesWriter.build_directory= --ClearOutputPreprocessor.enabled=True]\n", "--no-prompt\n", " Exclude input and output prompts from converted document.\n", " Equivalent to: [--TemplateExporter.exclude_input_prompt=True --TemplateExporter.exclude_output_prompt=True]\n", "--no-input\n", " Exclude input cells and output prompts from converted document.\n", " This mode is ideal for generating code-free reports.\n", " Equivalent to: [--TemplateExporter.exclude_output_prompt=True --TemplateExporter.exclude_input=True --TemplateExporter.exclude_input_prompt=True]\n", "--allow-chromium-download\n", " Whether to allow downloading chromium if no suitable version is found on the system.\n", " Equivalent to: [--WebPDFExporter.allow_chromium_download=True]\n", "--disable-chromium-sandbox\n", " Disable chromium security sandbox when converting to PDF..\n", " Equivalent to: [--WebPDFExporter.disable_sandbox=True]\n", "--show-input\n", " Shows code input. This flag is only useful for dejavu users.\n", " Equivalent to: [--TemplateExporter.exclude_input=False]\n", "--embed-images\n", " Embed the images as base64 dataurls in the output. This flag is only useful for the HTML/WebPDF/Slides exports.\n", " Equivalent to: [--HTMLExporter.embed_images=True]\n", "--sanitize-html\n", " Whether the HTML in Markdown cells and cell outputs should be sanitized..\n", " Equivalent to: [--HTMLExporter.sanitize_html=True]\n", "--log-level=\n", " Set the log level by value or name.\n", " Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']\n", " Default: 30\n", " Equivalent to: [--Application.log_level]\n", "--config=\n", " Full path of a config file.\n", " Default: ''\n", " Equivalent to: [--JupyterApp.config_file]\n", "--to=\n", " The export format to be used, either one of the built-in formats\n", " ['asciidoc', 'custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'qtpdf', 'qtpng', 'rst', 'script', 'slides', 'webpdf']\n", " or a dotted object name that represents the import path for an\n", " ``Exporter`` class\n", " Default: ''\n", " Equivalent to: [--NbConvertApp.export_format]\n", "--template=\n", " Name of the template to use\n", " Default: ''\n", " Equivalent to: [--TemplateExporter.template_name]\n", "--template-file=\n", " Name of the template file to use\n", " Default: None\n", " Equivalent to: [--TemplateExporter.template_file]\n", "--theme=\n", " Template specific theme(e.g. the name of a JupyterLab CSS theme distributed\n", " as prebuilt extension for the lab template)\n", " Default: 'light'\n", " Equivalent to: [--HTMLExporter.theme]\n", "--sanitize_html=\n", " Whether the HTML in Markdown cells and cell outputs should be sanitized.This\n", " should be set to True by nbviewer or similar tools.\n", " Default: False\n", " Equivalent to: [--HTMLExporter.sanitize_html]\n", "--writer=\n", " Writer class used to write the\n", " results of the conversion\n", " Default: 'FilesWriter'\n", " Equivalent to: [--NbConvertApp.writer_class]\n", "--post=\n", " PostProcessor class used to write the\n", " results of the conversion\n", " Default: ''\n", " Equivalent to: [--NbConvertApp.postprocessor_class]\n", "--output=\n", " Overwrite base name use for output files.\n", " Supports pattern replacements '{notebook_name}'.\n", " Default: '{notebook_name}'\n", " Equivalent to: [--NbConvertApp.output_base]\n", "--output-dir=\n", " Directory to write output(s) to. Defaults\n", " to output to the directory of each notebook. To recover\n", " previous default behaviour (outputting to the current\n", " working directory) use . as the flag value.\n", " Default: ''\n", " Equivalent to: [--FilesWriter.build_directory]\n", "--reveal-prefix=\n", " The URL prefix for reveal.js (version 3.x).\n", " This defaults to the reveal CDN, but can be any url pointing to a copy\n", " of reveal.js.\n", " For speaker notes to work, this must be a relative path to a local\n", " copy of reveal.js: e.g., \"reveal.js\".\n", " If a relative path is given, it must be a subdirectory of the\n", " current directory (from which the server is run).\n", " See the usage documentation\n", " (https://nbconvert.readthedocs.io/en/latest/usage.html#reveal-js-html-slideshow)\n", " for more details.\n", " Default: ''\n", " Equivalent to: [--SlidesExporter.reveal_url_prefix]\n", "--nbformat=\n", " The nbformat version to write.\n", " Use this to downgrade notebooks.\n", " Choices: any of [1, 2, 3, 4]\n", " Default: 4\n", " Equivalent to: [--NotebookExporter.nbformat_version]\n", "\n", "Examples\n", "--------\n", "\n", " The simplest way to use nbconvert is\n", "\n", " > jupyter nbconvert mynotebook.ipynb --to html\n", "\n", " Options include ['asciidoc', 'custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'qtpdf', 'qtpng', 'rst', 'script', 'slides', 'webpdf'].\n", "\n", " > jupyter nbconvert --to latex mynotebook.ipynb\n", "\n", " Both HTML and LaTeX support multiple output templates. LaTeX includes\n", " 'base', 'article' and 'report'. HTML includes 'basic', 'lab' and\n", " 'classic'. You can specify the flavor of the format used.\n", "\n", " > jupyter nbconvert --to html --template lab mynotebook.ipynb\n", "\n", " You can also pipe the output to stdout, rather than a file\n", "\n", " > jupyter nbconvert mynotebook.ipynb --stdout\n", "\n", " PDF is generated via latex\n", "\n", " > jupyter nbconvert mynotebook.ipynb --to pdf\n", "\n", " You can get (and serve) a Reveal.js-powered slideshow\n", "\n", " > jupyter nbconvert myslides.ipynb --to slides --post serve\n", "\n", " Multiple notebooks can be given at the command line in a couple of\n", " different ways:\n", "\n", " > jupyter nbconvert notebook*.ipynb\n", " > jupyter nbconvert notebook1.ipynb notebook2.ipynb\n", "\n", " or you can specify the notebooks list in a config file, containing::\n", "\n", " c.NbConvertApp.notebooks = [\"my_notebook.ipynb\"]\n", "\n", " > jupyter nbconvert --config mycfg.py\n", "\n", "To see all available configurables, use `--help-all`.\n", "\n" ] } ], "source": [ "# !jupyter nbconvert --to script mnist.ipynb\n", "!jupyter nbconvert --to script --TagRemovePreprocessor.remove_cell_tags=\"exclude\" --TemplateExporter.exclude_input_prompt=True mnist.ipynb\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "exclude" ] }, "outputs": [], "source": [ "# from IPython.display import HTML, display, Image\n", "# %%html\n", "# \n", "#
\n", "# \n", "#
\n", "# \n", "# \n", "#
\n", "\n", "#
\n", "# \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "python_main", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }