From Dogs and Cats to Pet Breeds

In the first model we built, we trained a model to classify pictures of dogs vs cats. We can actually use this same dataset to work on a significantly more challenging problem, figuring out what breed of pet is shown in an image.

from fastai.vision.all import *

Checking and debugging datablocks

If you’ve made a mistake in your DataBlock, it’s pretty unlikely that you’ll be able to tell before this next step.

We can debug a DataBlock using the summary method:

#hide_output
pets1 = DataBlock(blocks = (ImageBlock, CategoryBlock),
                get_items=get_image_files, 
                splitter=RandomSplitter(seed=42),
                get_y=using_attr(RegexLabeller(r'(.+)_\d+.jpg$'), 'name'))
pets1.summary(path/"images")

Cross-Entropy Loss

What is Cross-Entropy Loss?

  • Loss function that is similar to the one used in previous chapter, but has two benefits
  • Works even when our dependent variable has more than two categories
  • Results in faster and more reliable training

To understand how cross-entropy loss works for dependent variables with more than two categories, we have to understand what the actual data and activations seen by the loss function are like

Viewing Activations and Labels

Softmax

In our classificiation model, we use the softmax function in the final layer to make sure that our activations are all between 0 and 1