Video by freeCodeCamp.org · taught by Aakash N S · streamed from YouTube. All rights remain with the creator.
Lesson 3: Working with Images and Logistic Regression
About this lesson
This second session of the Deep Learning with PyTorch live course, taught by Aakash N S, moves from predicting numbers to classifying images. It works with the MNIST dataset of handwritten digits, one of the best-known datasets in machine learning, and shows how to download it with torchvision, look at individual images and convert them into tensors that a model can use. The session explains why the data must be divided into separate training and validation sets, and how to create them, along with data loaders that feed the images to the model in batches. It then builds a logistic regression model, a single linear layer that takes the pixels of each image as inputs and produces one score for each of the ten digits, and explains how to organise the model as a PyTorch class. The softmax function is introduced to turn those scores into probabilities, and categorical cross-entropy is introduced as the loss function for classification, together with an explanation of why accuracy, although it is the measure we care about, cannot be used directly for training. The session goes on to train the model, evaluate it on the validation set after each epoch and plot its progress. It finishes by testing the model on individual sample images, evaluating it on the separate test set and saving and loading the trained weights. Each step is shown running live in a notebook. Afterwards, read Chapter 3 of the course book, which works softmax and cross-entropy by hand.