Answers.Body: <p>Let's say you have an image with <span class="math-container">$3$</span> channels and you have <span class="math-container">$10$</span> filters, where each filter has the shape <span class="math-container">$5 \times 5 \times 3$</span>. The <strong>depth</strong> of the convolutional layer after having applied this filter to the image is <span class="math-container">$10$</span>, which is equal to the number of filters. The spatial dimensions of the filter (in this case, <span class="math-container">$5 \times 5$</span>) are more or less defined arbitrarily (it's a hyperparameter).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-04-22T19:59:32.070Z
Answers.LastActivityDate: 2021-12-18T16:13:16.140Z
Answers.LastEditDate: 2021-12-18T16:13:16.140Z
Answers.UserDisplayName: GPrathap
Answers.Body: <p>Given that you were also asking for a reference that describes in detail these operations, you should take a look at the paper <a href="https://arxiv.org/pdf/1603.07285.pdf" rel="nofollow noreferrer">A guide to convolution arithmetic for deep learning</a> (2018), which describes in detail the arithmetic of many convolution operations used in convolutional neural networks. There's also <a href="https://github.com/vdumoulin/conv_arithmetic" rel="nofollow noreferrer">the associated repo</a> with the animations of the different operations.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-18T16:19:21.013Z
Answers.LastActivityDate: 2021-12-18T16:19:21.013Z
Answers.UserDisplayName: nbro
Answers.Body: <p>The <span class="math-container">$96$</span> is the number of <strong>feature maps</strong>, which is equal to the number of filters/kernels.</p>
  <p>The choice of the number of kernels is not fully arbitrary, although there is no equation or exact rule restricting the number.</p>
  <p>If you have a CNN, one single convolution operation would be pointless: since it is used for the whole image information, it can generalize, but only to specific (meaning: a finite amount of) features. Easy example: if a 7x7 filter in the first layer concentrates on round shapes, it can not generalize on let's say red cubes at the same time.</p>
  <p>Therefore, your convolutional layers have several filters/kernels, i.e. several weights where each is used for a convolution. The result of each of these convolutions is one filter/feature map, i.e. the image information convolved by a kernel.</p>
  <p>Typically, you look at your kernels and your problem's domain to figure out what an appropriate number of kernels could be. You also have to keep in mind that too few kernels could possibly lose information and overfit specific patterns, while too many kernels could possibly underfit. Especially, when you have far more parameters (primarily the weights of your neural network) than training data, your neural network will normally perform bad and you have to reduce its size.</p>
  <p>The kernels should not be confused with batch size. The batch size is the number of samples (here images) you train <em>in parallel</em>. Each training step of your neural network does not only consist of feeding a single image, but feeding <em>batch size</em> number of images, usually combined with batch normalization steps between the layers. Hence, this has nothing to do with the number of kernels.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-09T00:04:12.953Z
Answers.Text: This is great, I understand now. Using the terminology in your post, I had a search and found: https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/ which made it clear what the purpose of each filter kernel was. Thanks!
Answers.UserDisplayName: OnNIX
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-05-08T23:56:28.040Z
Answers.LastActivityDate: 2021-12-18T16:09:26.313Z
Answers.LastEditDate: 2021-12-18T16:09:26.313Z
Answers.UserDisplayName: daniel451
Body: <p>I am looking at a diagram of <a href="https://arxiv.org/pdf/1311.2901.pdf" rel="nofollow noreferrer">ZFNet</a> below, in an attempt to understand how CNNs are designed.</p>
  <p><a href="https://i.sstatic.net/8af4m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8af4m.png" alt="enter image description here" /></a></p>
  <p>In the first layer, I understand the depth of 3 (224x224x3) is the number of color channels in the image.</p>
  <p>In the second layer, I understand the <span class="math-container">$110 \times 110$</span> is computed with the formula <span class="math-container">$W_2 = (W_1-F+2P)/S + 1 = (224 - 7 + 2*1/2)/2 + 1 = 110$</span>.</p>
  <p>I also understand how pooling works to create a size reduction from <span class="math-container">$110 \times 110$</span> to <span class="math-container">$55 \times 55$</span>.</p>
  <p>But where does the depth of <span class="math-container">$96$</span> come from in the second layer? Is this the new &quot;batch size&quot;? Is it totally arbitrary?</p>
  <p>Bonus points if someone can direct me to a reference that can help me understand how all these dimensions relate to each other.</p>
  
Tags: <convolutional-neural-networks><reference-request><filters><convolution-arithmetic><feature-maps>
Title: How is the depth of a convolutional layer determined?
UserDisplayName: OnNIX
ThreadText: # How is the depth of a convolutional layer determined?
  
  (Asked by: username_0 on 2017-05-08)
  
  I am looking at a diagram of [ZFNet](https://arxiv.org/pdf/1311.2901.pdf) below, in an attempt to understand how CNNs are designed.
  
  [![enter image description here](https://i.sstatic.net/8af4m.png)](https://i.sstatic.net/8af4m.png)
  
  In the first layer, I understand the depth of 3 (224x224x3) is the number of color channels in the image.
  
  In the second layer, I understand the $110 \times 110$ is computed with the formula $W\_2 = (W\_1-F+2P)/S + 1 = (224 - 7 + 2\*1/2)/2 + 1 = 110$.
  
  I also understand how pooling works to create a size reduction from $110 \times 110$ to $55 \times 55$.
  
  But where does the depth of $96$ come from in the second layer? Is this the new "batch size"? Is it totally arbitrary?
  
  Bonus points if someone can direct me to a reference that can help me understand how all these dimensions relate to each other.
  
  **Tags:** convolutional-neural-networks, reference-request, filters, convolution-arithmetic, feature-maps
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2017-05-08. Score: 5 | Accepted answer
  
  The $96$ is the number of **feature maps**, which is equal to the number of filters/kernels.
  
  The choice of the number of kernels is not fully arbitrary, although there is no equation or exact rule restricting the number.
  
  If you have a CNN, one single convolution operation would be pointless: since it is used for the whole image information, it can generalize, but only to specific (meaning: a finite amount of) features. Easy example: if a 7x7 filter in the first layer concentrates on round shapes, it can not generalize on let's say red cubes at the same time.
  
  Therefore, your convolutional layers have several filters/kernels, i.e. several weights where each is used for a convolution. The result of each of these convolutions is one filter/feature map, i.e. the image information convolved by a kernel.
  
  Typically, you look at your kernels and your problem's domain to figure out what an appropriate number of kernels could be. You also have to keep in mind that too few kernels could possibly lose information and overfit specific patterns, while too many kernels could possibly underfit. Especially, when you have far more parameters (primarily the weights of your neural network) than training data, your neural network will normally perform bad and you have to reduce its size.
  
  The kernels should not be confused with batch size. The batch size is the number of samples (here images) you train *in parallel*. Each training step of your neural network does not only consist of feeding a single image, but feeding *batch size* number of images, usually combined with batch normalization steps between the layers. Hence, this has nothing to do with the number of kernels.
  
  > **Comments:**
  > **username_0**: This is great, I understand now. Using the terminology in your post, I had a search and found: https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/ which made it clear what the purpose of each filter kernel was. Thanks!  
  
  ---
  
  ### Answer by username_1 on 2018-04-22. Score: 2
  
  Let's say you have an image with $3$ channels and you have $10$ filters, where each filter has the shape $5 \times 5 \times 3$. The **depth** of the convolutional layer after having applied this filter to the image is $10$, which is equal to the number of filters. The spatial dimensions of the filter (in this case, $5 \times 5$) are more or less defined arbitrarily (it's a hyperparameter).
  
  
  ---
  
  ### Answer by username_2 on 2021-12-18. Score: 1
  
  Given that you were also asking for a reference that describes in detail these operations, you should take a look at the paper [A guide to convolution arithmetic for deep learning](https://arxiv.org/pdf/1603.07285.pdf) (2018), which describes in detail the arithmetic of many convolution operations used in convolutional neural networks. There's also [the associated repo](https://github.com/vdumoulin/conv_arithmetic) with the animations of the different operations.
  
  
  ---
  
  