Keras pooling layers
Keras implements a pooling operation as a layer that can be added to CNNs between other layers. In this exercise, you will construct a convolutional neural network similar to the one you have constructed before:
Convolution => Convolution => Flatten => Dense
However, you will also add a pooling layer. The architecture will add a single max-pooling layer between the convolutional layer and the dense layer with a pooling of 2x2:
Convolution => Max pooling => Convolution => Flatten => Dense
A Sequential model
along with Dense
, Conv2D
, Flatten
, and MaxPool2D
objects are available in your workspace.
This exercise is part of the course
Image Modeling with Keras
Exercise instructions
- Add an input convolutional layer (15 units, kernel size of 2,
relu
activation). - Add a maximum pooling operation (pooling over windows of size 2x2).
- Add another convolution layer (5 units, kernel size of 2,
relu
activation). - Flatten the output of the second convolution and add a
Dense
layer for output (3 categories,softmax
activation).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a convolutional layer
____(____(15, kernel_size=2, activation='relu',
input_shape=(img_rows, img_cols, 1)))
# Add a pooling operation
____
# Add another convolutional layer
____
# Flatten and feed to output layer
model.add(____)
model.add(____(3, activation='softmax'))
model.summary()