Preparing the data
In this chapter, we are going to use the classic MNIST dataset. This dataset contains 28-pixel x 28-pixel images of handwritten digits. The task for the model is to take an image as input and identify the digit in the image. We will use PyTorch
, a popular deep-learning library, to demonstrate the algorithms. Let’s prepare the data now.
The first step in the process will be to import the libraries. We will need NumPy (as we deal with numpy
arrays), torchvision
(to load MNIST data), torch
, random
, and copy
libraries.
Next, we can download the MNIST data from torchvision.datasets
. The torchvision
library is a part of the PyTorch
framework, which contains datasets, models, and common image transformers for computer vision tasks. The following code will download the MNIST dataset from this library:
img_transform = torchvision.transforms.ToTensor() trainset = torchvision.datasets.MNIST(\ Â Â Â Â root='/tmp/mnist', train=True,\...