Implementing a CNN
So far, we have implemented convolution and pooling layers. Now, we will combine these layers to create a CNN that recognizes handwritten digits and implement it, as shown in Figure 7.23.
As shown in Figure 7.23, the network consists of "Convolution – ReLU – Pooling – Affine – ReLU – Affine – Softmax" layers. We will implement this as a class named SimpleConvNet
:
Figure 7.23: Network configuration of a simple CNN
Now, let's look at the initialization of SimpleConvNet (__init__)
. It takes the following arguments:
input_dim
: Dimensions of the input data (channel, height, width).conv_param
: Hyperparameters of the convolution layer (dictionary). The following are the dictionary keys:filter_num
: Number of filtersfilter_size
: Size of the filterstride
: Stridepad
: Paddinghidden_size
: Number of neurons in the hidden layer (fully connected)output_size...