Visualizing Convolutional Networks
Visualizing and Understanding Convolutional Networks
Convolutional networks can produce accurate class scores, bounding boxes, or pixel-level labels, but their intermediate computations are often difficult to interpret. Network visualization refers to methods that help explain what features a network represents, which input regions affect its decisions, and what kinds of patterns activate its internal units.
These methods are useful for building intuition and examining a model’s behavior. They do not automatically establish that a model is reliable or that its internal features have a single, easily stated meaning.
What a Convolutional Network Represents
A convolutional network transforms an input image through successive layers. Early layers operate on image pixels; later layers operate on features produced by earlier layers. A network’s output might be a class score, a set of object locations, or a label for each pixel.
Different vision tasks produce different kinds of outputs:
Semantic segmentation assigns a category label to each pixel but does not distinguish separate instances of the same category.
Classification with localization predicts a category and one or more object locations when the number of relevant objects is fixed or otherwise specified.
Object detection predicts locations and categories for an unknown number of object instances.
Instance segmentation detects individual objects and labels the pixels belonging to each instance.
Understanding a network involves examining not only its output, but also the features formed along the way. Visualization methods can be grouped broadly into methods based on activations and methods based on gradients.
Visualizing First-Layer Filters
The first convolutional layer receives image channels directly. Its filters can therefore be displayed as small images, providing a relatively direct view of the patterns to which the layer responds.
For example, a filter in a network that takes RGB images has a weight for each input color channel at each spatial position. These weights can be arranged and displayed as a small color image. A network with many filters can have each filter visualized separately.
Common first-layer patterns
Filters in the first layer often resemble:
Oriented edges at different angles
Bars or boundaries between light and dark regions
Patterns that respond to particular color contrasts, such as opposing colors
This resembles some known properties of early visual processing in humans, where neurons respond to oriented edges and related local patterns.
Why filter weights indicate preferred patterns
A convolutional filter computes an inner product between its weights and a local image patch. If the input patch is aligned with the filter’s weights, the inner product tends to be large. Under a constraint on the input’s norm, the input that maximizes the inner product is aligned with the filter.
Thus, visualizing a first-layer filter gives an approximate picture of the local pattern that can strongly activate it. The interpretation is not exact: visualization often rescales the weights for display and usually does not show the effects of biases or later nonlinearities.
Why Intermediate-Layer Weights Are Hard to Interpret
A filter in a later convolutional layer does not operate directly on RGB pixels. It operates on feature maps created by earlier layers. For example, a filter may take a tensor with many channels as input and combine information across all those channels.
Displaying the weights of such a filter as an image is therefore ambiguous:
Its channels represent learned features, not red, green, and blue.
Its activation depends on patterns produced by earlier layers.
The visualized weights do not directly show which image pixels or semantic structures will activate it.
A later filter’s weights can be viewed as describing which combinations of earlier-layer activations it responds to. But because those earlier activations are themselves abstract, the weights alone usually provide little intuitive explanation. Other visualization techniques are needed to relate intermediate features back to the input image.
Examining Features Near the Network Output
A useful way to study a network is to compare the feature representations it assigns to different images. For example, an image classifier may produce a vector of thousands of feature values in a layer immediately before its final class-scoring layer. Such a vector is often called a feature representation or embedding.
Nearest neighbors in feature space
To examine what the representation captures:
Run a collection of images through the trained network.
Record the feature vector for each image.
For a chosen image, find other images with nearby feature vectors.
Nearest neighbors in raw pixel space tend to have similar colors, textures, or layouts. Nearest neighbors in a learned feature space can look quite different in their pixels while showing similar semantic content. For instance, two images of the same kind of animal may be close in feature space even if the animal appears on opposite sides of the image.
This suggests that the learned representation captures some semantic properties that are relatively insensitive to exact pixel arrangement. However, ordinary classification training does not necessarily include a loss that explicitly requires same-category images to be close together. Such clustering can emerge as a consequence of training, but it is not guaranteed. Methods such as contrastive or triplet losses can impose explicit relationships between feature distances.
Dimensionality reduction with t-SNE
A feature vector with thousands of dimensions cannot be directly plotted in a two-dimensional diagram. t-SNE—t-distributed stochastic neighbor embedding—is a nonlinear dimensionality-reduction method used to create low-dimensional visualizations that preserve aspects of local neighborhood structure.
A typical visualization process is:
Extract feature vectors from many images.
Use t-SNE to map the vectors to two-dimensional coordinates.
Display a representative image near each coordinate.
The resulting plot can reveal clusters of visually or semantically related examples. For instance, handwritten digits may form separate groups corresponding to different digit classes.
A t-SNE plot is only an approximate, low-dimensional view of a much higher-dimensional space. Distances and densities in the plot should not be treated as exact measurements of the original feature space. The reduction can cause overlap, distort global geometry, and hide details.
Activation Maps and Maximally Activating Patches
A convolutional layer’s output is commonly represented as an activation volume: a three-dimensional tensor with channels, height, and width. Each channel is a two-dimensional activation map that records the response of one learned filter across spatial locations.
Visualizing an activation map as a grayscale image can show where a feature responds strongly in the input. For example, an activation map might respond mainly around a face in one image. That observation suggests the feature is sensitive to a face-like pattern, though a single example is not enough to establish that this is its only function.
Activation-map dimensions depend on the layer’s stride, padding, pooling, and other operations. They therefore need not have the same spatial dimensions as the input image.
Maximally activating patches
A more systematic approach is to find image regions that strongly activate a selected feature:
Choose a channel or unit in a convolutional layer.
Run many images through the network.
Find the locations where that feature has its largest activations.
Map those locations back to their corresponding input-image regions.
Display the resulting patches, ordered by activation strength.
The patches give examples of patterns that strongly drive the feature. A feature might respond to circular regions, text, curved edges, faces, or object parts.
As the selected layer becomes deeper, its units typically have larger receptive fields: each unit depends on a larger region of the input image. Consequently, deeper units may respond to more complex patterns or larger object parts. A convolutional channel shares filter weights across spatial positions, so the same feature can respond to a pattern wherever it appears in the image.
Maximally activating patches are evidence about what a feature can respond to, not proof of a complete or exclusive definition of that feature.
Occlusion Experiments
An occlusion experiment tests how a classifier’s output changes when parts of an image are hidden.
A common procedure is:
Choose an input image and a class score or predicted probability to examine.
Cover a small region of the image, often by replacing it with the dataset’s mean pixel value.
Run the modified image through the network and record the selected output.
Move the occluding region across the image and repeat.
Display the results as a heat map.
If covering a particular region causes the class score to drop substantially, that region may have contributed important evidence for the prediction. A map can also reveal reliance on context: for example, the network may respond not only to the main object but also to background structures associated with that class.
Occlusion maps are descriptive tools for analyzing a trained model. They do not directly improve the model, and their interpretation depends on how regions are replaced. An artificial replacement may itself create an unusual input that affects the network.
Saliency Maps
A saliency map estimates which input pixels most affect a selected class score. It is computed from the gradient of that score with respect to the input image.
Let sc(x) be the score for class c given image x. The gradient
measures how the score changes for small changes to the image pixels. A large gradient magnitude at a pixel indicates that a small change there could have a relatively large local effect on the score.
A saliency map often highlights contours or regions associated with the predicted object. It gives a first-order, local explanation: it describes sensitivity near the particular input image, rather than identifying every reason the classifier could make the same decision.
Saliency methods have also been explored for tasks such as segmentation. For example, a saliency map can be combined with a separate interactive segmentation method to help isolate an object. Such combinations can work in some cases, but they are generally less reliable than a network trained directly with segmentation supervision.
Guided Backpropagation
A related approach asks which input pixels influence an intermediate neuron, rather than a final class score. Ordinary backpropagation can compute the gradient of an intermediate activation with respect to the input image.
Guided backpropagation modifies how gradients pass through ReLU activations. In addition to the usual forward-pass condition for a ReLU, it allows only positive backward signals to pass through. In effect, negative gradients are suppressed at ReLU units.
This procedure is not the ordinary gradient of the network’s output. It is a modified visualization rule intended to produce cleaner-looking input attributions. It can highlight image structures associated with an intermediate activation and can be combined with maximally activating patches to inspect which parts of those patches are influential.
Synthesizing Images by Gradient Ascent
Instead of asking which parts of an existing image activate a unit, a network visualization method can ask what kind of input would activate it strongly. This is done by holding the trained network’s weights fixed and changing the image pixels to increase a chosen score.
For a selected score f(x), the basic update is
where x is the image, η is a step size, and the network parameters remain fixed. The process begins from an initial image—such as noise or a uniform image—and repeats forward and backward computations until the chosen score becomes large.
This method can target:
A class score, to visualize patterns that increase confidence in a class
An intermediate activation, to visualize patterns that excite a selected feature
Why regularization is needed
Without constraints, optimization can produce an image that scores highly but looks like noise. The network may exploit small, unnatural patterns that strongly affect its computations. A regularizer encourages the synthesized image to have properties associated with natural images while still increasing the target score.
Early approaches used a simple penalty on the image’s squared norm, such as
More elaborate procedures may blur the image periodically, suppress small values or weak-gradient changes, or constrain pixel values to an allowed range. These operations encourage spatial smoothness or keep the image closer to valid image data.
The visualizations can still be ambiguous. A class may be activated by several distinct kinds of images, a property known as multimodality. For example, a scene category might include both close-up images of objects on shelves and wide images of people shopping. A single optimization run may find only one of these modes. Clustering examples and initializing optimization near different clusters can help reveal multiple representative patterns. Stronger image priors can produce more natural-looking results, but they also influence what the visualization displays.
Fooling Images
Gradient-based optimization can also modify an existing image so that a classifier assigns it a different label. A fooling image is an input that appears unchanged or nearly unchanged to a human observer but is classified as a different category by a model.
For example, an optimization procedure can make small pixel changes to an image of one object until the network assigns a high score to an unrelated class. The resulting changes may look like weak patterns or noise rather than recognizable features of the target class.
This illustrates a difference between human perception and a classifier’s learned decision boundaries. A network can be sensitive to patterns that are not visually meaningful to people. Fooling images are related to adversarial examples, though the exact construction and constraints vary. Their existence motivates further study of model robustness and why a classifier makes particular decisions.
DeepDream
DeepDream amplifies patterns a network already detects in an image. Rather than increasing one class score, it increases the activations of a selected network layer.
A typical procedure is:
Run an image through the network to a chosen layer.
Set the backward signal at that layer based on its existing activations.
Backpropagate to the image.
Update the image to strengthen those activations.
Repeat.
This tends to enhance patterns already present in the image. Small textures can develop into more prominent shapes, and higher-level features can appear as recognizable or surreal objects.
The layer selected affects the result. Lower layers tend to emphasize edges, colors, and local textures; higher layers tend to amplify more complex patterns learned by the network. DeepDream is primarily a generative visualization technique rather than a rigorous explanation of a classifier’s decision. Its characteristic recurring patterns can nevertheless reveal something about the training data and model: a network trained on many categories of dogs may often generate dog-like forms.
Multiscale processing can make the effects appear at different image sizes. The image can be optimized at a small scale, enlarged, and optimized again, producing increasingly elaborate structures.
Feature Inversion
Feature inversion asks how much information about an image is retained by a network’s representation at a particular layer.
The procedure is:
Run an original image through the network.
Record its feature representation at a chosen layer.
Start from a new image, often random noise.
Adjust the new image so that its features at the chosen layer match the recorded features.
If Fl(x) is the feature representation at layer l, an inversion objective can minimize
Optimization also often uses an image regularizer, such as a total variation penalty. This penalizes differences between neighboring pixels and encourages spatial smoothness.
Reconstructions from earlier layers can preserve fine details and closely resemble the original pixels. Reconstructions from deeper layers often retain broad shapes and object identity while losing precise color, texture, or pixel-level detail. This suggests that deeper representations become less sensitive to some low-level image variations while preserving more abstract or semantic information.
Neural Texture Synthesis
Texture synthesis aims to create a new, larger image that resembles the texture of a given example. Traditional methods can generate simple textures by repeatedly copying pixels or patches from the input, but they often struggle with complex patterns.
Neural texture synthesis describes texture using the co-occurrence of features in a pretrained convolutional network.
Gram-matrix texture descriptors
Suppose a network layer produces an activation tensor with C channels and spatial dimensions H×W. At each spatial position, the layer has a C-dimensional feature vector. These vectors describe local appearances in the network’s feature space.
A Gram matrix summarizes how feature channels co-activate. If the activation tensor is reshaped into a matrix F with dimensions C×HW, a Gram matrix can be computed as
Each entry summarizes the joint activity of a pair of channels across spatial positions. The Gram matrix averages over the spatial arrangement, so it captures feature co-occurrences and second-order statistics without preserving the exact location of each pattern.
To synthesize a texture:
Pass the example texture through a pretrained network.
Compute its Gram matrices at selected layers.
Initialize a new image.
Pass the new image through the same network.
Adjust the new image so its Gram matrices match those of the example.
Matching Gram matrices at different layers affects the generated texture. Lower-level layers tend to reproduce colors and small patterns. Higher-level layers can capture larger structures, such as whole rocks or cranberries. A practical objective may combine losses from several layers, sometimes with different weights.
Because the Gram-matrix representation discards exact spatial layout, the synthesized image can have similar texture statistics while differing substantially from the original image.
Neural Style Transfer
Neural style transfer combines feature inversion with texture synthesis. It uses two input images:
A content image, which determines the main objects and spatial arrangement.
A style image, which determines the desired texture and visual style.
The generated image is optimized to preserve features of the content image while matching the style image’s Gram-matrix statistics. A simplified objective is
where Lcontent measures feature mismatch with the content image, Lstyle measures Gram-matrix mismatch with the style image, and α and β control the trade-off.
A typical optimization process is:
Compute feature representations of the content image.
Compute Gram matrices of the style image.
Initialize an output image.
Compute content and style losses for the output.
Backpropagate the combined loss to the output pixels.
Update the output and repeat.
The result retains much of the content image’s structure while adopting textures and patterns associated with the style image. Adjusting the loss weights changes the balance between content and style. Resizing the style image before computing its Gram matrices can also affect the scale of patterns transferred to the result. Multiple style images can be combined by matching multiple sets of style statistics.
This optimization-based method offers fine-grained control, but it can be slow because each output image requires many forward and backward passes through a network. High-resolution images are particularly expensive.
Feed-Forward Style Transfer
A faster approach trains a separate feed-forward network to produce stylized images. Instead of optimizing each new image from scratch, the network learns to map a content image directly to a stylized output.
During training:
A content image is passed through the stylization network.
The output is evaluated using content and style losses.
Those losses update the network’s weights.
Once trained, producing a stylized image requires only a forward pass. This can be much faster than iterative optimization, though a network trained for one style generally applies that style rather than an arbitrary new one.
These networks often use an encoder-decoder structure: spatial information is reduced through convolutional processing and then expanded to produce an output image. Instance normalization has been used in place of batch normalization to improve stylization quality.
Later approaches condition a single network on the requested style, allowing one trained network to produce several styles. Some can also blend styles at inference time. These methods make style transfer practical for interactive and real-time applications, while retaining a trade-off between speed, flexibility, and output quality.
Key Takeaways
First-layer filters can often be interpreted by viewing their weights because they operate directly on image pixels.
Later-layer weights are harder to interpret because they combine abstract features from earlier layers.
Nearest neighbors and dimensionality reduction reveal patterns in learned feature spaces, but their visualizations are approximate.
Activation maps, maximally activating patches, occlusion, saliency, and guided backpropagation provide different views of which features or input regions influence a network.
Gradient-based image synthesis reveals inputs that excite a class or feature, but regularization is needed to avoid unnatural patterns.
Feature inversion probes what information different layers retain; texture synthesis uses Gram matrices to capture feature co-occurrences.
Style transfer combines content-feature matching with texture-statistic matching, and feed-forward networks make stylization much faster.
These techniques help people inspect complex networks, but visual explanations are approximations and do not by themselves guarantee that a model’s reasoning is complete, reliable, or human-like.

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