Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

peiying410632
from peiying410632 More from this publisher
22.02.2024 Views

the filters learned by the model produce the features that will feed theclassifier part• computing accuracy for a multiclass classification problem• creating a static method to apply a function to all the mini-batches in a dataloaderCongratulations: You took one big step toward being able to tackle manycomputer vision problems. This chapter introduced the fundamental conceptsrelated to (almost) all things convolutional. We still need to add some more tricks toour arsenal, so we can make our models even more powerful. In the next chapter,we’ll learn about convolutions over multiple channels, using dropout layers toregularize a model, finding a learning rate, and the inner workings of optimizers.[88] https://github.com/dvgodoy/PyTorchStepByStep/blob/master/Chapter05.ipynb[89] https://colab.research.google.com/github/dvgodoy/PyTorchStepByStep/blob/master/Chapter05.ipynb[90] https://en.wikipedia.org/wiki/Convolution[91] https://en.wikipedia.org/wiki/Kernel_(image_processing)[92] https://bit.ly/3sJ7Nn7[93] https://realpython.com/primer-on-python-decorators/Recap | 415

Chapter 6Rock, Paper, ScissorsSpoilersIn this chapter, we will:• standardize an image dataset• train a model to predict rock, paper, scissors poses from hand images• use dropout layers to regularize the model• learn how to find a learning rate to train the model• understand how the Adam optimizer uses adaptive learning rates• capture gradients and parameters to visualize their evolution during training• understand how momentum and Nesterov momentum work• use schedulers to implement learning rate changes during trainingJupyter NotebookThe Jupyter notebook corresponding to Chapter 6 [94] is part of the official DeepLearning with PyTorch Step-by-Step repository on GitHub. You can also run itdirectly in Google Colab [95] .If you’re using a local installation, open your terminal or Anaconda prompt andnavigate to the PyTorchStepByStep folder you cloned from GitHub. Then, activatethe pytorchbook environment and run jupyter notebook:$ conda activate pytorchbook(pytorchbook)$ jupyter notebookIf you’re using Jupyter’s default settings, this link should open Chapter 6’snotebook. If not, just click on Chapter06.ipynb in your Jupyter’s home page.ImportsFor the sake of organization, all libraries needed throughout the code used in any416 | Chapter 6: Rock, Paper, Scissors

Chapter 6

Rock, Paper, Scissors

Spoilers

In this chapter, we will:

• standardize an image dataset

• train a model to predict rock, paper, scissors poses from hand images

• use dropout layers to regularize the model

• learn how to find a learning rate to train the model

• understand how the Adam optimizer uses adaptive learning rates

• capture gradients and parameters to visualize their evolution during training

• understand how momentum and Nesterov momentum work

• use schedulers to implement learning rate changes during training

Jupyter Notebook

The Jupyter notebook corresponding to Chapter 6 [94] is part of the official Deep

Learning with PyTorch Step-by-Step repository on GitHub. You can also run it

directly in Google Colab [95] .

If you’re using a local installation, open your terminal or Anaconda prompt and

navigate to the PyTorchStepByStep folder you cloned from GitHub. Then, activate

the pytorchbook environment and run jupyter notebook:

$ conda activate pytorchbook

(pytorchbook)$ jupyter notebook

If you’re using Jupyter’s default settings, this link should open Chapter 6’s

notebook. If not, just click on Chapter06.ipynb in your Jupyter’s home page.

Imports

For the sake of organization, all libraries needed throughout the code used in any

416 | Chapter 6: Rock, Paper, Scissors

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!