From 9432e558cc737c536253dd38dfb6fa24b6684687 Mon Sep 17 00:00:00 2001 From: pritesh2000 Date: Mon, 19 Aug 2024 19:15:01 +0530 Subject: [PATCH] Update 06_pytorch_transfer_learning.ipynb --- 06_pytorch_transfer_learning.ipynb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/06_pytorch_transfer_learning.ipynb b/06_pytorch_transfer_learning.ipynb index a78392a..e5d4629 100644 --- a/06_pytorch_transfer_learning.ipynb +++ b/06_pytorch_transfer_learning.ipynb @@ -400,7 +400,7 @@ "| 3 | A mean of `[0.485, 0.456, 0.406]` (values across each colour channel). | `torchvision.transforms.Normalize(mean=...)` to adjust the mean of our images. |\n", "| 4 | A standard deviation of `[0.229, 0.224, 0.225]` (values across each colour channel). | `torchvision.transforms.Normalize(std=...)` to adjust the standard deviation of our images. | \n", "\n", - "> **Note:** ^some pretrained models from `torchvision.models` in different sizes to `[3, 224, 224]`, for example, some might take them in `[3, 240, 240]`. For specific input image sizes, see the documentation.\n", + "> **Note:** some pretrained models from `torchvision.models` in different sizes to `[3, 224, 224]`, for example, some might take them in `[3, 240, 240]`. For specific input image sizes, see the documentation.\n", "\n", "> **Question:** *Where did the mean and standard deviation values come from? Why do we need to do this?*\n", ">\n", @@ -495,7 +495,7 @@ "```\n", "\n", "Where,\n", - "* `EfficientNet_B0_Weights` is the model architecture weights we'd like to use (there are many differnt model architecture options in `torchvision.models`).\n", + "* `EfficientNet_B0_Weights` is the model architecture weights we'd like to use (there are many different model architecture options in `torchvision.models`).\n", "* `DEFAULT` means the *best available* weights (the best performance in ImageNet).\n", " * **Note:** Depending on the model architecture you choose, you may also see other options such as `IMAGENET_V1` and `IMAGENET_V2` where generally the higher version number the better. Though if you want the best available, `DEFAULT` is the easiest option. See the [`torchvision.models` documentation](https://pytorch.org/vision/main/models.html) for more.\n", " \n", @@ -530,7 +530,7 @@ "id": "cebcdf20-4ab7-40ba-8691-9d9af8962dab", "metadata": {}, "source": [ - "And now to access the transforms assosciated with our `weights`, we can use the `transforms()` method.\n", + "And now to access the transforms associated with our `weights`, we can use the `transforms()` method.\n", "\n", "This is essentially saying \"get the data transforms that were used to train the `EfficientNet_B0_Weights` on ImageNet\"." ] @@ -657,7 +657,7 @@ "\n", "But if you've got unlimited compute power, as [*The Bitter Lesson*](http://www.incompleteideas.net/IncIdeas/BitterLesson.html) states, you'd likely take the biggest, most compute hungry model you can.\n", "\n", - "Understanding this **performance vs. speed vs. size tradeoff** will come with time and practice.\n", + "Understanding this **performance vs. speed vs. size** tradeoff will come with time and practice.\n", "\n", "For me, I've found a nice balance in the `efficientnet_bX` models. \n", "\n", @@ -1267,7 +1267,7 @@ "* **Same shape** - If our images are different shapes to what our model was trained on, we'll get shape errors.\n", "* **Same datatype** - If our images are a different datatype (e.g. `torch.int8` vs. `torch.float32`) we'll get datatype errors.\n", "* **Same device** - If our images are on a different device to our model, we'll get device errors.\n", - "* **Same transformations** - If our model is trained on images that have been transformed in certain way (e.g. normalized with a specific mean and standard deviation) and we try and make preidctions on images transformed in a different way, these predictions may be off.\n", + "* **Same transformations** - If our model is trained on images that have been transformed in certain way (e.g. normalized with a specific mean and standard deviation) and we try and make predictions on images transformed in a different way, these predictions may be off.\n", "\n", "> **Note:** These requirements go for all kinds of data if you're trying to make predictions with a trained model. Data you'd like to predict on should be in the same format as your model was trained on.\n", "\n", @@ -1359,7 +1359,7 @@ "\n", "We can get a list of all the test image paths using `list(Path(test_dir).glob(\"*/*.jpg\"))`, the stars in the `glob()` method say \"any file matching this pattern\", in other words, any file ending in `.jpg` (all of our images).\n", "\n", - "And then we can randomly sample a number of these using Python's [`random.sample(populuation, k)`](https://docs.python.org/3/library/random.html#random.sample) where `population` is the sequence to sample and `k` is the number of samples to retrieve." + "And then we can randomly sample a number of these using Python's [`random.sample(population, k)`](https://docs.python.org/3/library/random.html#random.sample) where `population` is the sequence to sample and `k` is the number of samples to retrieve." ] }, { @@ -1445,7 +1445,7 @@ "\n", "That's where the real fun of machine learning is!\n", "\n", - "Predicting on your own custom data, outisde of any training or test set.\n", + "Predicting on your own custom data, outside of any training or test set.\n", "\n", "To test our model on a custom image, let's import the old faithful `pizza-dad.jpeg` image (an image of my dad eating pizza).\n", "\n", @@ -1521,7 +1521,7 @@ "metadata": {}, "source": [ "## Main takeaways\n", - "* **Transfer learning** often allows to you get good results with a relatively small amount of custom data.\n", + "* **Transfer learning** often allows you to get good results with a relatively small amount of custom data.\n", "* Knowing the power of transfer learning, it's a good idea to ask at the start of every problem, \"does an existing well-performing model exist for my problem?\"\n", "* When using a pretrained model, it's important that your custom data be formatted/preprocessed in the same way that the original model was trained on, otherwise you may get degraded performance.\n", "* The same goes for predicting on custom data, ensure your custom data is in the same format as the data your model was trained on.\n", @@ -1560,8 +1560,8 @@ " * You may want to try an EfficientNet with a higher number than our B0, perhaps `torchvision.models.efficientnet_b2()`?\n", " \n", "## Extra-curriculum\n", - "* Look up what \"model fine-tuning\" is and spend 30-minutes researching different methods to perform it with PyTorch. How would we change our code to fine-tine? Tip: fine-tuning usually works best if you have *lots* of custom data, where as, feature extraction is typically better if you have less custom data.\n", - "* Check out the new/upcoming [PyTorch multi-weights API](https://pytorch.org/blog/introducing-torchvision-new-multi-weight-support-api/) (still in beta at time of writing, May 2022), it's a new way to perform transfer learning in PyTorch. What changes to our code would need to made to use the new API?\n", + "* Look up what \"model fine-tuning\" is and spend 30-minutes researching different methods to perform it with PyTorch. How would we change our code to fine-tune? Tip: fine-tuning usually works best if you have *lots* of custom data, where as, feature extraction is typically better if you have less custom data.\n", + "* Check out the new/upcoming [PyTorch multi-weights API](https://pytorch.org/blog/introducing-torchvision-new-multi-weight-support-api/) (still in beta at time of writing, May 2022), it's a new way to perform transfer learning in PyTorch. What changes to our code would need to be made to use the new API?\n", "* Try to create your own classifier on two classes of images, for example, you could collect 10 photos of your dog and your friends dog and train a model to classify the two dogs. This would be a good way to practice creating a dataset as well as building a model on that dataset." ] }