22.02.2024 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4

Classifying Images

Spoilers

In this chapter, we will:

• build models to classify images

• use Torchvision to apply transformations to images

• compose transformations and apply them to datasets

• perform data augmentation in the training set

• use samplers to handle imbalanced datasets

• understand why we need activation functions

• build a deeper model using activation functions

Jupyter Notebook

The Jupyter notebook corresponding to Chapter 4 [76] is part of the official Deep

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

directly in Google Colab [77] .

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

notebook. If not, just click on Chapter04.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:

Spoilers | 265

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

Saved successfully!

Ooh no, something went wrong!