A convolutional layer applies learned filters, also called kernels, across an image. Each filter slides over local patches—typically one pixel at a time—and produces output values that form a feature map. The filter weights are learned, so different filters can extract different image features. section 7.1
In Keras, `Conv2D` specifies the number of filters, kernel dimensions, activation, padding, and, for the first layer, input shape. A simple Fashion-MNIST feature extractor starts with 64 filters on a 28×28×1 image, then uses 32 and 16 filters in later convolutional layers. section 7.1
Listing 7.2 EDL_7_1_Keras_CNN.ipynb: Building CNN layers
model = models.Sequential() model.add(layers.Conv2D(64, (3, 3), activation='relu', padding="same", input_shape=(28, 28, 1))) #1 model.add(layers.MaxPooling2D((2, 2), padding="same")) #2 model.add(layers.Conv2D(32, (3, 3), activation='relu', [padding="same")) #3 model.add(layers.MaxPooling2D((2, 2))) #4 model.add(layers.Conv2D(16, (3, 3), activation='relu')) #5 model.add(layers.MaxPooling2D((2, 2))) #6 model.summary()
This sequential model alternates `Conv2D` and `MaxPooling2D`: convolutions expand or transform channels, while pooling reduces spatial dimensions between feature-extraction stages. section 7.1
Convolutional layers are combined with neighboring layer types for different jobs:
- Use max pooling after convolution to summarize feature maps and reduce their spatial size. section 7.1
- Use convolution plus pooling in an autoencoder encoder to form a latent image representation. section 8.1.2
- Use convolution plus upsampling in an autoencoder decoder to rebuild an image, ending with a layer that produces the required channel count. section 8.1.2
- Encode filter count and kernel size as gene values when evolving CNN or autoencoder architectures. section 8.2.1
A convolutional autoencoder path
For a grayscale 28×28 input, an encoder can apply 64, 32, and 16-filter convolutional layers with 3×3 kernels, pooling after each layer. A decoder then convolves and upsamples through corresponding stages before a final one-filter convolution restores a single-channel output. section 8.1.2
Layer design remains an experimental task. Change kernel sizes, pooling sizes, or the number of convolutional layers and rerun the model to inspect the effect. Because choosing an effective CNN architecture can be difficult, filter counts and kernel sizes can also become variables in an evolutionary search. section 7.1.2 section 7.2













