From 53075d236a8c98c0251db58d70bc415a1478e122 Mon Sep 17 00:00:00 2001 From: carlfeynman Date: Wed, 13 Sep 2023 09:35:01 +0530 Subject: [PATCH] ipynb to py conversion process added --- mnist.ipynb | 33 +++++++++--- mnist.py | 146 +--------------------------------------------------- 2 files changed, 27 insertions(+), 152 deletions(-) diff --git a/mnist.ipynb b/mnist.ipynb index 6896f2d..a4c90fd 100644 --- a/mnist.ipynb +++ b/mnist.ipynb @@ -145,6 +145,7 @@ "metadata": {}, "outputs": [], "source": [ + "# model definition\n", "def linear_classifier():\n", " return nn.Sequential(\n", " Reshape((-1, 784)),\n", @@ -209,7 +210,11 @@ { "cell_type": "code", "execution_count": 31, - "metadata": {}, + "metadata": { + "tags": [ + "exclude" + ] + }, "outputs": [], "source": [ "# with open('./linear_classifier.pkl', 'wb') as model_file:\n", @@ -218,33 +223,47 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [ + "exclude" + ] + }, "source": [ "#### commit to .py file for deployment" ] }, { "cell_type": "code", - "execution_count": 33, - "metadata": {}, + "execution_count": 43, + "metadata": { + "tags": [ + "exclude" + ] + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[NbConvertApp] Converting notebook mnist.ipynb to script\n", - "[NbConvertApp] Writing 6388 bytes to mnist.py\n" + "[NbConvertApp] Writing 3123 bytes to mnist.py\n" ] } ], "source": [ - "!jupyter nbconvert --to script mnist.ipynb" + "# !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": {}, + "metadata": { + "tags": [ + "exclude" + ] + }, "outputs": [], "source": [ "# from IPython.display import HTML, display, Image\n", diff --git a/mnist.py b/mnist.py index 32d0957..e7a2d72 100644 --- a/mnist.py +++ b/mnist.py @@ -1,9 +1,6 @@ #!/usr/bin/env python # coding: utf-8 -# In[1]: - - import torch from torch import nn import torch.nn.functional as F @@ -19,17 +16,11 @@ plt.rcParams['figure.figsize'] = [2, 2] -# In[2]: - - dataset_nm = 'mnist' x,y = 'image', 'label' ds = load_dataset(dataset_nm) -# In[3]: - - def transform_ds(b): b[x] = [TF.to_tensor(ele) for ele in b[x]] return b @@ -38,9 +29,6 @@ def transform_ds(b): plt.imshow(dst['train'][0]['image'].permute(1,2,0)); -# In[4]: - - bs = 1024 class DataLoaders: def __init__(self, train_ds, valid_ds, bs, collate_fn, **kwargs): @@ -56,9 +44,6 @@ def collate_fn(b): xb.shape, yb.shape -# In[5]: - - class Reshape(nn.Module): def __init__(self, dim): super().__init__() @@ -68,9 +53,6 @@ def forward(self, x): return x.reshape(self.dim) -# In[6]: - - def cnn_classifier(): ks,stride = 3,2 return nn.Sequential( @@ -89,9 +71,7 @@ def cnn_classifier(): ) -# In[7]: - - +# model definition def linear_classifier(): return nn.Sequential( Reshape((-1, 784)), @@ -103,9 +83,6 @@ def linear_classifier(): ) -# In[8]: - - model = linear_classifier() lr = 0.1 max_lr = 0.1 @@ -133,128 +110,7 @@ def linear_classifier(): -# In[31]: - - -# with open('./linear_classifier.pkl', 'wb') as model_file: -# pickle.dump(model, model_file) - - -# #### commit to .py file for deployment - -# In[32]: - - -get_ipython().system('jupyter nbconvert --to script mnist.ipynb') - - -# In[29]: - - -get_ipython().system('pip3 install markupsafe') - - - -# In[ ]: - - -# from IPython.display import HTML, display, Image -# %%html -# -#
-# -#
-# -# -#
- -#
-# - - -# In[ ]: - - - - -# In[ ]: