liveBook · Manning

Convolutional layer

As explained in Distributed Machine Learning Patterns

A convolutional layer is a neural-network layer that applies learned convolutional filters to its input.

A convolutional layer applies learned filters to image-like inputs and produces feature mappings that later layers can use for classification. In a CNN, several convolutional layers are commonly interleaved with pooling before flattening and dense classification. section 3.2.2 section 9.2.1

A practical convolutional-layer workflow typically follows this structure:

  • Provide an image-shaped input, such as a 28 × 28 frame. section 9.2.1
  • Stack convolutional layers to learn increasingly useful feature mappings. section 3.2.2
  • Use max-pooling layers to reduce intermediate representations before flattening and dense classification. section 9.2.1
  • Compile and train the complete model with an optimizer, loss function, metrics, and callbacks for monitoring or checkpointing. section 9.2.1

Three-layer TensorFlow CNN

A Sequential model can apply Conv2D three times: 32 filters with a 3 × 3 kernel, then 64 filters twice. Max-pooling follows the first two convolutional layers; Flatten and Dense layers produce the final classification.

Listing 9.4 Defining the basic CNN model
def build_and_compile_cnn_model():
 print("Training CNN model")
 model = models.Sequential()
 model.add(layers.Input(shape=(28, 28, 1), name='image_bytes'))
 model.add(
         layers.Conv2D(32, (3, 3), activation='relu'))
 model.add(layers.MaxPooling2D((2, 2)))
 model.add(layers.Conv2D(64, (3, 3), activation='relu'))
 model.add(layers.MaxPooling2D((2, 2)))
 model.add(layers.Conv2D(64, (3, 3), activation='relu'))
 model.add(layers.Flatten())
 model.add(layers.Dense(64, activation='relu'))
 model.add(layers.Dense(10, activation='softmax'))
 model.summary()
 model.compile(optimizer='adam',
          loss='sparse_categorical_crossentropy',
          metrics=['accuracy'])
 return model

Browse the complete TensorFlow definition to inspect the convolutional-layer sequence, tensor shapes, pooling stages, and compilation settings. section 9.2.1

How Distributed Machine Learning Patterns covers it

How deep it goes
Defines layer placement and TensorFlow configuration, but stops short of convolution arithmetic or filter-internals.
Examples
Uses a three-layer 28 × 28 image CNN and a LeNet architecture for classifying images or video frames.
What it assumes
Assumes an existing input pipeline and familiarity with CNN architecture while defining the basic model and layer sequence concretely.
What you can do after
Build it from scratch with TensorFlow Sequential and Conv2D, then inspect, compile, train, and monitor the resulting CNN.
How it connects
Connects convolutional layers to convolutional neural networks, feature maps, max pooling, dense layers, and backpropagation.

Also explained in

Compare how 14 books explain convolutional layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Distributed Machine Learning Patterns. The section links point to the parts of the book it draws on.