json_clean[source]

json_clean(o)

In all this notebook, we will use the following data:

from fastai.vision.all import *
path = untar_data(URLs.PETS)/'images'
fnames = get_image_files(path)
def is_cat(x): return x[0].isupper()
dls = ImageDataLoaders.from_name_func(
    path, fnames, valid_pct=0.2, seed=42,
    label_func=is_cat, item_tfms=Resize(128))
from random import randint
learn = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)
epoch train_loss valid_loss error_rate time
0 0.367540 0.159957 0.060217 00:10
epoch train_loss valid_loss error_rate time
0 0.144134 0.073435 0.027064 00:12

Captum Interpretation

The Distill Article here provides a good overview of what baseline image to choose. We can try them one by one.

class CaptumInterpretation[source]

CaptumInterpretation(learn, cmap_name='custom blue', colors=None, N=256, methods=['original_image', 'heat_map'], signs=['all', 'positive'], outlier_perc=1)

Captum Interpretation for Resnet

Interpretation

captum=CaptumInterpretation(learn)
idx=randint(0,len(fnames))
captum.visualize(fnames[idx])
captum.visualize(fnames[idx],baseline_type='uniform')
captum.visualize(fnames[idx],baseline_type='gauss')
captum.visualize(fnames[idx],metric='NT',baseline_type='uniform')
captum.visualize(fnames[idx],metric='Occl',baseline_type='gauss')