Training a neural network
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 can be found in the Steps_to_build_a_neural_network_on_FashionMNIST.ipynb
file located in the Chapter03
folder on GitHub at https://bit.ly/mcvp-2e.
- 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...