Feature Maps
A feature map is the output created when a filter or kernel scans an image and detects a particular pattern. It tells the neural network where that pattern appears and how strongly it appears.
What Is a Feature Map?
During convolution, a filter moves across an image and performs calculations at different positions.
Each calculation produces one number. All those numbers together form a feature map.
Input Image
↓
Filter
↓
Convolution
↓
Feature Map
So you can remember:
Feature Map =
The result of applying a filter to an image.
Simple Example
Let's use the same small image from the previous lesson.
Image
1 2 3
4 5 6
7 8 9
Suppose our kernel is:
Kernel
1 0
0 1
The kernel scans the image and produces these values:
6 8
10 12
This output is the feature map.
Feature Map
6 8
10 12
Why Is It Called a Feature Map?
The filter is designed to respond to a particular feature, such as an edge or texture.
The resulting map tells us where that feature appears in the image.
Filter
"Find vertical edges"
↓
Image
↓
Feature Map
↓
"These locations contain vertical edges"
The word feature means something useful in the image, while map means the locations where that feature was detected.
Strong and Weak Responses
A feature map contains numbers. These numbers represent how strongly the filter responds at different locations.
For example:
Feature Map
0.1 0.2 0.1
0.3 5.8 0.4
0.2 0.1 0.2
The value 5.8 is much larger than the surrounding values.
This means the filter produced a strong response at that location.
Small value
↓
Weak response
Large value
↓
Strong response
Example 1 — Edge Feature Map
Suppose a filter has learned to detect vertical edges.
Vertical Edge Filter
-1 0 1
-1 0 1
-1 0 1
When this filter scans an image, locations containing strong vertical edges can produce strong responses.
Input Image
↓
Vertical Edge Filter
↓
Convolution
↓
Feature Map
0 0.2 0
4.8 5.2 4.7
0 0.1 0
The high values indicate locations where the learned feature was detected strongly.
Example 2 — Face Recognition
Imagine a CNN processing a face image.
An early filter might detect edges.
Image
↓
Edge Filter
↓
Edge Feature Map
Another filter might respond to curves.
Image
↓
Curve Filter
↓
Curve Feature Map
Another filter might learn a more complex pattern.
Image
↓
Complex Feature Filter
↓
Complex Feature Map
Multiple feature maps allow the network to represent different aspects of the same image.
Multiple Filters Create Multiple Feature Maps
A convolutional layer usually contains many filters.
Input Image
│
├── Filter 1
│ ↓
│ Feature Map 1
│
├── Filter 2
│ ↓
│ Feature Map 2
│
├── Filter 3
│ ↓
│ Feature Map 3
│
└── Filter 4
↓
Feature Map 4
Each feature map represents the response of one filter.
Filter 1 → Detects pattern A
Filter 2 → Detects pattern B
Filter 3 → Detects pattern C
Filter 4 → Detects pattern D
Filter vs Feature Map
Do not confuse the filter with the feature map.
FILTER
"What pattern am I looking for?"
↓
CONVOLUTION
"Scan the image"
↓
FEATURE MAP
"Where did I find that pattern?"
The filter is the detector. The feature map is the result of using that detector on the image.
Feature Map Size
The size of a feature map depends on the input size, kernel size, padding, and stride.
For example, if we have:
Input image = 5 × 5
Kernel = 3 × 3
Stride = 1
Padding = 0
The output size is:
Output size =
((Input - Kernel + 2 × Padding) / Stride) + 1
= ((5 - 3 + 0) / 1) + 1
= 3
Feature Map = 3 × 3
So a 5 × 5 image with a 3 × 3 kernel, stride 1, and no padding produces a 3 × 3 feature map.
Feature Maps With Python
We can create a simple feature map using NumPy.
import numpy as np
image = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
kernel = np.array([
[1, 0],
[0, 1]
])
feature_map = np.zeros((2, 2))
for i in range(2):
for j in range(2):
region = image[i:i + 2, j:j + 2]
feature_map[i, j] = np.sum(
region * kernel
)
print("Feature Map:")
print(feature_map)
Output:
Feature Map:
[[ 6. 8.]
[10. 12.]]
Understand the Python Code
First, we create the image.
image = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
Next, we create the kernel.
kernel = np.array([
[1, 0],
[0, 1]
])
We create an empty matrix to store the feature map.
feature_map = np.zeros((2, 2))
The loops move the kernel across the image.
for i in range(2):
for j in range(2):
This extracts the current part of the image.
region = image[i:i + 2, j:j + 2]
The region is multiplied by the kernel and the values are added together.
feature_map[i, j] = np.sum(
region * kernel
)
Finally, the calculated value is stored in the feature map.
Image region
+
Kernel
↓
One number
↓
Feature Map
Feature Maps With Keras
In a real CNN, Keras handles the convolution calculations for us.
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(
filters=4,
kernel_size=(3, 3),
activation='relu',
input_shape=(28, 28, 1)
)
])
Here:
filters=4
→ The layer has 4 filters
kernel_size=(3, 3)
→ Each filter uses a 3 × 3 kernel
input_shape=(28, 28, 1)
→ 28 × 28 grayscale image
Because there are four filters, the layer produces four feature maps.
Input Image
↓
┌───────────────┐
│ Filter 1 │ → Feature Map 1
│ Filter 2 │ → Feature Map 2
│ Filter 3 │ → Feature Map 3
│ Filter 4 │ → Feature Map 4
└───────────────┘
Feature Maps Become More Complex
CNNs normally contain multiple convolutional layers.
Early layers generally learn simple visual patterns. Later layers can combine those patterns into more complex structures.
Input Image
↓
First CNN Layer
↓
Edges
↓
Feature Maps
↓
Second CNN Layer
↓
Shapes and textures
↓
Feature Maps
↓
Deeper CNN Layer
↓
Object parts
↓
Feature Maps
↓
Prediction
The feature maps therefore become an internal representation of what the CNN has detected in the image.
The Big Picture
CNN
Input Image
↓
Filters
↓
Convolution
↓
Feature Maps
↓
Activation
↓
Pooling / Next Layer
↓
More Feature Maps
↓
Higher-Level Features
↓
Prediction
The important relationship is:
Filter
"What should I look for?"
↓
Convolution
"Scan the image"
↓
Feature Map
"Where did I find it?"
Easy Way to Remember
FILTER
↓
Pattern detector
CONVOLUTION
↓
Apply the detector across the image
FEATURE MAP
↓
Result of the detection
Think of a feature map like a map showing the locations where a particular visual pattern was found.
Filter:
"Find edges"
Feature Map:
"Edges are strong in these locations."
Check Your Understanding
What is a feature map?
It is the output produced when a filter is applied to
an image through convolution.
What does a feature map show?
It shows where the feature detected by the filter
appears and how strongly it appears.
Can one image produce multiple feature
maps?
Yes. A convolutional layer can use multiple filters,
with each filter producing its own feature map.
What does a large value in a feature map
mean?
It generally means the filter produced a strong
response at that location.
What happens to feature maps in deeper
layers?
Later layers can combine simpler features into more
complex visual representations.
What is the easiest way to remember
feature maps?
A feature map is a map showing where a particular
learned feature was detected in an image.