liveBook · Manning

Feature map

As explained in Deep Learning with R, Third Edition

A feature map is a spatial array of activations indicating the presence or strength of a learned visual pattern at different image locations.

A feature map records where visual patterns appear in an image. In a convolutional network, it is usually a three-dimensional array with height, width, and channels. Each channel is a two-dimensional response map: its values indicate the strength of one learned filter’s response at different locations. section 8.1.1

Reading shapes in a digit classifier

A 28 × 28 grayscale MNIST image has shape (28, 28, 1). A convolution layer with 64 filters produces a feature map of shape (26, 26, 64): 64 response maps, each 26 × 26. A 2 × 2 max-pooling layer then reduces the spatial dimensions to 13 × 13 while keeping the 64 channels. section 8.1.1 section 8.1.2

Listing 8.1 Instantiating a small convnet
library(keras3)

inputs <- keras_input(shape = c(28, 28, 1))
outputs <- inputs |>
  layer_conv_2d(filters = 64, kernel_size = 3, activation = "relu") |>
  layer_max_pooling_2d(pool_size = 2) |>
  layer_conv_2d(filters = 128, kernel_size = 3, activation = "relu") |>
  layer_max_pooling_2d(pool_size = 2) |>
  layer_conv_2d(filters = 256, kernel_size = 3, activation = "relu") |>
  layer_global_average_pooling_2d() |>
  layer_dense(10, activation = "softmax")

model <- keras_model(inputs = inputs, outputs = outputs)

Follow the R/Keras model from its image input through convolution, pooling, and the final classifier. section 8.1

A convolution applies the same learned transformation to local patches across its input. Early layers can detect small patterns such as edges; later layers combine earlier features into more complex patterns. Unlike RGB input channels, learned feature channels represent filters rather than fixed colors. section 8.1.1

As a network processes a feature map, its shape and role can change:

  • Max pooling takes the maximum in each channel within a window, reducing spatial size. This helps later layers combine information from larger areas of the original image. section 8.1.2
  • Global average pooling averages each channel over its spatial positions. For example, it turns a (3, 3, 256) map into a vector of length 256 for a classifier, discarding the spatial layout. section 8.1 section 8.3.1
  • For segmentation, location matters: strided convolutions downsample feature maps while retaining location information better than max pooling, which does not record where a window’s maximum came from. section 11.3.2

Feature maps can also be reused or inspected. A pretrained convolutional base can produce features for a new classifier; earlier maps tend to capture more generic patterns than later ones. To see what a layer responds to, plot each channel as a separate image. Learned filters can vary between training runs. section 8.3.1 section 10.1

Figure 10.3 Every channel of every layer activation on the test cat picture
figure

Compare channels across layers to see how the same cat image produces different intermediate responses. section 10.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains tensor shapes, convolution and pooling transformations, and per-channel activation visualization.
Examples
Traces MNIST digit shapes and visualizes intermediate activations for a cat image.
What you can do after
Apply it via R/Keras to inspect model shapes and visualize intermediate activation channels.
How it connects
Connects convolution, max pooling, global average pooling, transfer learning, and image segmentation.

Also explained in

Compare how 8 books explain feature map →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.