Answers.Body: <blockquote>
    <p>Am I right in thinking that because there are only <code>newImageX * newImageY</code> patterns in the <code>32 x 32</code> image, that the maximum amount of filters should be <code>newImageX * newImageY</code>, and any more would be redundant?</p>
  </blockquote>
  
  <p>Your assumption is wrong. If you have a <span class="math-container">$32 \times 32$</span> images (so consider only grayscale images), then you have <span class="math-container">$256^{32 \times 32}$</span> possible patterns (i.e. a <a href="https://www.universetoday.com/36302/atoms-in-the-universe/" rel="nofollow noreferrer">huge number of possible patterns!</a>), given that, for each pixel, you can have <span class="math-container">$256$</span> values, and there are <span class="math-container">$32\times 32$</span> pixels. Of course, for a human, many of these patterns may be very similar to each other (or even indistinguishable), but the way you measure similarity, in this case, is another hard problem. Hence also the difficulty in choosing the number of filters.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-22T02:42:26.143Z
Answers.Text: Later, I will eventually add more details about the possible "optimal" number of filters.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-22T02:35:14.603Z
Answers.LastActivityDate: 2020-02-22T02:46:17.837Z
Answers.LastEditDate: 2020-02-22T02:46:17.837Z
Answers.UserDisplayName: nbro
Body: <p>I’m trying to figure out how to write an optimal convolutional neural network with respect to maximizing and minimizing filters in a convolution 2D layer. This is my thinking and I’m not sure if it's correct.</p>
  
  <p>If we have a dataset of 32x32 images, we could start with a <code>Conv2D</code> layer, filter of 3x3 and stride of 1x1. Therefore the maximum times this filter would be able to fit into the 32 x 32 images would be 30 times e.g. <code>newImageX * newImageY</code></p>
  
  <pre><code>newImageX = (imageX – filterX + 1)  
  newImageY = (imageY – filterY + 1)
  </code></pre>
  
  <p>Am I right in thinking that because there are only <code>newImageX * newImageY</code> patterns in the 32 x 32 image, that the maximum amount of filters should be <code>newImageX * newImageY</code>, and any more would be redundant?</p>
  
  <p>So, the following code is the maximum possible filters given that we have 3x3 filter, 1x1 stride and 32x32 images?</p>
  
  <pre><code>Conv2D((30*30), kernel=(3,3), stride=(1,1), input_shape=(32,32,1))
  </code></pre>
  
  <p>Is there any reason to go above <code>30*30</code> filters, and are there any reasons to go below this number, assuming that <code>kernel</code>, <code>stride</code> and <code>input_shape</code> remain the same?</p>
  
  <p>If you knew you were looking for one specific filter, would you have to use the maximum amount of filters to ensure that the one you were looking for was present, or can you include it another way?</p>
  
Tags: <machine-learning><convolutional-neural-networks><convolution>
Title: How do I optimize the number of filters in a convolution layer?
UserDisplayName: w13rfed
ThreadText: # How do I optimize the number of filters in a convolution layer?
  
  (Asked by: username_0 on 2020-02-20)
  
  I’m trying to figure out how to write an optimal convolutional neural network with respect to maximizing and minimizing filters in a convolution 2D layer. This is my thinking and I’m not sure if it's correct.
  If we have a dataset of 32x32 images, we could start with a Conv2D layer, filter of 3x3 and stride of 1x1. Therefore the maximum times this filter would be able to fit into the 32 x 32 images would be 30 times e.g. newImageX * newImageY
  newImageX = (imageX – filterX + 1)  
  newImageY = (imageY – filterY + 1)
  
  Am I right in thinking that because there are only newImageX * newImageY patterns in the 32 x 32 image, that the maximum amount of filters should be newImageX * newImageY, and any more would be redundant?
  So, the following code is the maximum possible filters given that we have 3x3 filter, 1x1 stride and 32x32 images?
  Conv2D((30*30), kernel=(3,3), stride=(1,1), input_shape=(32,32,1))
  
  Is there any reason to go above 30*30 filters, and are there any reasons to go below this number, assuming that kernel, stride and input_shape remain the same?
  If you knew you were looking for one specific filter, would you have to use the maximum amount of filters to ensure that the one you were looking for was present, or can you include it another way?
  
  **Tags:** machine-learning, convolutional-neural-networks, convolution
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-22. Score: 3 | Accepted answer
  
  > Am I right in thinking that because there are only `newImageX * newImageY` patterns in the `32 x 32` image, that the maximum amount of filters should be `newImageX * newImageY`, and any more would be redundant?
  
  Your assumption is wrong. If you have a $32 \times 32$ images (so consider only grayscale images), then you have $256^{32 \times 32}$ possible patterns (i.e. a [huge number of possible patterns!](https://www.universetoday.com/36302/atoms-in-the-universe/)), given that, for each pixel, you can have $256$ values, and there are $32\times 32$ pixels. Of course, for a human, many of these patterns may be very similar to each other (or even indistinguishable), but the way you measure similarity, in this case, is another hard problem. Hence also the difficulty in choosing the number of filters.
  
  > **Comments:**
  > **username_1**: Later, I will eventually add more details about the possible "optimal" number of filters.  
  
  ---
  
  