# Neural Nets: CNN confirming layer/filter arithmetic

I was hoping someone could just confirm some intuition about how convolutions work in convolutional neural networks. I have seen all of the tutorials on applying convolutional filters on an image, but most of those tutorials focus on one channel images, like a 128 x 128 x 1 image. I wanted to clarify what happens when we apply a convolutional filter to RGB 3 channel images.

Now this is not a unique question, I think a lot of people ask this question as well. It is just that there seem to be so many answers out there, each with their own variations, that it is hard to find a consistent answer. I included a post below that seems to comport with what my own intuition, but I was hoping one of the experts on SE could help validate the layer arithmetic, to make sure my intuition was not off.

Convolutional neural nets and reduction of the layers

Consider an Alexnet network with 5 convolutional layers and 3 fully connected layers. I borrowed the network from this post. Now, say the input is 227 x 227, and the filter is specified as 11 x 11 x 96 with stride 4. That means there are 96 filters each with dimensions 11x11x3, right? So there are a total of 363 parameters per filter--excluding the bias term-- and there are 96 of these filters to learn. So the 363*96 = 34848 filter values are learned just like the weights in the fully connected layers right?

My second question deals with the next convolutional network layer. In the next layer I will have an image that is 55 x 55 x 96 image. In this case, would the filter be 5x5x96--since there are now 96 feature maps on the image? So that means that each individual filter would need to learn 5x5x96 = 2400 filter values (weights), and that across all 256 filters this would mean 614,400 filter values?

I just wanted to make sure that I was understanding exactly what is being learned at each level.

• Oh thanks so much. Yeah I just wanted to make sure I was understanding the structure correctly. The equations are good, but they hide the implementation details. And the deep learning frameworks like keras will wrap the operation in these high level functions, so you can't see what is going on underneath. Don't get me wrong, I love keras. I just did not want to treat the networks like "black boxes" where I just plug stuff in and get a result without understanding how to get the answer. I took Andrew Ng's course on Coursera and it was really nice. – krishnab Jun 3 '19 at 8:58
• Clement - thanks for the info, yeah I took the course a while ago so don't remember the details of the assignment. If I remember correctly, didn't he do the assignment in Numpy for the forward pass? I think it was a really good course. I wish that the Deep Learning specialization had had a deeper set of "lab" courses in tensorflow. I believe Coursera has a new set of deep learning classes where they are trying to provide more tf practice. – krishnab Jun 3 '19 at 17:21