...

/

Training Our Classifier

Training Our Classifier

Learn to train the classifier in this lesson.

Training a classifier neural network is now really simple. That’s because we’ve done all the hard work setting up the dataset class and the neural network class.

Creating a neural network object

We first create a neural network from our Classifier class.

Press + to interact
# create neural network
C = Classifier()

Training the network

To train the network, the code is again very simple:

Press + to interact
# train network on MNIST data set
for label, image_data_tensor, target_tensor in mnist_dataset:
C.train(image_data_tensor, target_tensor)
pass

The mnist_dataset inherits from PyTorch’s Dataset allowing us to work through all the training data with an elegant for loop. For each training example, we simply pass the image data and target tensor to the ...