Fix some formatting and typos

This commit is contained in:
Ben Eyal committed 2022-05-27 15:18:28 +03:00
1 parent 87e2c49f9c
commit 04ab4e71ff
1 file changed
+10 -9
+10 -9
View File
@@ -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",