How it works...

In the previous recipe, Introduction to convolution operation, we built a simple CNN model. Apart from filter size and the number of filters, there are two more parameters of a convolution layer that can be configured for better feature extraction, and these are strides and padding. In step 1, we passed a vector of two integers (width and height), specifying the strides of the convolution along the width and height. The padding argument takes two values, valid, and same, with valid meaning no padding, and same means that the input and output sizes remain the same. Next, we printed a summary of the model.

The output shape and number of trainable parameters of a convolutional layer can be given by the following formula:

  • Output shape: If the input to our convolutional layer is  and we apply  filters of  and  strides and  padding, then the output shape is given by the following formula:

  • The number of parameters in each layer is calculated as follows:

In step 2, we defined the loss function of our model, then compiled and trained it. We then tested the model's performance on the testing dataset and printed the model's loss and accuracy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset