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 more dimensions, the more separable the points are, as we’ve seen in the "AreMy Data Points Separable?" section in Chapter 3.Then, by projecting it back into two dimensions, we can visualize the decisionboundary in the modified feature space. The overall shape is more complex, as if itwent through multiple foldings, as a result of the increase in dimensionality.Personally, this is one of my favorite topics, and it was the subject of my very firstblog post: "Hyper-parameters in Action! Part I—Activation Functions." [84] You canalso check out some animations I built back then for visualizing the trainingprocess using different activation functions: sigmoid, [85] hyperbolic tangent, [86] andReLU. [87]RecapAnd that’s enough for our feature space visualization journey! I hope you liked it.This is what we’ve covered:• learning what a feature space is and how a hidden layer performs affinetransformations to modify it• visualizing the effect of activation functions on the feature space• learning that the decision boundary is a straight line in the activated featurespace, but a curve in the original feature space• visualizing different decision boundaries (in original feature space) fordifferent activation functions• making a more powerful model by making it deeper• making a more powerful model by making it wider, thus increasingdimensionalityNow, let’s get back to the main track, tackling a multiclass classification problemusing convolutional neural networks (CNNs).[80] https://bit.ly/3l5XVkN[81] https://bit.ly/2QgEmYR[82] https://bit.ly/34mw0ai[83] https://bit.ly/3hgfIU6[84] https://towardsdatascience.com/hyper-parameters-in-action-a524bf5bf1c[85] https://youtu.be/4RoTHKKRXgE[86] https://youtu.be/PFNp8_V_Apg[87] https://youtu.be/Ji_05nOFLE0Recap | 343

Chapter 5ConvolutionsSpoilersIn this chapter, we will:• understand the arithmetic of convolutional layers in detail• build a model for multiclass classification• understand the role of the softmax function• use negative log-likelihood and cross-entropy losses• visualize filters learned by our convolutional neural network• understand and use hooks to capture outputs from intermediate layers• visualize feature maps to better understand what’s happening inside the modelJupyter NotebookThe Jupyter notebook corresponding to Chapter 5 [88] is part of the official DeepLearning with PyTorch Step-by-Step repository on GitHub. You can also run itdirectly in Google Colab [89] .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 5’snotebook. If not, just click on Chapter05.ipynb in your Jupyter’s home page.ImportsFor the sake of organization, all libraries needed throughout the code used in anygiven chapter are imported at its very beginning. For this chapter, we’ll need thefollowing imports:344 | Chapter 5: Convolutions

Chapter 5

Convolutions

Spoilers

In this chapter, we will:

• understand the arithmetic of convolutional layers in detail

• build a model for multiclass classification

• understand the role of the softmax function

• use negative log-likelihood and cross-entropy losses

• visualize filters learned by our convolutional neural network

• understand and use hooks to capture outputs from intermediate layers

• visualize feature maps to better understand what’s happening inside the model

Jupyter Notebook

The Jupyter notebook corresponding to Chapter 5 [88] is part of the official Deep

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

directly in Google Colab [89] .

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 5’s

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

Imports

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

given chapter are imported at its very beginning. For this chapter, we’ll need the

following imports:

344 | Chapter 5: Convolutions

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

Saved successfully!

Ooh no, something went wrong!