Notes from Fast.ai Deep Learning Course

Posted on May 15, 2023

Training a Digit Classifier

Goal: Create a model that can classify any image as a 3 or a 7

Example of a handwritten number 3, taken from the MNIST dataset of handwritten numbers:

The same image represented as a array:

image3 = Image.open(image3_path)
array(image3)[0:28,0:28]

Pixel Similarity approach

We can get two group averages using the average pixel value for each pixel of the 3s and the 7s. We could then compare the values of the images we want to classify with both groups and calculate which one is more similar.

In the process of calculating the groups averages we need to create a tensor containing all of our sample data stacked together. List comprehension is useful for this.

Terminology

  • rank-x tensor:
    • rank is the number of axes or dimensions in a tensor
    • shape is the size of each axis of a tensor
  • mean absolute difference or L1 norm: Take the mean of the absolute value of differences (absolute value is the function that replaces negative values with positive values).
  • root mean squared error (RMSE) or L2 norm: Take the mean of the square of differences (which makes everything positive) and then take the square root (which undoes the squaring).

NumPy Arrays and PyTorch Tensors