Convolutional layers in Keras

To create a convolutional layer in Keras, you must first import the required modules as follows:

from keras.layers import Conv2D

Then, you can create a convolutional layer by using the following format:

Conv2D(filters, kernel_size, strides, padding, activation='relu', input_shape)

You must pass the following arguments:

  • filters: The number of filters.
  • kernel_size: A number specifying both the height and width of the (square) convolution window. There are also some additional optional arguments that you might like to tune.
  • strides: The stride of the convolution. If you don't specify anything, this is set to one.
  • padding: This is either valid or same. If you don't specify anything, the padding is set to valid

Get Practical Convolutional Neural Networks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.