nn.Conv2d, what kind of filters did it use when I specify different out_channels?

noob213: <p>I noticed, I can specify how many filters the conv net should use, but what kind of filters are being used? (edge detection, sharpen etct ?)  What is the difference when I specify this argument as 10 or 20?</p>
<p>As how I understood looks like there is a “filter pool”, and different number of filters will be randomly picked from the pool as specified by the out_channels?</p>

ptrblck: <aside class="quote no-group" data-username="noob213" data-post="1" data-topic="82667">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/n/b5ac83/48.png" class="avatar"> noob213:</div>
<blockquote>
<p>I noticed, I can specify how many filters the conv net should use, but what kind of filters are being used? (edge detection, sharpen etct ?)</p>
</blockquote>
</aside>
<p>Each filter will be randomly initialized (using <a href="https://github.com/pytorch/pytorch/blob/d035d05080729c30636ff30fcc068de3c7e9badd/torch/nn/modules/conv.py#L61-L66">this metho</a> and trained. The filters will not be initialized as classical image processing filters, but the training procedure might of course yield filters which are similar to e.g. edge detectors etc.</p>
<aside class="quote no-group" data-username="noob213" data-post="1" data-topic="82667">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/n/b5ac83/48.png" class="avatar"> noob213:</div>
<blockquote>
<p>What is the difference when I specify this argument as 10 or 20?</p>
</blockquote>
</aside>
<p>Each filter will process the input activation and create an output activation map (in the default setup). The more filters a conv layer has, the more output channels (each processed by a single filter) it will yield. The higher the number of filters, the more “capacity” this layer has (similar to the number of neurons of a linear layer).</p>
<aside class="quote no-group" data-username="noob213" data-post="1" data-topic="82667">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/n/b5ac83/48.png" class="avatar"> noob213:</div>
<blockquote>
<p>As how I understood looks like there is a “filter pool”, and different number of filters will be randomly picked from the pool as specified by the out_channels?</p>
</blockquote>
</aside>
<p>No, all filters, which were specified during the initialization of the conv layer, will be used.</p>
<p>Have a look at <a href="https://cs231n.github.io/convolutional-networks/#layers">CS231n - Convolutions</a> for a general overview how this layer works.</p>

noob213: <p>“ Each filter will be randomly initialized (using [this metho and trained.”</p>
<p>So it means if I run the program twice with the same out_channels, nn.Conv2D might actually use different filters, just the number of filters will be the same.</p>

ptrblck: <p>Yes, if you don’t seed the code, this would be the case.<br>
To get the same pseudo random values, you could have a look at the <a href="https://pytorch.org/docs/stable/notes/randomness.html">Reproducibility docs</a>.</p>