Answers.Body: <p>Ok, here's the break down:</p>
  
  <p>The depth of an input to a convolutional layer is termed channels. The depth of a convolutional layer is the number of kernels (aka filters). The depth of a <em>kernel</em> is equal to the number of channels in the input.</p>
  
  <p>See below:</p>
  
  <p><a href="https://i.sstatic.net/z9kb7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/z9kb7.png" alt="Convolution"></a></p>
  
  <p>The input (of 7x7, pad of 1) has 3 channels. The convolutional layer has 2 kernels (or filters). Each filter has a depth of 3, equal to the number of channels in the input. Using the notation you used in your question:</p>
  
  <ul>
  <li>Filter 1, channel 1 to input channel 1</li>
  <li>Filter 1, channel 2 to input channel 2</li>
  <li>Filter 1, channel 3 to input channel 3</li>
  <li><p>Sum all three channels of filter 1, then add bias</p></li>
  <li><p>Filter 2, channel 1 to input channel 1</p></li>
  <li>Filter 2, channel 2 to input channel 2</li>
  <li>Filter 2, channel 3 to input channel 3</li>
  <li>Sum all three channels of filter 2, then add bias</li>
  </ul>
  
  <p>These steps are repeated for each frame the filter slides over the input image.</p>
  
  <p>To answer question 2, if the output is 128, that simply means there are 128 filters. There could be an infinite number of filters if you so choose.</p>
  
  <p>EDIT:</p>
  
  <p>Here's the link to the interactive graphic: <a href="http://cs231n.github.io/convolutional-networks/" rel="nofollow noreferrer">http://cs231n.github.io/convolutional-networks/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-30T19:32:51.330Z
Answers.Text: Apologies for the late reply. Thank you v much for the answer. Makes sense. With regards to question 2, I may have not phrased the question clearly. My question was how do you apply 128 filters to 64 outputs from Maxpool layer, and still end up with an output of 128 feature maps. My thought was, each filter is applied to each Maxpool output. In this case you end up with 64 x 128 filters =  8192 feature maps instead of 128. However, when I read the article your shared: http://cs231n.github.io/convolutional-networks/, in the entire article there's one key sentence which I think helps explain ..
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-30T19:33:22.900Z
Answers.Text: “As we will soon see, the neurons in a layer will only be connected to a small region of the layer before it, instead of all of the neurons in a fully-connected manner”. So my thinking/understanding of this (which I could be wrong), is that only a select outputs will have a select filters applied to them in such a way where you end up with the same number of output feature maps as the filters. In the case of the 64 “Maxpooled” outputs, perhaps every 1 Maxpool output is connected to 2 filters ...
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-30T19:33:29.567Z
Answers.Text: which makes sense because then you would get the output of 128 feature maps. Does that make sense and is it correct?
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T01:27:15.243Z
Answers.Text: Not quite, but you're on the right idea. I think what's confusing is the term "filter", which I would argue is horrifically incorrect, as a "filter", is actually rather a collection of filters (called channels). So in this case, the 128 filters are each a collection of 64 filters (channels), which correspond to a depth level of the output of the maxpool layer.
Answers.UserDisplayName: Recessive
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T01:27:18.370Z
Answers.Text: Say we're filter collection 1, then we perform the intuitive sliding and multiplying of each of the 64 filters (channels) in the collection, then for each output node of the collection, take the total sum of all 64 filters (channels) at that location, and then once put through an activation function, that is your final output for that layer.
Answers.UserDisplayName: Recessive
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T17:59:06.930Z
Answers.Text: Excellent explanation. That makes perfect sense now. So the key missing part of information that cleared it up for me is: "then for each output node of the collection, take the total sum of all 64 filters (channels) at that location". Man seriously, it's these small details that I found hard to clarify from literature and articles, or it's explained at the input image convolution layer stage, but I failed to apply the same concept from a Maxpool to another Convolution layer stage. Thank you very much.
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T18:01:21.867Z
Answers.Text: I assumed the 64 channels of a filter collection start as aribitrary values that are optimised over time with the backpropagation optimisation gradient descent stage, much like the other parameters that get optimised in the network during the learning process.
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T18:03:06.517Z
Answers.Text: Also one final question, how did you embed the screenshots in your thread so they appear in the post. Mine didn't show on the post, and you have to click on the image link to show it. :(
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-01T03:27:10.597Z
Answers.Text: I just copied the image across rather then a link. Also just as a note, the initial values of the filters are always randomly selected, but over a specific range. You'll notice very quickly if you don't select the correct initial values the network will fail to learn almost every time, as you will get both exploding and vanishing numbers in the forward *and* backward pass. I asked a question in relation to this and got a fantastic answer, see here: https://ai.stackexchange.com/questions/13106/how-are-exploding-numbers-in-a-forward-pass-of-a-cnn-combated
Answers.UserDisplayName: Recessive
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-04T20:01:22.683Z
Answers.Text: Sorry for asking another question, just one more question. You mentioned: "... take the total sum of all 64 filters (channels) at that location ...". Do we actually add all 64 matrices together, or do we get their combined 'dot' products? Also the final output should be only 1 matrix (feature map), correct? That way with every filter (and its 64 channels) produce only 1 output matrix(feature map), then we would have the expected 128 matrices (or 128 feature maps) output.
Answers.UserDisplayName: Hazzaldo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T06:44:35.833Z
Answers.Text: If you consider the output to be a 3d matrix, then yes, otherwise no, the output should be 128 2d matrices. Yes, you add the matrices together.
Answers.UserDisplayName: Recessive
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-26T02:50:45.170Z
Answers.LastActivityDate: 2019-07-26T02:50:45.170Z
Answers.UserDisplayName: Recessive
Body: <p>I was watching a video about Convolutional Neural Networks: <a href="https://www.youtube.com/watch?v=SQ67NBCLV98" rel="nofollow noreferrer">https://www.youtube.com/watch?v=SQ67NBCLV98</a>. What I'm confused about is the arrangement of applying the filters' channels to the input image or even to the output of a previous layer.</p>
  <p><b>Question 1</b> - Looking at the visual explanation example of how one filter with 3 channels is applied to the input image (with 3 channels), so that each 1 filter channel is applied to its corresponding input channel: <a href="https://i.sstatic.net/FH72T.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FH72T.jpg" alt="Conv 2_D" /></a>.
  So hence the output is 3 channels. Makes sense.</p>
  <p>However, looking at the second screenshot which shows an example of the VGG network: <a href="https://i.sstatic.net/hblZO.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hblZO.jpg" alt="VGG" /></a>, looking at the first layer (I've delineated with a red frame), which is 64 channels, where the input of the image contains 3 channels. How does the output shape become 64? The only way I would think this would be possible is if you apply:</p>
  <ul>
  <li>filter channel 1 to image channel 1</li>
  <li>filter channel 2 to image channel 2</li>
  <li>filter channel 3 to image channel 3</li>
  <li>filter channel 4 to image channel 1</li>
  <li>filter channel 5 to image channel 2</li>
  <li>filter channel 6 to image channel 3</li>
  </ul>
  <p>.. and so on.</p>
  <p>Or the other thing could be, that these are representing Conv layers, with 64 filters. Rather than a filter with 64 channels. And that's precisely what I'm confused about here. In all the popular Convolutional networks, when we see these big numbers - 64, 128, 256 ... etc, are these Conv layers with 64 filters, or are they individual filters with 64 channels each?</p>
  <p><b>Question 2</b> - Referring back to the second screenshot, the layer I've delineated with blue frame (3x3x128). This Conv layer, as I understand, takes the output of 64 Max-pooled nodes and applies 128 Conv filters. But how does the output become 128. If we apply each filter to each Max-pooled output node, that's 64 x 128 = 8192 channels or nodes in output shape. Clearly that's not what's happening and so I'm definitely missing something here. So, how does 128 filters is applied to 64 output nodes in a way so that the output is still 128? What's the arrangement?</p>
  <p>Many thanks in advance.</p>
  
Tags: <deep-learning><convolutional-neural-networks>
Title: Understanding arrangement of applying filters to input channels
UserDisplayName: Hazzaldo
ThreadText: # Understanding arrangement of applying filters to input channels
  
  (Asked by: username_0 on 2019-07-25)
  
  I was watching a video about Convolutional Neural Networks: <https://www.youtube.com/watch?v=SQ67NBCLV98>. What I'm confused about is the arrangement of applying the filters' channels to the input image or even to the output of a previous layer.
  
  **Question 1** - Looking at the visual explanation example of how one filter with 3 channels is applied to the input image (with 3 channels), so that each 1 filter channel is applied to its corresponding input channel: [![Conv 2_D](https://i.sstatic.net/FH72T.jpg)](https://i.sstatic.net/FH72T.jpg).
  So hence the output is 3 channels. Makes sense.
  
  However, looking at the second screenshot which shows an example of the VGG network: [![VGG](https://i.sstatic.net/hblZO.jpg)](https://i.sstatic.net/hblZO.jpg), looking at the first layer (I've delineated with a red frame), which is 64 channels, where the input of the image contains 3 channels. How does the output shape become 64? The only way I would think this would be possible is if you apply:
  
  * filter channel 1 to image channel 1
  * filter channel 2 to image channel 2
  * filter channel 3 to image channel 3
  * filter channel 4 to image channel 1
  * filter channel 5 to image channel 2
  * filter channel 6 to image channel 3
  
  .. and so on.
  
  Or the other thing could be, that these are representing Conv layers, with 64 filters. Rather than a filter with 64 channels. And that's precisely what I'm confused about here. In all the popular Convolutional networks, when we see these big numbers - 64, 128, 256 ... etc, are these Conv layers with 64 filters, or are they individual filters with 64 channels each?
  
  **Question 2** - Referring back to the second screenshot, the layer I've delineated with blue frame (3x3x128). This Conv layer, as I understand, takes the output of 64 Max-pooled nodes and applies 128 Conv filters. But how does the output become 128. If we apply each filter to each Max-pooled output node, that's 64 x 128 = 8192 channels or nodes in output shape. Clearly that's not what's happening and so I'm definitely missing something here. So, how does 128 filters is applied to 64 output nodes in a way so that the output is still 128? What's the arrangement?
  
  Many thanks in advance.
  
  **Tags:** deep-learning, convolutional-neural-networks
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-26. Score: 1 | Accepted answer
  
  Ok, here's the break down:
  
  The depth of an input to a convolutional layer is termed channels. The depth of a convolutional layer is the number of kernels (aka filters). The depth of a *kernel* is equal to the number of channels in the input.
  
  See below:
  
  [![Convolution](https://i.sstatic.net/z9kb7.png)](https://i.sstatic.net/z9kb7.png)
  
  The input (of 7x7, pad of 1) has 3 channels. The convolutional layer has 2 kernels (or filters). Each filter has a depth of 3, equal to the number of channels in the input. Using the notation you used in your question:
  
  * Filter 1, channel 1 to input channel 1
  * Filter 1, channel 2 to input channel 2
  * Filter 1, channel 3 to input channel 3
  * Sum all three channels of filter 1, then add bias
  * Filter 2, channel 1 to input channel 1
  * Filter 2, channel 2 to input channel 2
  * Filter 2, channel 3 to input channel 3
  * Sum all three channels of filter 2, then add bias
  
  These steps are repeated for each frame the filter slides over the input image.
  
  To answer question 2, if the output is 128, that simply means there are 128 filters. There could be an infinite number of filters if you so choose.
  
  EDIT:
  
  Here's the link to the interactive graphic: <http://cs231n.github.io/convolutional-networks/>
  
  > **Comments:**
  > **username_0**: Apologies for the late reply. Thank you v much for the answer. Makes sense. With regards to question 2, I may have not phrased the question clearly. My question was how do you apply 128 filters to 64 outputs from Maxpool layer, and still end up with an output of 128 feature maps. My thought was, each filter is applied to each Maxpool output. In this case you end up with 64 x 128 filters =  8192 feature maps instead of 128. However, when I read the article your shared: http://cs231n.github.io/convolutional-networks/, in the entire article there's one key sentence which I think helps explain ..  
  > **username_0**: “As we will soon see, the neurons in a layer will only be connected to a small region of the layer before it, instead of all of the neurons in a fully-connected manner”. So my thinking/understanding of this (which I could be wrong), is that only a select outputs will have a select filters applied to them in such a way where you end up with the same number of output feature maps as the filters. In the case of the 64 “Maxpooled” outputs, perhaps every 1 Maxpool output is connected to 2 filters ...  
  > **username_0**: which makes sense because then you would get the output of 128 feature maps. Does that make sense and is it correct?  
  > **username_1**: Not quite, but you're on the right idea. I think what's confusing is the term "filter", which I would argue is horrifically incorrect, as a "filter", is actually rather a collection of filters (called channels). So in this case, the 128 filters are each a collection of 64 filters (channels), which correspond to a depth level of the output of the maxpool layer.  
  > **username_1**: Say we're filter collection 1, then we perform the intuitive sliding and multiplying of each of the 64 filters (channels) in the collection, then for each output node of the collection, take the total sum of all 64 filters (channels) at that location, and then once put through an activation function, that is your final output for that layer.  
  > **username_0**: Excellent explanation. That makes perfect sense now. So the key missing part of information that cleared it up for me is: "then for each output node of the collection, take the total sum of all 64 filters (channels) at that location". Man seriously, it's these small details that I found hard to clarify from literature and articles, or it's explained at the input image convolution layer stage, but I failed to apply the same concept from a Maxpool to another Convolution layer stage. Thank you very much.  
  > **username_0**: I assumed the 64 channels of a filter collection start as aribitrary values that are optimised over time with the backpropagation optimisation gradient descent stage, much like the other parameters that get optimised in the network during the learning process.  
  > **username_0**: Also one final question, how did you embed the screenshots in your thread so they appear in the post. Mine didn't show on the post, and you have to click on the image link to show it. :(  
  > **username_1**: I just copied the image across rather then a link. Also just as a note, the initial values of the filters are always randomly selected, but over a specific range. You'll notice very quickly if you don't select the correct initial values the network will fail to learn almost every time, as you will get both exploding and vanishing numbers in the forward *and* backward pass. I asked a question in relation to this and got a fantastic answer, see here: https://ai.stackexchange.com/questions/13106/how-are-exploding-numbers-in-a-forward-pass-of-a-cnn-combated  
  > **username_0**: Sorry for asking another question, just one more question. You mentioned: "... take the total sum of all 64 filters (channels) at that location ...". Do we actually add all 64 matrices together, or do we get their combined 'dot' products? Also the final output should be only 1 matrix (feature map), correct? That way with every filter (and its 64 channels) produce only 1 output matrix(feature map), then we would have the expected 128 matrices (or 128 feature maps) output.  
  > **username_1**: If you consider the output to be a 3d matrix, then yes, otherwise no, the output should be 128 2d matrices. Yes, you add the matrices together.  
  
  ---
  
  