1. Home
  2. Explore
  3. Computer Science
  4. Interpreting Neural Networks

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Interpreting Neural Networks

Interpreting and Visualizing Convolutional Neural Networks

Why Neural Network Interpretability Matters

Convolutional neural networks (CNNs) have achieved strong performance in image classification, object detection, face recognition, and neural style transfer. However, their improvements are often obtained through trial and error:

  • Researchers try different architectures.

  • Hyperparameters are searched experimentally.

  • Validation data is used to identify configurations that improve performance.

  • Some changes help, while others do not.

Although this process can produce accurate models, it does not fully explain why a model works or what it has learned. Interpretability methods address this problem by revealing:

  • Which parts of an input image influenced a prediction.

  • Which internal features or neurons respond to particular visual patterns.

  • What the network considers representative of a class.

  • Whether the network is using meaningful evidence or relying on misleading correlations.

  • Whether some neurons or feature maps are inactive or “dead.”

Interpretability is especially important in applications such as healthcare, where users may be reluctant to trust a model unless it can show the evidence behind its decisions.

Two Broad Interpretability Questions

CNN visualization methods can be divided into two major categories:

  1. Input-to-output interpretation

    • Given a prediction, which parts of the input caused it?

    • Examples: saliency maps, occlusion sensitivity, and class activation maps.

  2. Internal network interpretation

    • What does a particular neuron, feature map, or layer represent?

    • Examples: gradient ascent, dataset search, and deconvolution.


From Classification Scores to Input Evidence

Suppose an image xxx is passed through a CNN and the network predicts that it contains a dog. The network may produce scores for classes such as:

  • Iguana

  • Dog

  • Car

  • Cat

  • Crab

A softmax layer converts the raw class scores into probabilities.

Pre-Softmax Scores and Post-Softmax Probabilities

Before softmax, the network produces a vector of raw scores:

s=(s1,s2,…,sC)s = (s_1, s_2, \ldots, s_C)s=(s1​,s2​,…,sC​)

where each score may range from negative infinity to positive infinity.

The softmax probability for class ccc is:

P(c∣x)=esc∑j=1CesjP(c \mid x) = \frac{e^{s_c}}{\sum_{j=1}^{C} e^{s_j}}P(c∣x)=∑j=1C​esj​esc​​

The probabilities sum to one:

∑c=1CP(c∣x)=1\sum_{c=1}^{C} P(c \mid x) = 1∑c=1C​P(c∣x)=1

For interpretability, it is generally better to use the pre-softmax score scs_csc​ rather than the post-softmax probability.

Why Use the Pre-Softmax Score?

The probability of one class depends on every class score in the denominator. Increasing the probability of “dog” can therefore happen in two different ways:

  • Increasing the dog score.

  • Decreasing the scores of other classes.

A pixel might reduce the score of “fish” without directly increasing the score of “dog.” Such a pixel could have a large effect on the dog probability even though it does not directly support the dog class.

Using the pre-softmax dog score isolates the evidence that directly affects the dog output:

∂sdog∂x\frac{\partial s_{\text{dog}}}{\partial x}∂x∂sdog​​

This derivative measures how changes to the input pixels would change the dog score.

Key principle: Input gradients should usually be computed with respect to the chosen class’s pre-softmax score, not its final probability.


Methods for Explaining a Specific Prediction

1. Saliency Maps

A saliency map shows how sensitive a class score is to each input pixel.

For a target class ccc, compute the gradient:

∂sc∂x\frac{\partial s_c}{\partial x}∂x∂sc​​

The resulting gradient has the same shape as the input image xxx. If the input is an image of height HHH, width WWW, and three color channels, the gradient also has dimensions H×W×3H \times W \times 3H×W×3.

Interpretation

  • A large absolute gradient indicates that the corresponding pixel strongly affects the class score.

  • A small gradient indicates that changing that pixel would have little immediate effect on the score.

  • Positive and negative values indicate different directions of influence.

  • Visualization usually applies a color scheme or aggregates across color channels.

A simple pixel-importance map can be created by taking the absolute gradient:

M(i,j)=∥∂sc∂xi,j∥M(i,j) = \left\| \frac{\partial s_c}{\partial x_{i,j}} \right\|M(i,j)=​∂xi,j​∂sc​​​

Generating a Saliency Map

  1. Pass the image through the CNN.

  2. Select the pre-softmax score for the target class.

  3. Backpropagate the gradient from that score to the input pixels.

  4. Visualize the magnitude of the resulting gradient.

  5. Optionally threshold the map to identify highly influential regions.

Example

For a dog image, pixels around the dog may receive stronger values than pixels in the background. Thresholding these values could produce a rough segmentation of the dog.

However, saliency-based segmentation is usually not very accurate compared with dedicated segmentation methods.

Strengths and Limitations

Strengths:

  • Fast to compute.

  • Directly connects the output to the input.

  • Useful for quickly identifying influential regions.

Limitations:

  • Gradients can be noisy.

  • A large gradient does not always mean that a region is semantically meaningful.

  • The map may highlight edges or small pixel changes rather than complete objects.

  • It can be sensitive to model nonlinearities and local behavior.


2. Occlusion Sensitivity

Occlusion sensitivity measures how a prediction changes when parts of the input are hidden.

The method systematically covers different regions of an image with an occluding patch, often a gray square, and records the target class score after each modification.

Procedure

  1. Start with the original image.

  2. Place a gray square over one region.

  3. Forward-propagate the modified image through the CNN.

  4. Record the target class probability or score.

  5. Move the square to another location.

  6. Repeat until the image has been scanned.

  7. Construct a spatial map of the resulting scores.

For a target class ccc and occlusion location (i,j)(i,j)(i,j), the map can be written as:

Mc(i,j)=sc(x with region (i,j) occluded)M_c(i,j) = s_c\left(x \text{ with region } (i,j) \text{ occluded}\right)Mc​(i,j)=sc​(x with region (i,j) occluded)

Interpretation

  • If occluding a region causes the class score to decrease, that region likely contains evidence supporting the class.

  • If occluding a region causes the score to increase, the occluded region may contain distracting or misleading information.

  • If the score remains almost unchanged, the region probably has little influence on the prediction.

For example, covering a dog’s face may sharply reduce the dog score. Covering an irrelevant background region may have little effect.

Why Occlusion Can Increase Confidence

Occlusion does not always reduce the target score. A hidden region might contain:

  • Background clutter.

  • Another object associated with a competing class.

  • Misleading visual information.

  • Noise that interferes with classification.

For example, covering a human face in an image containing a dog may make the network more confident that the image belongs to the dog class if the face had caused competition from a human-related class.

Spatial Precision

The size of the occluding square affects the map:

  • Large patch: faster and more broadly informative, but less spatially precise.

  • Small patch: more precise, but requires more forward passes and therefore more computation.

Occlusion sensitivity is usually more precise and intuitive than a raw saliency map, but it is slower because it requires many evaluations of the network.

Important Examples

Occlusion sensitivity can reveal object-specific evidence:

  • Covering a tennis ball in a Pomeranian image may reduce the Pomeranian score if the dog’s appearance includes the ball.

  • Covering a human face may increase the confidence that an image belongs to a dog class.

  • Covering a car wheel may reduce the score for a wheel-related object class.

Key principle: Occlusion sensitivity identifies important regions by measuring the effect of removing them.


3. Class Activation Maps

A class activation map, or CAM, identifies the image regions that contribute to a particular class prediction.

Unlike saliency maps, CAMs do not rely on backpropagating gradients all the way to the pixels. They use the spatial feature maps in the final convolutional layer and the weights connecting those features to a target class.

The Problem with Flattening

A conventional classification CNN often follows this pattern:

  1. Convolutional layers extract spatial features.

  2. Pooling layers reduce spatial resolution.

  3. The final convolutional volume is flattened.

  4. Fully connected layers produce class scores.

  5. Softmax produces class probabilities.

Flattening destroys explicit spatial organization. Once a feature map is converted into a vector and passed through fully connected layers, it becomes difficult to determine where an activation originated in the input image.

Global Average Pooling

CAM replaces the flattening-plus-fully-connected structure with global average pooling.

Suppose the final convolutional layer produces KKK feature maps, each of spatial size H×WH \times WH×W. Let the activation at location (i,j)(i,j)(i,j) in feature map kkk be Ak(i,j)A_k(i,j)Ak​(i,j).

Global average pooling converts each feature map into one scalar:

ak=1HW∑i=1H∑j=1WAk(i,j)a_k = \frac{1}{HW} \sum_{i=1}^{H} \sum_{j=1}^{W} A_k(i,j)ak​=HW1​∑i=1H​∑j=1W​Ak​(i,j)

The resulting vector is:

(a1,a2,…,aK)(a_1, a_2, \ldots, a_K)(a1​,a2​,…,aK​)

For example, a volume of size 4×4×64 \times 4 \times 64×4×6 becomes a vector of six values.

Each feature map may represent a visual pattern such as:

  • An edge.

  • A face.

  • A texture.

  • A wheel.

  • A dog-like shape.

  • A particular object part.

Class-Specific Weighted Combination

Let wkcw_k^cwkc​ be the weight connecting feature map kkk to class ccc. The score for class ccc is computed from the pooled activations:

s_c = \sum_{k=1}^{K} w_k^c a_k \] Substituting the global-average-pooling expression gives:

s_c = \sum_{k=1}^{K} w_k^c \left( \frac{1}{HW} \sum_{i=1}^{H} \sum_{j=1}^{W} A_k(i,j) \right)

Thesumscanberearranged:The sums can be rearranged:Thesumscanberearranged:

s_c = \frac{1}{HW} \sum_{i=1}^{H} \sum_{j=1}^{W} \sum_{k=1}^{K} w_k^c A_k(i,j)

Thissuggestsdefiningaclassactivationmap:This suggests defining a class activation map:Thissuggestsdefiningaclassactivationmap:

M_c(i,j)

\sum_{k=1}^{K} w_k^c A_k(i,j) $$

The map measures how strongly location (i,j)(i,j)(i,j) contributes to class ccc.

Producing the Final CAM

  1. Select the target class ccc.

  2. Obtain the feature maps from the final convolutional layer.

  3. Weight each feature map by its class-specific weight wkcw_k^cwkc​.

  4. Sum the weighted feature maps.

  5. Upsample the resulting low-resolution map to the original image size.

  6. Overlay the map on the input image.

The resulting heatmap highlights the image regions most relevant to the chosen class.

The class activation map is class-dependent: using the weights for “dog” produces a different map from using the weights for “car” or “human.”

Why Spatial Information Is Preserved

Global average pooling does not eliminate all useful spatial information. Although each feature map is summarized into one average during classification, the original spatial feature maps remain available. The class-specific weights can be applied to each spatial location before summing across locations.

Thus, the network can determine which regions contributed most to the final class score.

Properties of CAMs

Advantages:

  • Provide class-specific explanations.

  • Use spatial feature maps directly.

  • Often produce intuitive object-localization maps.

  • Require only limited architectural modification and fine-tuning.

  • Demonstrate that classification networks can learn localization even when trained only with image-level labels.

Limitations:

  • The maps are limited by the spatial resolution of the final convolutional layer.

  • Upsampling produces an approximate localization.

  • The original CAM method requires a compatible global-average-pooling architecture.

  • CAMs generally identify discriminative regions rather than precise object boundaries.

Classification and Localization

A network trained only to classify an image can still develop localization ability. A classifier may learn that specific regions, such as a dog’s face or a human’s head, are particularly useful for recognizing the class.

This phenomenon is also used in object detection. For example, classification pretraining can help an object detector develop useful localization features before being fine-tuned on object-detection data.


Methods for Understanding Internal Representations

The previous methods explain why the network produced a particular output for a particular image. The following methods investigate what the network has learned internally.

They can answer questions such as:

  • What does the network think a dog looks like?

  • What does a particular neuron detect?

  • What visual pattern activates a feature map?

  • How does representation change across layers?


4. Gradient Ascent and Class Model Visualization

Gradient ascent searches for an input image that maximizes a chosen activation or class score.

For a target class ccc, define an objective:

J(x)=sc(x)−λR(x)J(x) = s_c(x) - \lambda R(x)J(x)=sc​(x)−λR(x)

where:

  • sc(x)s_c(x)sc​(x) is the target class score.

  • R(x)R(x)R(x) is a regularization term encouraging the image to remain visually meaningful.

  • λ\lambdaλ controls the strength of regularization.

The image is updated iteratively in the direction that increases the objective:

xt+1=xt+η∇xJ(xt)x_{t+1} = x_t + \eta \nabla_x J(x_t)xt+1​=xt​+η∇x​J(xt​)

where η\etaη is the step size.

Procedure

  1. Begin with a random image or an existing image.

  2. Forward-propagate it through the network.

  3. Compute the selected class score or neuron activation.

  4. Backpropagate the gradient to the input.

  5. Update the input pixels in the direction that increases the objective.

  6. Repeat until the activation becomes large or the image stabilizes.

The result is called a class model visualization when the target is a class score.

What the Visualization Reveals

The resulting image represents what the network considers evidence for a class. Examples include:

  • A dalmatian class producing black spots on a light background.

  • A kit fox class producing orange-colored structures.

  • A flamingo class producing multiple flamingo-like forms.

  • A class associated with a dumbbell producing a hand holding a dumbbell rather than an isolated dumbbell.

The last example demonstrates that the network learns from the training distribution. If dumbbells in the training images usually appear in people’s hands, the network may associate “dumbbell” with both the object and the hand.

Why Multiple Objects May Appear

A class visualization may produce multiple copies of an object. If the network assigns a higher score to an image containing several examples of the target than to an image containing only one, gradient ascent may generate many copies.

This reflects the model’s learned scoring function, not necessarily the real-world definition of the class.


Regularization for Gradient Ascent

Without regularization, gradient ascent can produce noisy or unnatural images.

L2 Regularization

L2 regularization discourages extreme pixel values:

R(x)=∥x∥22R(x) = \|x\|_2^2R(x)=∥x∥22​

This encourages pixel values to remain relatively small and prevents individual pixels from becoming excessively large.

After optimization, pixel values may be rescaled into a displayable range such as 000 to 255255255. The optimization itself may not naturally constrain values to this range, so clipping may also be required.

Pixel-Value Constraints

The image can be clipped so that:

0≤xi,j,k≤2550 \leq x_{i,j,k} \leq 2550≤xi,j,k​≤255

This keeps the optimized result within a conventional image range.

Gaussian Blurring

High-frequency pixel variation often produces noisy visualizations. Repeated Gaussian blurring encourages smooth transitions between neighboring pixels.

Blurring acts as another form of regularization by reducing patterns that are mathematically useful to the network but visually meaningless to humans.

Interpreting Class Visualizations

A realistic-looking class visualization does not necessarily prove that the model is accurate. However, it can help determine whether the network appears to rely on sensible visual structures.

The usefulness of a visualization depends on:

  • The quality of the regularization.

  • The architecture of the network.

  • The training data.

  • The chosen layer or class.

  • Whether the model’s learned associations correspond to human concepts.


Visualizing Intermediate Activations

Gradient ascent can be applied to any activation, not only the final class score.

Suppose an internal neuron or feature map has activation a(x)a(x)a(x). An image can be optimized to maximize:

J(x)=a(x)−λR(x)J(x) = a(x) - \lambda R(x)J(x)=a(x)−λR(x)

The resulting image shows what input pattern causes that internal unit to activate strongly.

This is often more informative than visualizing only the final output because it reveals how representation develops through the network.


5. Dataset Search

Dataset search identifies real images from a dataset that produce the highest activation for a selected neuron or feature map.

Rather than synthesizing an image through optimization, dataset search finds naturally occurring examples that already activate the network strongly.

Procedure

  1. Select a layer and a feature map.

  2. Forward-propagate many dataset images through the network.

  3. Record the activation produced by the selected feature map for each image.

  4. Rank the images by activation strength.

  5. Display the top-scoring images.

For example, if the selected feature map is one of 256256256 maps in a layer, the method finds the images that maximize that map’s activation.

Interpreting the Results

The top images may reveal that a feature map detects:

  • Shirts or clothing.

  • Edges.

  • Circles.

  • Faces.

  • Wrinkles.

  • Printed text.

  • Wheels.

  • Specific textures or object parts.

Dataset search is useful because it shows examples from the actual data distribution rather than artificial images that may be difficult to interpret.

Advantages and Limitations

Advantages:

  • Produces realistic examples.

  • Directly reveals the data patterns associated with an activation.

  • Can expose unexpected features learned by the network.

  • Often easier to interpret than synthetic gradient-ascent images.

Limitations:

  • Requires evaluating many images.

  • The highest-scoring examples may not completely explain the neuron.

  • The selected activation may respond to several related patterns.

  • Results depend on the diversity and quality of the dataset.


Receptive Fields

An activation in a CNN generally sees only part of the original input image. The portion of the input that can influence an activation is called its receptive field.

Receptive Field Growth Through the Network

Consider a convolutional network processing a 64×6464 \times 6464×64 image.

  • An activation near the first convolutional layer depends on a small local region.

  • Later convolutions combine information from earlier activations.

  • As depth increases, each activation depends on a larger portion of the original image.

  • Deep activations may eventually incorporate information from nearly the entire image.

The receptive field depends on:

  • Filter sizes.

  • Strides.

  • Pooling operations.

  • The number of preceding layers.

Why Dataset-Search Images May Be Cropped

When the top examples for a feature map appear as small crops rather than complete images, the crop represents the receptive field of the selected activation.

An activation in an early layer sees only a small local patch, so the corresponding top examples can be displayed as small image regions. An activation in a deeper layer sees more of the input, so its corresponding crops are larger and may contain complete objects or object parts.

Localization of an Activation

To identify the region associated with an activation:

  1. Track the activation’s spatial position in its feature map.

  2. Account for the stride and filter size of each preceding layer.

  3. Map that position back through the network.

  4. Identify the corresponding receptive field in the original image.


6. Deconvolution and Network Reconstruction

Deconvolution-based visualization reconstructs the input-space pattern that caused a selected internal activation.

The method reverses the operations used during the forward pass:

  • Pooling is approximately reversed through unpooling.

  • ReLU processing is reversed using a reconstruction rule.

  • Convolution is reversed using a transposed or deconvolution operation.

The goal is not necessarily to recover the exact original image. Instead, the goal is to identify the visual structure responsible for an activation.

Why Deconvolution Is Useful

Deconvolution is used for:

  • Visualizing intermediate feature maps.

  • Reconstructing the image region associated with a neuron.

  • Understanding what individual filters detect.

  • Image segmentation.

  • Decoder networks.

  • Generative models.

  • Upsampling encoded representations.

In segmentation, a convolutional encoder reduces the spatial dimensions of an image while extracting meaningful features. A deconvolutional decoder then upsamples the representation to produce a segmentation mask with the original image dimensions.


Convolution as a Matrix Operation

A one-dimensional convolution can be represented as matrix multiplication.

Suppose a padded input vector has length 121212, with the meaningful values represented as:

x=(0,0,x1,x2,…,x8,0,0)Tx = (0,0,x_1,x_2,\ldots,x_8,0,0)^Tx=(0,0,x1​,x2​,…,x8​,0,0)T

Assume:

  • Filter size: 444

  • Stride: 222

  • Padding: 222

The convolution output has size:

ny=⌊nx−f+2ps⌋+1n_y = \left\lfloor \frac{n_x - f + 2p}{s} \right\rfloor + 1ny​=⌊snx​−f+2p​⌋+1

where:

  • nxn_xnx​ is the input size.

  • fff is the filter size.

  • ppp is the padding.

  • sss is the stride.

Using the values above:

ny=⌊12−4+2(2)2⌋+1=7n_y = \left\lfloor \frac{12-4+2(2)}{2} \right\rfloor + 1 = 7ny​=⌊212−4+2(2)​⌋+1=7

If the padded vector is counted as already incorporating the padding and the effective convolution setup is defined accordingly, the resulting output dimensions depend on the precise convention being used. The central idea is that each output is a weighted sum of a local input window.

For a filter:

w=(w1,w2,w3,w4)w = (w_1,w_2,w_3,w_4)w=(w1​,w2​,w3​,w4​)

one output may be:

y1=w1(0)+w2(0)+w3x1+w4x2y_1 = w_1(0)+w_2(0)+w_3x_1+w_4x_2y1​=w1​(0)+w2​(0)+w3​x1​+w4​x2​

The next output, shifted by a stride of two, is:

y2=w1x1+w2x2+w3x3+w4x4y_2 = w_1x_1+w_2x_2+w_3x_3+w_4x_4y2​=w1​x1​+w2​x2​+w3​x3​+w4​x4​

All outputs can be written as:

y=Wxy = Wxy=Wx

where WWW is a structured matrix containing shifted copies of the filter weights and zeros elsewhere.

Structure of the Convolution Matrix

The matrix WWW contains:

  • Filter weights in positions corresponding to the local receptive field.

  • Zeros where an input value does not affect a particular output.

  • Shifts determined by the stride.

  • Boundary effects determined by padding.

This representation makes it possible to reason about convolution using ordinary linear algebra.


Transposed Convolution

If:

y=Wxy = Wxy=Wx

then an inverse-like reconstruction would ideally be:

x=W−1yx = W^{-1}yx=W−1y

However, WWW is not always square or invertible. Therefore, practical deconvolution commonly uses the transpose of the convolution matrix:

xreconstructed=WTyx_{\text{reconstructed}} = W^T yxreconstructed​=WTy

This operation is often called:

  • Transposed convolution.

  • Deconvolution.

  • Fractionally strided convolution.

The transposed convolution reverses the spatial direction of the mapping and generally increases height and width.

Orthogonal-Matrix Intuition

If WWW is orthogonal, then:

WTW=IW^T W = IWTW=I

and:

W−1=WTW^{-1} = W^TW−1=WT

In this special case, the transpose acts as the exact inverse. Real CNN filters are not generally orthogonal, so the reconstruction is usually approximate.

An edge-detection filter can sometimes produce an approximately orthogonal structure, but this is not guaranteed.

Why the Assumption Matters

For visualization, the network’s existing convolution filters are reused during reconstruction. The deconvolutional network is not necessarily trained independently. The transpose provides a practical way to reverse the learned transformations approximately.

For segmentation or image generation, the upsampling layers can instead have their own trainable filters. In that case, exact invertibility is not required because the decoder learns how to produce the desired output.


Sub-Pixel Convolution Interpretation

A transposed convolution can be implemented in a way that resembles an ordinary convolution:

  1. Insert zeros between elements of the input feature map.

  2. Reduce the stride.

  3. Flip the filter weights.

  4. Apply a normal convolution.

  5. Handle padding and cropping appropriately.

For a one-dimensional activation vector:

y=(y1,y2,y3,y4,y5)y = (y_1,y_2,y_3,y_4,y_5)y=(y1​,y2​,y3​,y4​,y5​)

zero insertion creates a longer vector such as:

(0,0,y1,0,y2,0,y3,0,y4,0,y5,0,0)(0,0,y_1,0,y_2,0,y_3,0,y_4,0,y_5,0,0)(0,0,y1​,0,y2​,0,y3​,0,y4​,0,y5​,0,0)

The filter is then applied with a smaller stride. In a two-dimensional setting, zeros are inserted between rows and columns, allowing the convolution to produce a larger spatial output.

Equivalent Filter Decomposition

A two-dimensional sub-pixel convolution can sometimes be understood as several ordinary convolutions using different subsets of the filter weights. The resulting outputs are interleaved to form the upsampled image.

The important intuition is that the operation:

  • Expands spatial dimensions.

  • Uses learned weights.

  • Produces overlapping contributions.

  • Can be implemented using standard convolutional operations.


Reconstructing Activations Through a CNN

To visualize a selected activation:

  1. Select a feature map at a chosen layer.

  2. Find the activation with the largest value.

  3. Set other activations to zero.

  4. Record the position of the selected activation.

  5. Reverse the subsequent operations:

    • Unpooling.

    • ReLU reconstruction.

    • Transposed convolution.

  6. Continue backward through earlier layers.

  7. Inspect the resulting image-space reconstruction.

The reconstruction usually covers only the receptive field of the selected activation, not the entire original image.

Why Zero Out Other Activations?

If all activations are retained, the reconstruction combines evidence from many different features and may become cluttered or noisy. Keeping only one strong activation makes it easier to determine what that particular unit detected.


Unpooling

Max pooling is not mathematically invertible because it retains only the maximum value in each local region.

For example, a pooling region might contain:

[01−142]\begin{bmatrix} 0 & 1 \\ -1 & 42 \end{bmatrix}[0−1​142​]

Max pooling outputs 424242, but the other values are discarded.

Therefore, the original input cannot be recovered exactly from the pooled value alone.

Switches

During the forward pass, the location of the maximum can be stored in a binary switch matrix. During unpooling:

  • The pooled value is placed at the stored maximum location.

  • Other positions are filled with zeros.

This approximates the inverse of max pooling.

The switches preserve where the maximum occurred, but not the values that were discarded.

Relationship to Backpropagation

The same switch concept appears in max-pooling backpropagation. Only the input that produced the maximum receives the gradient; the other inputs receive zero gradient.


ReLU Reconstruction

The ReLU function is:

ReLU⁡(z)=max⁡(0,z)\operatorname{ReLU}(z) = \max(0,z)ReLU(z)=max(0,z)

During ordinary backpropagation:

  • Positive forward activations pass their gradients.

  • Negative forward activations receive zero gradient.

For example, if an input to ReLU is negative, it had no influence through that ReLU output and its backward gradient is set to zero.

ReLU DeconvNet Rule

Visualization methods may use a modified ReLU reconstruction rule rather than standard ReLU backpropagation. The purpose is to preserve positive evidence for the selected activation and reduce the influence of unrelated forward-pass information.

This is a visualization heuristic rather than a mathematically exact inverse. It is designed to reveal which positive input patterns support an activation.


Visualizing What Different Layers Learn

Visualization studies show that CNN representations tend to become more abstract with depth.

First Convolutional Layer

The first layer operates directly on pixels. Its filters often learn:

  • Horizontal edges.

  • Vertical edges.

  • Diagonal edges.

  • Color transitions.

  • Simple textures.

Because the first-layer weights directly multiply pixel values, the filters themselves can often be interpreted visually.

For example, a filter with diagonal positive and negative weights may respond strongly to diagonal edges.

Middle Layers

Middle layers combine simple features into more meaningful patterns, such as:

  • Circles.

  • Curves.

  • Corners.

  • Textures.

  • Repeated shapes.

  • Object parts.

The features become more invariant to small changes in position, scale, color, or orientation.

Deeper Layers

Deep layers represent more complex and abstract concepts, such as:

  • Faces.

  • Clothing.

  • Animal parts.

  • Books.

  • Wheels.

  • Groups of objects.

  • Text.

  • Wrinkles or other textures.

A feature map may activate for several variations of the same concept rather than one exact visual arrangement.

Emergent Features

The network is not explicitly told to detect faces, wrinkles, or printed text. It receives only the final training labels. Nevertheless, internal features emerge because they help the network make the final classification decisions.

For example:

  • A text detector may help identify a book.

  • Detecting multiple books may help identify a bookcase.

  • Detecting a face may help classify a person or an animal.

  • Detecting wrinkles may help distinguish clothing categories.

Key principle: Internal features can acquire semantic meaning even when the training labels never explicitly name those features.


Deep Dream

Deep Dream is a visualization technique that amplifies patterns already detected by a neural network.

Basic Procedure

  1. Start with an input image.

  2. Forward-propagate it through the network.

  3. Select a layer, called the dreaming layer.

  4. Use the layer’s activations as the signal to amplify.

  5. Backpropagate that signal to the input.

  6. Update the pixels to increase the selected activations.

  7. Repeat the process.

Unlike ordinary class model visualization, Deep Dream does not necessarily optimize a single class score. It reinforces whatever patterns the network already detects in the image.

Why Patterns Become Stronger

If a region slightly resembles a dog, the dog-related feature may activate. Deep Dream increases that activation, causing the region to look more dog-like. The altered image may then produce an even stronger dog activation, creating a feedback loop.

Repeated iterations can cause:

  • Animals to appear in clouds.

  • Faces to emerge from textures.

  • Buildings or towers to form.

  • Repeated patterns to become increasingly elaborate.

  • Lower-layer edges and textures to become exaggerated.

Layer Choice

The chosen layer determines the visual character of the result:

  • Early layers: emphasize edges, colors, and simple textures.

  • Middle layers: emphasize patterns, shapes, and object parts.

  • Deep layers: emphasize recognizable objects and complex semantic structures.

Deep Dream is visually striking but should not be interpreted as a literal picture of everything the network knows. It is an amplification of the network’s existing activations under a particular optimization process.


Choosing an Interpretability Method

To Determine Which Input Regions Caused a Prediction

Use:

  • Saliency maps: fast pixel-level sensitivity.

  • Occlusion sensitivity: precise evidence based on removing regions.

  • Class activation maps: class-specific spatial localization.

To Understand a Neuron or Feature Map

Use:

  • Gradient ascent: synthesize an input that maximizes the activation.

  • Dataset search: find real examples that strongly activate the unit.

  • Deconvolution: reconstruct the input-space region responsible for the activation.

To Understand How the Network Represents the Visual World

Use:

  • Gradient-ascent visualizations.

  • Deep Dream.

  • Layer-by-layer feature-map analysis.

  • Top-activating dataset examples.

  • Deconvolutional reconstructions.


Practical Applications

Segmentation

Saliency maps can provide rough object localization or segmentation by thresholding pixel importance. However, this approach is usually less effective than modern segmentation methods.

Deconvolution and decoder networks are more commonly used to upsample encoded representations and produce full-resolution segmentation masks.

Image Reconstruction and Generation

Transposed convolutions can reconstruct larger images from compact representations. They are used in:

  • Generative adversarial networks.

  • Image decoders.

  • Autoencoders.

  • Segmentation networks.

  • Super-resolution systems.

Debugging Model Behavior

Visualization can reveal whether a model is:

  • Looking at the intended object.

  • Relying on background artifacts.

  • Using irrelevant contextual cues.

  • Overfitting to a particular object part.

  • Confusing correlated objects.

  • Ignoring important evidence.

Detecting Dead Neurons

A feature map that remains dark for nearly every input may indicate a dead or inactive feature detector.

This can happen when:

  • A neuron consistently receives negative inputs before ReLU.

  • Its parameters are poorly initialized or trained.

  • The feature is not useful for the current task.

  • The network architecture prevents useful gradient flow.

Visualization tools can reveal such inactive feature maps directly.


Summary of Core Concepts

  • Pre-softmax scores are preferable to probabilities when computing attribution because probabilities depend on all class scores.

  • Saliency maps backpropagate the gradient of a class score to the input pixels.

  • Occlusion sensitivity measures prediction changes after systematically hiding image regions.

  • Class activation maps combine final convolutional feature maps using class-specific weights and upsample the result.

  • Global average pooling preserves enough spatial structure to support class-specific localization.

  • Gradient ascent synthesizes images that maximize a class score or internal activation.

  • Dataset search finds real images that strongly activate a selected neuron or feature map.

  • Receptive fields describe the portion of the input that can influence an activation.

  • Deconvolution reconstructs input-space patterns from internal activations using unpooling, ReLU reconstruction, and transposed convolution.

  • Unpooling uses stored max-pooling switches to place activations back into approximate spatial locations.

  • Transposed convolution expands spatial dimensions and can be understood using a transposed convolution matrix or zero-insertion formulation.

  • Deep Dream amplifies patterns already detected by a network.

  • CNNs typically learn simple edges in early layers, textures and shapes in middle layers, and semantic object concepts in deeper layers.

  • Visualization supports scientific analysis, model debugging, localization, segmentation, reconstruction, and trust in high-stakes applications.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent