An activation is the numeric value produced by a model layer, often after an activation function. In a ConvNet, a layer returns a feature map with width, height, and channels; each channel records how strongly a learned feature responds at each location. section 10.1
Reading a ConvNet activation
Feed an unseen cat image through a model and collect the outputs of its convolution and pooling layers. The first convolutional activation can have shape (1, 178, 178, 32): 32 channels of spatial responses. Plotting channel 5 as a two-dimensional image may reveal a diagonal-edge detector, although learned channels can vary between training runs. section 10.1
Use these practical rules when inspecting activations:
- Treat each channel independently when visualizing a feature map; channels usually encode relatively independent features. section 10.1
- Use a feature-extractor model to retrieve one layer’s output without copying the original model. section 10.2
- Maximize a chosen filter’s activation value with gradient ascent on the input to reveal the visual pattern it responds to. section 10.2
Listing 10.3 Instantiating a model that returns layer activations
from keras import layers layer_outputs = [] layer_names = [] for layer in model.layers: #1 if isinstance(layer, (layers.Conv2D, layers.MaxPooling2D)): #1 layer_outputs.append(layer.output) #1 layer_names.append(layer.name) #2 activation_model = keras.Model(inputs=model.input, outputs=layer_outputs)#3
Inspect the Keras pattern for constructing a model that returns convolutional and pooling-layer activations. section 10.1


