To train a neural network, we must perform the following steps:
- Import the relevant packages.
- Build a dataset that can fetch data one data point at a time.
- Wrap the DataLoader from the dataset.
- Build a model and then define the loss function and the optimizer.
- Define two functions to train and validate a batch of data, respectively.
- Define a function that will calculate the accuracy of the data.
- Perform weight updates based on each batch of data over increasing epochs.
In the following lines of code, we'll perform each of the following steps:
The following code is available as Steps_to_build_a_neural_network_on_FashionMNIST.ipynb in the Chapter03 folder of this book's GitHub repository - https://tinyurl.com/mcvp-packt
- Import the relevant packages and the FMNIST dataset:
from torch.utils.data import Dataset, DataLoader
import torch
import torch.nn as nn
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
device = "cuda" if...