Modules / Deep Learning / Convolutional Layer

Feature Map in CNN

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

Overview

Quick Context

The convolution operation is the heart of Convolutional Neural Networks (CNNs), the models that power most modern computer vision. This interactive visualizes that exact process. A small matrix, called a kernel or filter, slides over an input image. At each position, it performs an element-wise multiplication and sums the results to produce a single pixel in the output, known as a feature map.

Filter Kernel (3x3)

Understanding Convolutional Feature Maps

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

The Core Idea: Learning to See Features

Why do this? Because different kernels are designed to detect different 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 image 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 values during training to solve a specific 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 image — 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 image; it is a map of one specific kind of evidence.

A convolution layer with 64 filters produces 64 such maps, stacked into a tensor of shape (height, width, 64). Each channel answers a different question about every 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 allows segmentation and detection to recover locations.

Reading the numbers

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 every response, which means a filter effectively detects its pattern in one polarity only. Networks compensate by learning pairs of opposite filters, which is why filter visualisations of early layers so often come in mirrored pairs.

The depth of the feature map stack is the number 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 image: edges, colour boundaries, 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 original 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 exactly what makes transfer learning work. The early layers of a network trained on ImageNet have learned generic visual primitives that apply to almost any image task, so they can be reused unchanged. The late layers are specific to the original 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 image. This is because 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 demonstrates how specific kernels are tuned to find specific orientations.

  3. The "Sharpen" Kernel:

    Draw a simple shape. Apply the Sharpen kernel. The output will look like a crisper, more defined version of your drawing. This kernel emphasizes differences between a pixel and its neighbors.

  4. The Role of Bias:

    Reset to the Identity kernel. Now, set the Bias to 50. The entire feature map becomes brighter. A positive bias increases the activation of every output pixel, while a negative bias decreases 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 values to zero. Notice how all the red areas (negative values) in the feature map disappear, leaving only the green (positive) ones. This is a crucial step in real neural networks to introduce non-linearity.

  6. Animate the Matrix:

    Click the Animate Matrix button. This is the most important 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 produce the single highlighted pixel in the output. This is the convolution operation in action.

Common Misconceptions

  • "It's just matrix multiplication." Not quite. It's a series of smaller, element-wise multiplications and sums, not one large matrix multiplication.
  • "The output is always smaller." 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 every position. This builds several from the same image and shows what each cell means, how the meaning changes with depth, and why the channel axis and the spatial axes are read completely differently.

example_01.pyNumPy
Output

Worth remembering

  • A kernel is a small filter that detects a specific 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 different kernels, each producing its own feature map.
  • The combination of convolution, bias, and an activation function (like ReLU) forms the fundamental 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 entire objects.

Using feature maps to see what the model is doing

Feature maps are the most direct interpretability tool available 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 model that is not working:

Dead channels. A feature map that is entirely zero for every input is a filter that has stopped learning — usually a dying ReLU. If a large fraction of channels are dead, lower the learning rate or switch to Leaky ReLU.

Saturated maps. Values in the thousands suggest missing normalisation somewhere.

Redundant channels. Several filters producing near-identical maps means the layer is wider than it needs to be.

For a higher-level view, Grad-CAM weights the final convolutional feature maps by how much each contributed to a particular class score, producing a heatmap over the original image. It is the standard way to check that a classifier is looking at the object rather than at the background — and it regularly reveals models that were keying on a watermark, a hospital label, or the grass in every photograph of a particular animal.

The arithmetic of output size

Feature map dimensions follow one formula, and knowing it prevents 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 number 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 produces one output channel, which is one feature map.

Why do deep feature maps get smaller? Pooling and strided convolutions reduce spatial size, which cuts computation and widens the receptive field.

Can I visualise what a filter detects? Yes — either by showing the filter weights (readable only in the first layer) or by optimising an input image to maximise a channel's activation, which produces the familiar psychedelic feature-visualisation images.

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 usually 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 image.
  • Inspecting maps finds dead filters, and Grad-CAM shows whether the model 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

The convolution operation is the heart of Convolutional Neural Networks (CNNs), the models that power most modern computer vision. This interactive visualizes that exact process. A small matrix, called a kernel or filter, slides over an input image. At each position, it performs an element-wise multiplication and sums the results to produce a single pixel in the output, known as a feature map.

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.