We are going to use PYTorch and create CNN model step by step. Then we will train the model with training data and evaluate the model with test data.
Import libraries
import torch
Check available device
# Device configuration
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device
Output: device(type=’cpu’)
Download MNIST dataset
What is MNIST dataset?
The MNIST database (Modified National Institute of Standards and Technology database) is a large database of handwritten digits that is commonly used for training various image processing systems. The database is also widely used for training and testing in the field of machine learning.
The MNIST database contains 60,000 training images and 10,000 testing images.
PyTorch domain libraries provide a number of pre-loaded datasets (such as FashionMNIST, MNIST etc…) that subclass torch.utils.data.Dataset and implement functions specific to the particular data. They can be used to prototype and benchmark your model. In this example we are using MNIST dataset.