Path: blob/master/second_edition/chapter09_part03_interpreting-what-convnets-learn.ipynb
713 views
This is a companion notebook for the book Deep Learning with Python, Second Edition. For readability, it only contains runnable code blocks and section titles, and omits everything else in the book: text paragraphs, figures, and pseudocode.
If you want to be able to follow what's going on, I recommend reading the notebook side by side with your copy of the book.
This notebook was generated for TensorFlow 2.6.
Interpreting what convnets learn
Visualizing intermediate activations
Preprocessing a single image
Displaying the test picture
Instantiating a model that returns layer activations
Using the model to compute layer activations
Visualizing the fifth channel
Visualizing every channel in every intermediate activation
Visualizing convnet filters
Instantiating the Xception convolutional base
Printing the names of all convolutional layers in Xception
Creating a feature extractor model
Using the feature extractor
Loss maximization via stochastic gradient ascent
Function to generate filter visualizations
Utility function to convert a tensor into a valid image
Generating a grid of all filter response patterns in a layer
Visualizing heatmaps of class activation
Loading the Xception network with pretrained weights
Preprocessing an input image for Xception
Setting up a model that returns the last convolutional output
Reapplying the classifier on top of the last convolutional output
Retrieving the gradients of the top predicted class
Gradient pooling and channel-importance weighting
Heatmap post-processing
Superimposing the heatmap on the original picture