liveBook · Manning

Activation

As explained in Deep Learning with Python, Third Edition

The numeric value of a model activation.

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

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines activation tensors, visualizes individual channels, and optimizes filter responses, but does not survey every interpretation technique.
Examples
Uses a cat image, a sixth-channel edge visualization, complete activation grids, and optimized Xception filter patterns.
What it assumes
Assumes a trained ConvNet and image preprocessing, while introducing multi-output models, feature extraction, and low-level gradient loops.
What you can do after
Diagnose/debug with it: extract, inspect, visualize, and optimize ConvNet activations to understand learned visual responses.
How it connects
Connects activations with ConvNets, convolution and pooling layers, feature maps, filters, feature extractors, and gradient ascent.

Also explained in

Compare how 3 books explain activation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.