Aan de slagGa gratis aan de slag

Add padding to a CNN

Padding allows a convolutional layer to retain the resolution of the input into this layer. This is done by adding zeros around the edges of the input image, so that the convolution kernel can overlap with the pixels on the edge of the image.

Deze oefening maakt deel uit van de cursus

Image Modeling with Keras

Cursus bekijken

Oefeninstructies

Add a Conv2D layer and choose a padding such that the output has the same size as the input.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Initialize the model
model = Sequential()

# Add the convolutional layer
model.add(____(10, kernel_size=3, activation='relu', 
                 input_shape=(img_rows, img_cols, 1), 
                 ____))

# Feed into output layer
model.add(Flatten())
model.add(Dense(3, activation='softmax'))
Code bewerken en uitvoeren