22.02.2024 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• defining our StepByStep class

• understanding the purpose of the constructor (__init__()) method

• defining the arguments of the constructor method

• defining class' attributes to store arguments, placeholders, and variables we need

to keep track of

• defining functions as attributes, using higher-order functions and the class'

attributes to build functions that perform training and validation steps

• understanding the difference between public, protected, and private methods,

and Python’s "relaxed" approach to it

• creating methods to set data loaders and TensorBoard integration

• (re)implementing training methods: _mini_batch() and train()

• implementing saving and loading methods: save_checkpoint() and

load_checkpoint()

• implementing a method for making predictions that takes care of all

boilerplate code regarding Numpy-to-PyTorch conversion and back

• implementing methods to plot losses and add the model’s graph to

TensorBoard

• instantiating our StepByStep class and running a classy pipeline: configuring

the model, loading the data, training the model, making predictions,

checkpointing, and resuming training. The whole nine yards!

Congratulations! You have developed a fully functioning class that implements all

methods relevant to model training and evaluation. From now on, we’ll use it over

and over again to tackle different tasks and models. Next stop: classification!

[61] https://github.com/dvgodoy/PyTorchStepByStep/blob/master/Chapter02.1.ipynb

[62] https://colab.research.google.com/github/dvgodoy/PyTorchStepByStep/blob/master/Chapter02.1.ipynb

[63] https://realpython.com/python3-object-oriented-programming/

[64] https://realpython.com/python-super/

[65] https://www.w3schools.com/python/ref_func_setattr.asp

[66] https://pytorch.org/docs/stable/notes/randomness.html

[67] https://github.com/dvgodoy/PyTorchStepByStep/blob/master/stepbystep/v0.py

Recap | 205

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

Saved successfully!

Ooh no, something went wrong!