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 2

Rethinking the Training Loop

Spoilers

In this chapter, we will:

• build a function to perform training steps

• implement our own dataset class

• use data loaders to generate mini-batches

• build a function to perform mini-batch gradient descent

• evaluate our model

• integrate TensorBoard to monitor model training

• save / checkpoint our model to disk

• load our model from disk to resume training or to deploy

Jupyter Notebook

The Jupyter notebook corresponding to Chapter 2 [53] is part of the official Deep

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

directly in Google Colab [54] .

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

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

Imports

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

Spoilers | 123

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

Saved successfully!

Ooh no, something went wrong!