|
400 | 400 | "| 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", |
401 | 401 | "| 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", |
402 | 402 | "\n", |
403 | | - "> **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", |
| 403 | + "> **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", |
404 | 404 | "\n", |
405 | 405 | "> **Question:** *Where did the mean and standard deviation values come from? Why do we need to do this?*\n", |
406 | 406 | ">\n", |
|
495 | 495 | "```\n", |
496 | 496 | "\n", |
497 | 497 | "Where,\n", |
498 | | - "* `EfficientNet_B0_Weights` is the model architecture weights we'd like to use (there are many differnt model architecture options in `torchvision.models`).\n", |
| 498 | + "* `EfficientNet_B0_Weights` is the model architecture weights we'd like to use (there are many different model architecture options in `torchvision.models`).\n", |
499 | 499 | "* `DEFAULT` means the *best available* weights (the best performance in ImageNet).\n", |
500 | 500 | " * **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", |
501 | 501 | " \n", |
|
530 | 530 | "id": "cebcdf20-4ab7-40ba-8691-9d9af8962dab", |
531 | 531 | "metadata": {}, |
532 | 532 | "source": [ |
533 | | - "And now to access the transforms assosciated with our `weights`, we can use the `transforms()` method.\n", |
| 533 | + "And now to access the transforms associated with our `weights`, we can use the `transforms()` method.\n", |
534 | 534 | "\n", |
535 | 535 | "This is essentially saying \"get the data transforms that were used to train the `EfficientNet_B0_Weights` on ImageNet\"." |
536 | 536 | ] |
|
657 | 657 | "\n", |
658 | 658 | "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", |
659 | 659 | "\n", |
660 | | - "Understanding this **performance vs. speed vs. size tradeoff** will come with time and practice.\n", |
| 660 | + "Understanding this **performance vs. speed vs. size** tradeoff will come with time and practice.\n", |
661 | 661 | "\n", |
662 | 662 | "For me, I've found a nice balance in the `efficientnet_bX` models. \n", |
663 | 663 | "\n", |
|
1267 | 1267 | "* **Same shape** - If our images are different shapes to what our model was trained on, we'll get shape errors.\n", |
1268 | 1268 | "* **Same datatype** - If our images are a different datatype (e.g. `torch.int8` vs. `torch.float32`) we'll get datatype errors.\n", |
1269 | 1269 | "* **Same device** - If our images are on a different device to our model, we'll get device errors.\n", |
1270 | | - "* **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", |
| 1270 | + "* **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", |
1271 | 1271 | "\n", |
1272 | 1272 | "> **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", |
1273 | 1273 | "\n", |
|
1359 | 1359 | "\n", |
1360 | 1360 | "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", |
1361 | 1361 | "\n", |
1362 | | - "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." |
| 1362 | + "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." |
1363 | 1363 | ] |
1364 | 1364 | }, |
1365 | 1365 | { |
|
1445 | 1445 | "\n", |
1446 | 1446 | "That's where the real fun of machine learning is!\n", |
1447 | 1447 | "\n", |
1448 | | - "Predicting on your own custom data, outisde of any training or test set.\n", |
| 1448 | + "Predicting on your own custom data, outside of any training or test set.\n", |
1449 | 1449 | "\n", |
1450 | 1450 | "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", |
1451 | 1451 | "\n", |
|
1521 | 1521 | "metadata": {}, |
1522 | 1522 | "source": [ |
1523 | 1523 | "## Main takeaways\n", |
1524 | | - "* **Transfer learning** often allows to you get good results with a relatively small amount of custom data.\n", |
| 1524 | + "* **Transfer learning** often allows you to get good results with a relatively small amount of custom data.\n", |
1525 | 1525 | "* 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", |
1526 | 1526 | "* 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", |
1527 | 1527 | "* 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 | 1560 | " * You may want to try an EfficientNet with a higher number than our B0, perhaps `torchvision.models.efficientnet_b2()`?\n", |
1561 | 1561 | " \n", |
1562 | 1562 | "## Extra-curriculum\n", |
1563 | | - "* 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", |
1564 | | - "* 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", |
| 1563 | + "* 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", |
| 1564 | + "* 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", |
1565 | 1565 | "* 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." |
1566 | 1566 | ] |
1567 | 1567 | } |
|
0 commit comments