🔢

MNIST Basics

Anki

Aim: create a model that can classify an image as a 3 or a 7

Setup

Download dataset

FastAI: download (library-provided) dataset
path = untar_data(URLs.<dataset_name>)
FastAI: set global base path
Path.BASE_PATH = path
FastAI: get files at path
path.ls()
FastAI: get subdirectory from path
path/'sub1'/'fileA'

Analysis

FastAI: path to PIL image
Image.open(path)
FastAI: PIL image to tensor
tensor(image)
FastAI: view tensor as image
show_image(image_tensor)

Training

General

Pytorch: track gradients
tensor.requires_grad_()
Pytorch: backprop
loss.backward()
Pytorch: get calculated gradients
params.grad

MNIST

FastAI: tensor to batched iterator
DataLoader(tensor, batch_size)
FastAI: what is a DataLoader
A wrapper around a tensor enabling batched iteration
FastAI: group training and validation datasets (transforms can be applied to both)
DataLoaders(train, valid)
FastAI: what is a DataLoaders
A wrapper grouping training and validation datasets (transforms can be applied to both)
Pytorch: linear layer
nn.Linear(dims)
Pytorch: get module params
module.parameters()
FastAI: base class combining everything needed for training (also, what are the key components?)
Learner(dataloaders, model, loss_func, opt_func, ...)
FastAI: where are statistics from training run stored?
learner.recorder
Pytorch: combine modules/layers
nn.Sequential(m1, m2, ...)

Misc

Pytorch: cast to e.g. float
tensor.float()
Pytorch: torch.stack vs torch.cat?
torch.stack: concatenates a sequence of tensors along a new dimension
torch.cat: concatenates a sequence of tensors along a in the given dimension
Pytorch: stack tensors
torch.stack([tensorA, ...])
Pytorch: what is "concatenating"
Concatenating a sequence of tensors in the given dimension
Pytorch: what does .view(...) do on a tensor?
Changes the shape to the one specified.
Pytorch: how to change a tensor's shape (within reason)?
.view(...)
Pytorch: what does .unsqueeze(dim) do on a tensor?
Returns a new tensor with a dimension of size one inserted at the specified position.
Pytorch: how to insert a dimension of size one at a specified position?
.unsqueeze(dim)
Pytorch: conditional computation
torch.where(condition, x, y)