1
$\begingroup$

I am currently trying to write a CNN from scratch, but I don't understand how to feed the information from a max-pooling layer to the next convolutional layer. Specifically, I don't know what to do with the 6 filtered and pooled images from the first convolutional and max-pooling layers. How do I feed those images into the next convolutional layer?

$\endgroup$
0
1
$\begingroup$

The application of 1 kernel (aka filter) to an input (with a 2d convolution) is a matrix (a 2d array), which is often known as a feature map (aka activation map). The application of $k$ kernels to the same input is a 3d array (sometimes called tensor, though this may not be exactly correct, or 3d volume) with depth $k$, i.e. you have $k$ concatenated feature maps. This 3d array is the input to the next convolutional layer, which needs to have 3d kernels of depth $k$: this is the main requirement in the case of 2d convolutions (in the case of 3d convolutions, the kernels can have a different depth than the input 3d volume, but you can ignore this for now!).

Another thing that you need to take care of is the padding that you can add around this 3d volume. This, along with the stride (i.e. the step with which you move the kernel), determines the height and width of the output of the convolutional layer.

So, to recapitulate, what you have to do is set the depth of the kernels in the convolutional layer $l+1$ to be equal to the number of kernels that you use in the convolutional layer $l$. So, let's say that the number of kernels is a hyper-parameter (note that this is usually the case!), and that the user sets the number of kernels $k=8$ in the convolutional layer $l$, and, for simplicity, assume that all kernels are $3 \times 3$, then, in layer $l$, you will perform $8$ convolutions, one for each kernel. These $8$ convolutions produce a 3d array of dimensions $w \times h \times 8$ (where $w$ and $h$ depend on the dimensions of the input to layer $l$, the stride, and padding). Consequently, in the convolutional layer $l+1$, the kernels need to be $3 \times 3 \times 8$.

If it's the pooling layer that produces the 3d array to be passed to the next convolutional layer, you should still set the depth of the kernels in the convolutional layer $l+1$ to the number of kernels in the convolutional layer $l$ (provided that, in the pooling layer, you only redimension the width and height of the 3d array, which is usually the case).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.