Skip to content

Instantly share code, notes, and snippets.

@zwliew
Last active January 28, 2019 14:52
Show Gist options
  • Save zwliew/a2eea62ed2b361d2884b58c04803e71a to your computer and use it in GitHub Desktop.
Save zwliew/a2eea62ed2b361d2884b58c04803e71a to your computer and use it in GitHub Desktop.
fast.ai Practical Deep Learning for Coders v3 (2019) Notes

Lesson 1 - Image Classification

Looking at data

  • It pays to think creatively. Specifically, can something be modelled as an image that can be fed into a neural network for training?
  • Create a Python PoxisPath from a filename via the prefix path/.
  • Each data set should comprise a training set and a validation set. The validation loss should usually be slightly higher than the training loss.
  • The fastai library supports loading data sets into ImageDataBunch's from DataFrames (from_df), CSVs (from_csv), file name regex (from_name_re), file name functions (from_name_func), from folder names (from_folder), and from Python lists (from_lists).
  • ImageDataBunch.classes can generally be thought of as the number of labels.
  • ImageDataBunch.show_batch gives us a quick look at the data. This is useful to get a feel of the data before training the model.

Training

  • Convolutional neural networks, specifically resnet18/34/50, are good for training models to recognize images. According to Wikipedia, they are "most commonly applied to analyzing visual imagery".
  • A convolutional neural network is made up of multiple layers, each layer acting as a filter that looks for specific patterns. The outputs of each layer are fed into the next to filter even more complicated patterns. Ultimately, a complicated pattern similar to what we're looking for is able to be filtered by the network.
  • We usually want to fit_one_cycle several times for a pre-trained model, save it for later reference, then unfreeze the model (allow the front and middle layers to be trained) and fit_one_cycle several more times with a range of max learning rates determined via lr_find and recorder_plot.

Results

  • ClassificationInterpretation.plot_top_losses, ClassificationInterpretation.most_confused and ClassificationInterpretation.plot_confusion_matrix give us a quick look at the top losses of the trained model. This is useful to find out whether there is an issue with the model or that the classification of specific categories are indeed just nigh impossible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment