Week 4 GradCAM colab

There is a minor mistake in the show_sample method, that it claims to pick a random activation layer, but it always selects the first activation layer:

sample_activation = activations[0][0,:,:,16]

This line is taking the specific activation output from the visualization model. The randomness is on selecting the image samples, as shown by the idx argument in the function. Selecting the sample is done in the codes before generating the activations.

if image index is specified, get that image

if idx:
    for img, label in test_batches.take(idx):
        sample_image = img[0]
        sample_label = label[0]
# otherwise if idx is not specified, get a random image
    for img, label in test_batches.shuffle(1000).take(1):
        sample_image = img[0]
        sample_label = label[0]