Hands-on exercise – building and training a PyTorch model
In this hands-on exercise, you will learn how to install the PyTorch library in your local machine and train a simple deep learning model using PyTorch. Launch a Jupyter notebook that you have previously installed on your machine. If you don't remember how to do this, visit the Hands-on lab section of Chapter 3, Machine Learning Algorithms. Now, let's get started:
- Create a new folder called
pytorch-lab
in your Jupyter notebook environment and create a new notebook file calledpytorch-lab1.ipynb
. Run the following command in a cell to install PyTorch and thetorchvision
package.torchvision
contains a set of computer vision models and datasets. We will use the pre-built MNIST dataset in thetorchvision
package for this exercise:!pip3 install torch !pip3 install torchvision
- The following sample code shows the previously mentioned main components. Be sure to run each code block in a separate Jupyter...