From 04ab4e71ff753c4ddd6611b7613a766510a4cf6e Mon Sep 17 00:00:00 2001 From: Ben Eyal Date: Fri, 27 May 2022 15:18:28 +0300 Subject: [PATCH] Fix some formatting and typos --- 06_pytorch_transfer_learning.ipynb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/06_pytorch_transfer_learning.ipynb b/06_pytorch_transfer_learning.ipynb index c4d6c2b..988e5f5 100644 --- a/06_pytorch_transfer_learning.ipynb +++ b/06_pytorch_transfer_learning.ipynb @@ -151,13 +151,12 @@ "metadata": {}, "outputs": [], "source": [ + "import matplotlib.pyplot as plt\n", "import torch\n", "import torchvision\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", "\n", "from torch import nn\n", - "from torchvision import transforms, datasets\n", + "from torchvision import transforms\n", "\n", "# Try to get torchinfo, install it if it doesn't work\n", "try:\n", @@ -244,11 +243,12 @@ ], "source": [ "import os\n", - "import requests\n", "import zipfile\n", "\n", "from pathlib import Path\n", "\n", + "import requests\n", + "\n", "# Setup path to data folder\n", "data_path = Path(\"data/\")\n", "image_path = data_path / \"pizza_steak_sushi\"\n", @@ -332,7 +332,7 @@ ">\n", "> ```\n", "> normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],\n", - " std=[0.229, 0.224, 0.225])\n", + "> std=[0.229, 0.224, 0.225])\n", "> ```\n", "\n", "The good news is, we can achieve the above transformations with a combination of: \n", @@ -460,7 +460,7 @@ "\n", "You might think better performance is *always better*, right?\n", "\n", - "That's true but **some better performaning models are too big for some devices**.\n", + "That's true but **some better performing models are too big for some devices**.\n", "\n", "For example, say you'd like to run your model on a mobile-device, you'll have to take into account the limited compute resources on the device, thus you'd be looking for a smaller model.\n", "\n", @@ -649,7 +649,7 @@ "\n", "We'll keep the `Dropout` layer the same using [`torch.nn.Dropout(p=0.2, inplace=True)`](https://pytorch.org/docs/stable/generated/torch.nn.Dropout.html).\n", "\n", - "> **Note:** [Dropout layers](https://developers.google.com/machine-learning/glossary#dropout_regularization) randomly remove connections between two neural network layers with a probability of `p`. For example, if `p=0.2`, 20% of connections between neural network layers will be removed at random each pass. This practice is meant to help to regularize (prevent overfitting) a model by making sure the connections that remain learn features to compensate for the removal of the other connections (hopefully these remaining features are *more general*). \n", + "> **Note:** [Dropout layers](https://developers.google.com/machine-learning/glossary#dropout_regularization) randomly remove connections between two neural network layers with a probability of `p`. For example, if `p=0.2`, 20% of connections between neural network layers will be removed at random each pass. This practice is meant to help regularize (prevent overfitting) a model by making sure the connections that remain learn features to compensate for the removal of the other connections (hopefully these remaining features are *more general*). \n", "\n", "And we'll keep `in_features=1280` for our `Linear` output layer but we'll change the `out_features` value to the length of our `class_names` (`len(['pizza', 'steak', 'sushi']) = 3`).\n", "\n", @@ -953,14 +953,15 @@ "metadata": {}, "outputs": [], "source": [ - "from PIL import Image\n", "from typing import List, Tuple\n", "\n", + "from PIL import Image\n", + "\n", "# 1. Take in a trained model, class names, image path, image size, a transform and target device\n", "def pred_and_plot_image(model: torch.nn.Module,\n", " class_names: List[str],\n", " image_path: str, \n", - " image_size: Tuple[int, int]=(224, 224),\n", + " image_size: Tuple[int, int] = (224, 224),\n", " transform: torchvision.transforms = None,\n", " device: torch.device=device):\n", " \n",