Feature Map in CNN
Slide a kernel across an image to perform multiplications and generate a feature map.
Slide a kernel across an image to perform multiplications and generate a feature map.
The convolution step is the heart of Convolutional Neural Networks (CNNs), the nets that power most modern computer vision. This interactive visualizes that exact process. A small matrix, called a kernel or filter, slides over an input pic. At each position, it does an item-wise multiplication and sums the results to give a single pixel in the output, known as a feature map. A single convolutional layer applies many filters in parallel, giving one feature map per filter. An early layer might have 32 filters detecting edges at other angles. A deeper layer might have 256 filters detecting textures, shapes. Or object parts. The spatial dimensions of the feature map shrink with each layer (unless padding is used), while the count of channels grows — the network trades spatial resolution for semantic richness. Pooling layers between convolutions downsample each feature map more, keeping the strongest activations and discarding the rest. After ReLU zeroes the negative vals, the surviving positive entries are the locations where the filter's pattern was found. A feature map with large vals in one corner and zeros elsewhere means the pattern exists in that corner and nowhere else. This page applies a single filter to an pic, shows the resulting feature map as a heatmap. And lets you swap filters to see how other patterns give other maps.
Slide a kernel across an image to perform multiplications and generate a feature map.
The core building block of how Convolutional Neural Networks (CNNs) see the world.
The convolution step is the heart of Convolutional Neural Networks (CNNs), the nets that power most modern computer vision. This interactive visualizes that exact process. A small matrix, called a kernel or filter, slides over an input pic. At each position, it does an item-wise multiplication and sums the results to give a single pixel in the output, known as a feature map. A single convolutional layer applies many filters in parallel, giving one feature map per filter. An early layer might have 32 filters detecting edges at other angles. A deeper layer might have 256 filters detecting textures, shapes. Or object parts. The spatial dimensions of the feature map shrink with each layer (unless padding is used), while the count of channels grows — the network trades spatial resolution for semantic richness. Pooling layers between convolutions downsample each feature map more, keeping the strongest activations and discarding the rest. After ReLU zeroes the negative vals, the surviving positive entries are the locations where the filter's pattern was found. A feature map with large vals in one corner and zeros elsewhere means the pattern exists in that corner and nowhere else. This page applies a single filter to an pic, shows the resulting feature map as a heatmap. And lets you swap filters to see how other patterns give other maps.
Why do this? Since other kernels are designed to detect other features. One kernel might be good at finding vertical edges. Another might detect horizontal edges. A more complex one might activate when it sees a certain texture or curve. The resulting feature map is an pic that shows "where" in the input the kernel found the feature it's looking for.
In a real CNN, the network learns the best kernel vals in training to solve a set task (like classifying cats vs. dogs). Here, you can manually set the kernel to build intuition for how they work.
A feature map is the output of one filter applied across the whole pic — a grid showing where that filter's pattern was found. And how strongly.
Apply a vertical-edge filter to a photograph and the resulting map is bright along vertical edges and near zero elsewhere. It is not a picture of the pic. It is a map of one set kind of evidence.
A convolution layer with 64 filters gives 64 such maps, stacked into a tensor of shape (height, width, 64). Each channel answers a other question about each location: is there a vertical edge here? a red-to-blue transition? a corner?
The spatial dimensions are preserved in a loose sense — position (10, 15) in the feature map corresponds to a patch centred near (10, 15) in the input, scaled by whatever striding and pooling has happened so far. That correspondence is what makes activation maps interpretable and what lets segmentation and detection to recover locations.
| Value in the map | Meaning |
|---|---|
| Large positive | Strong match for the filter's pattern |
| Near zero | Pattern absent |
| Negative (before ReLU) | The opposite pattern — e.g. a reversed edge |
| Zero after ReLU | Everything negative has been discarded |
That last row is worth pausing on. ReLU throws away the negative half of each response. It means a filter effectively detects its pattern in one polarity just. Networks compensate by learning pairs of opposite filters. It is why filter visualisations of early layers so often come in mirrored pairs.
The depth of the feature map stack is the count of filters. And it is a design choice. The spatial size shrinks as you go deeper, through striding and pooling. A typical progression: 224×224×3 input, then 112×112×64, 56×56×128, 28×28×256, 14×14×512. Space contracts, depth expands — fewer positions, more distinct things detected at each.
Early feature maps look like the pic: edges, colour edges, textures, all clearly spatially aligned with what you can see.
Deep feature maps do not. At 7×7×512, each of the 49 positions summarises a large region of the first photograph. And each of the 512 channels responds to something abstract — "dog-face-like", "wheel-like", "text-like". Visualising them shows blobs, not pictures.
This progression is just what makes transfer learning work. The early layers of a network trained on ImageNet have learned generic visual primitives that apply to almost any pic task. So they can be reused unchanged. The late layers are set to the first classes and are the ones you replace.
Select the Identity kernel. Notice the output feature map is identical to the input pic. This is since the kernel has a '1' in the center and '0's elsewhere. It's a perfect baseline—it doesn't change anything.
Draw a vertical line. Now, select the Edge Detection (Vert) kernel. The feature map will light up strongly along the line you drew. Now, select the Edge Detection (Horz) kernel. The feature map will be much darker. This shows how set kernels are tuned to find set orientations.
Draw a simple shape. Apply the Sharpen kernel. The output will look like a crisper, more set version of your drawing. This kernel emphasizes gaps between a pixel and its neighbors.
Reset to the Identity kernel. Now, set the Bias to 50. The whole feature map turns brighter. A positive bias raises the activation of each output pixel, while a negative bias drops it. It's a simple way to make the neuron more or less likely to fire.
Select the Edge Detection (Vert) kernel and check the Apply ReLU box. ReLU (Rectified Linear Unit) is an activation function that clips all negative vals to zero. Notice how all the red areas (negative vals) in the feature map disappear, leaving just the green (positive) ones. This is a key step in real neural networks to add non-linearity.
Click the Animate Matrix button. This is the most key part! Watch how the 3x3 kernel slides over the input. And how the highlighted 3x3 grid of input pixels is multiplied by the kernel to give the single highlighted pixel in the output. This is the convolution step in action.
A feature map is not a picture and not a vector -- it is a grid that keeps the answer to one question at each position. This builds a few from the same pic and shows what each cell means, how the meaning changes with depth. And why the channel axis and the spatial axes are read fully differently.
The three axes of a feature map are not interchangeable. Here is why, and how a second layer builds on the first.
A feature map is a grid of answers, not an pic. How the spatial axes are handled sets the design.
By stacking layers of these feature detectors, CNNs can learn to recognize increasingly complex patterns, from simple edges to eyes, faces. And whole objects.
Feature maps are the most direct interpretability tool on hand for a CNN. And inspecting them costs a few lines of code.
import torch
activations = {}
def hook(name):
def fn(module, inp, out):
activations[name] = out.detach()
return fn
model.layer1.register_forward_hook(hook("layer1"))
model(image_batch)
maps = activations["layer1"][0] # (channels, height, width)
maps.shape, maps.mean(), (maps == 0).float().mean() # sparsity after ReLUThree things worth checking on a net that is not working:
Dead channels. A feature map that is fully zero for each input is a filter that has stopped learning — often a dying ReLU. If a large fraction of channels are dead, less the learning rate or switch to Leaky ReLU.
Saturated maps. Vals in the thousands suggest missing normalisation somewhere.
Redundant channels. A few filters giving near-identical maps means the layer is wider than it needs to be.
For a more-level view, Grad-CAM weights the final convolutional feature maps by how much each added to a particular class score, giving a heatmap over the first pic. It is the standard way to check that a classifier is looking at the object rather than at the background — and it often reveals nets that were keying on a watermark, a hospital label. Or the grass in each photograph of a particular animal.
Feature map dimensions follow one formula, and knowing it stops most shape errors:
out = floor( (in + 2×padding − kernel) / stride ) + 1
A 32×32 input, 3×3 kernel, padding 1, stride 1: (32 + 2 − 3)/1 + 1 = 32. Size preserved, which is why "same" padding of 1 goes with a 3×3 kernel.
Same input, stride 2: (32 + 2 − 3)/2 + 1 = 16. Halved.
The channel count is simply the count of filters. And each filter spans all input channels — a 3×3 filter over a 64-channel input has 3×3×64 = 576 weights, not 9.
Is a feature map the same as a channel? Effectively yes — one filter gives one output channel. It is one feature map.
Why do deep feature maps get less? Pooling and strided convolutions reduce spatial size. It cuts computation and widens the receptive field.
Can I visualise what a filter detects? Yes — either by showing the filter weights (readable just in the first layer) or by optimising an input pic to maximise a channel's activation. It gives the familiar psychedelic feature-visualisation pics.
How many channels should a layer have? Convention is to double as spatial size halves, keeping the computation per layer roughly constant.
What is a 1×1 convolution for? It mixes channels at each position without touching spatial structure — used to reduce or expand depth cheaply, as in the bottleneck blocks of ResNet.
Do feature maps mean anything individually? Early ones do. Deep ones often respond to combinations rather than to any single nameable concept.
Answer without scrolling back up.
A feature map is:
The filter is what you slide; the feature map is what comes out - a record of where in the image that filter found what it responds to.
Applying a 3x3 filter to a 32x32 image with no padding gives:
The filter cannot centre on the outermost ring of pixels, so you lose one from each side: 32 - 3 + 1 = 30. Padding exists to hold the size steady.
Why do later layers have many more feature maps than early ones?
There are only so many ways to be an edge. There are a great many ways to be a combination of edges, so the count of distinct useful detectors grows with depth as the spatial size shrinks.
Drag a convolution filter across an image and watch it build a feature map one value at a time, the core operation inside a CNN.