Modules / Deep Learning / Convolutional Layer

Feature Map in CNN

Slide a kernel across an image to perform multiplications and generate a feature map.

Filter Kernel (3x3)

Overview

Slide a kernel across an image to perform multiplications and generate a feature map.

In this guide
  1. Quick Context
  2. The Core Idea: Learning to See Features
  3. What a filter leaves behind
  4. Reading the counts
  5. Feature maps change character with depth
  6. Guided Experiments with This Interactive
  7. Common Misconceptions
  8. Reading a feature map like a map
  9. Worth remembering
  10. With feature maps to see what the net is doing
  11. The arithmetic of output size
  12. Questions people ask
  13. Recap in one screen

Understanding Convolutional Feature Maps

The core building block of how Convolutional Neural Networks (CNNs) see the world.

Quick Context

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.

The Core Idea: Learning to See Features

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.

What a filter leaves behind

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.

Reading the counts

Value in the mapMeaning
Large positiveStrong match for the filter's pattern
Near zeroPattern absent
Negative (before ReLU)The opposite pattern — e.g. a reversed edge
Zero after ReLUEverything 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.

Feature maps change character with depth

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.

Guided Experiments with This Interactive

  1. The "Identity" Kernel:

    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.

  2. Edge Detection Kernels:

    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.

  3. The "Sharpen" Kernel:

    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.

  4. The Role of Bias:

    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.

  5. Applying ReLU:

    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.

  6. Animate the Matrix:

    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.

Common Misconceptions

  • "It's just matrix multiplication." Not quite. It's a series of less, item-wise multiplications and sums, not one large matrix multiplication.
  • "The output is always less." Not necessarily. Techniques like "padding" (adding a border of zeros to the input) can be used to keep the output the same size, as is done in this interactive.

Reading a feature map like a map

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.

example_01.pyNumPy
Output

The three axes of a feature map are not interchangeable. Here is why, and how a second layer builds on the first.

example_02.pyNumPy
Output

A feature map is a grid of answers, not an pic. How the spatial axes are handled sets the design.

example_03.pyNumPy
Output

Worth remembering

  • A kernel is a small filter that detects a set feature.
  • A feature map is the output of the convolution, showing where the feature was detected.
  • A single convolutional layer in a CNN has many other kernels, each giving its own feature map.
  • The combination of convolution, bias. And an activation function (like ReLU) forms the basic building block of a CNN layer.

By stacking layers of these feature detectors, CNNs can learn to recognize increasingly complex patterns, from simple edges to eyes, faces. And whole objects.

With feature maps to see what the net is doing

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 ReLU

Three 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.

The arithmetic of output size

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.

Questions people ask

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.

Recap in one screen

  • A feature map records where and how strongly one filter matched, across the whole input.
  • One filter gives one map. A layer's output is a stack of them, one channel each.
  • Spatial size shrinks with depth while channel count grows — fewer positions, more patterns.
  • Early maps are edges and textures. Deep maps are abstract and no longer look like the pic.
  • Inspecting maps finds dead filters. And Grad-CAM shows whether the net is looking at the right thing.

Check yourself

0 of 3

Answer without scrolling back up.

  1. A feature map is:

  2. Applying a 3x3 filter to a 32x32 image with no padding gives:

  3. Why do later layers have many more feature maps than early ones?

Cheat sheet

Convolutional Layer

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.

COMPUTER VISION · vizlearn.in/computer_vision/feature_map_in_cnn.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.