Task: plot a confusion matrix, find images that were misclassified
You do not need to read or modify the code in this section to successfully complete this assignment.
# Import fastai code.
from fastai.vision.all import *
# Set a seed for reproducibility.
set_seed(0, reproducible=True)
path = untar_data(URLs.PETS)/'images'
image_files = get_image_files(path).sorted()
def cat_or_dog(filename):
# Cat images have filenames that start with a capital letter.
return 'cat' if filename[0].isupper() else 'dog'
labels = [cat_or_dog(path.name) for path in image_files]
dataloaders = ImageDataLoaders.from_lists(
path=path, fnames=image_files, labels=labels,
valid_pct=0.2,
seed=42,
item_tfms=Resize(224)
)
learn = vision_learner(
dls=dataloaders,
arch=resnet18,
metrics=accuracy
)
learn.fine_tune(epochs=1)
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 0.170331 | 0.029591 | 0.988498 | 00:11 |
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 0.065506 | 0.022286 | 0.995940 | 00:14 |
We've given you a classifier (the learn object). It makes a few mistakes; can you find them?
Follow these steps:
DataLoader objects at dataloaders.train and dataloaders.valid; each of them has a .show_batch() method.)# your code here
# your code here
interp = ClassificationInterpretation.from_learner(learn)
interp.plot_top_losses(12)
interp.plot_confusion_matrix()
# your code here
interp_train = ClassificationInterpretation.from_learner(learn, ds_idx=0))interp_train = ClassificationInterpretation.from_learner(learn, ds_idx=0)
# your code here
X out of XX images were incorrectly labeled "cat".
Y out of YY images were incorrectly labeled "dog".
your answer here
your answer here