Answers.Body: <p>Your first point is correct. The filters are stored in 4d arrays, with dimensions of (height, width, input channels, filter number) . The order may differ.
  Your second point is correct too. The filtered result get stacked together so the output dimensions are (Height,width,filter numbers) the next layer's filters are of size( filter width, filter width, last layer's filter number). Your understanding of CNN is correct. If you want additional resources on CNN, you can try Andrew Ng's class on CNN in Coursera. Hope you can learn more about CNN.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-03T08:58:37.910Z
Answers.Text: 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.
Answers.UserDisplayName: krishnab
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-03T08:59:13.460Z
Answers.Text: I wish Andrew Ng's original class had more tensorflow code to see how the details were implemented. I think he has some new courses out, but have not seen those.
Answers.UserDisplayName: krishnab
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-03T10:44:59.213Z
Answers.Text: Andrew Ng's course has an assignment that needs you to implement the forward pass of a CNN layer from scratch in numpy. Btw, it is the Convolutional Neural Network course in the Deep Learning Specialization.
Answers.UserDisplayName: Clement
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-03T17:21:27.837Z
Answers.Text: 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.
Answers.UserDisplayName: krishnab
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-03T07:47:53.283Z
Answers.LastActivityDate: 2019-06-03T07:47:53.283Z
Answers.UserDisplayName: Clement
Body: <p>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.</p>
  <p>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.</p>
  <p><a href="https://ai.stackexchange.com/q/6934/2444">How is the depth of the input related to the depth of the output of a convolutional layer?</a></p>
  <p>Consider an Alexnet network with 5 convolutional layers and 3 fully connected
  layers. I borrowed the network from this <a href="https://medium.com/@smallfishbigsea/a-walk-through-of-alexnet-6cbd137a5637" rel="nofollow noreferrer">post</a>.  <strong>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?</strong>
  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?</p>
  <p>My second question deals with the next convolutional network layer. <strong>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?</strong> 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?</p>
  <p>I just wanted to make sure that I was understanding exactly what is being learned
  at each level.</p>
  
Tags: <deep-learning><convolutional-neural-networks><weights><convolution-arithmetic>
Title: Neural Nets: CNN confirming layer/filter arithmetic
UserDisplayName: krishnab
ThreadText: # Neural Nets: CNN confirming layer/filter arithmetic
  
  (Asked by: username_0 on 2019-06-03)
  
  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.
  
  [How is the depth of the input related to the depth of the output of a convolutional layer?](https://ai.stackexchange.com/q/6934/2444)
  
  Consider an Alexnet network with 5 convolutional layers and 3 fully connected
  layers. I borrowed the network from this [post](https://medium.com/@smallfishbigsea/a-walk-through-of-alexnet-6cbd137a5637). **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.
  
  **Tags:** deep-learning, convolutional-neural-networks, weights, convolution-arithmetic
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-03. Score: 3 | Accepted answer
  
  Your first point is correct. The filters are stored in 4d arrays, with dimensions of (height, width, input channels, filter number) . The order may differ.
  Your second point is correct too. The filtered result get stacked together so the output dimensions are (Height,width,filter numbers) the next layer's filters are of size( filter width, filter width, last layer's filter number). Your understanding of CNN is correct. If you want additional resources on CNN, you can try Andrew Ng's class on CNN in Coursera. Hope you can learn more about CNN.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_0**: I wish Andrew Ng's original class had more tensorflow code to see how the details were implemented. I think he has some new courses out, but have not seen those.  
  > **username_1**: Andrew Ng's course has an assignment that needs you to implement the forward pass of a CNN layer from scratch in numpy. Btw, it is the Convolutional Neural Network course in the Deep Learning Specialization.  
  > **username_0**: username_1 - 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.  
  
  ---
  
  