Meaning of output shapes of ResNet9 model layers

username: alyeko
cooked: <p>I have a ResNet 9 model, implemented in Pytorch which I am using for multi-class image classification. My total number of classes is 6. Using the following code, from torchsummary library, I am able to show the summary of the model, seen in the attached image:</p>
<p><code>INPUT_SHAPE = (3, 256, 256)</code> <span class="hashtag-raw">#input</span> shape of my image<br>
<code>print(summary(model.cuda(), (INPUT_SHAPE)))</code></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/6/26290d1a6f052b3d761f3917db6212f66c7e3865.png" data-download-href="https://discuss.pytorch.org/uploads/default/26290d1a6f052b3d761f3917db6212f66c7e3865" title="qn for pytorch"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/6/26290d1a6f052b3d761f3917db6212f66c7e3865.png" alt="qn for pytorch" data-base62-sha1="5rA5VCmuvjuQeTZnzneRXLsbX6Z" width="463" height="500" data-dominant-color="F2F2F3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">qn for pytorch</span><span class="informations">480×518 8.81 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>However, I am quite confused about the -1 values in all layers of the ResNet9 model. Also, for Conv2d-1 layer, I am confused about the 64 value in the output shape [-1, 64, 256, 256] as I believe the <code>n_channels</code> value of the input image is 3. Can anyone please help me with the explanation of the output shape values? Thanks!</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="alyeko" data-post="1" data-topic="158839">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alyeko/48/49123_2.png" class="avatar"> alyeko:</div>
<blockquote>
<p>I am quite confused about the -1 values in all layers of the ResNet9 model.</p>
</blockquote>
</aside>
<p><code>summary</code> expects the first dimension to be the batch dimension and thus “dynamic”. Instead of printing a fixed batch size, they just print <code>-1</code> instead.</p>
<aside class="quote no-group" data-username="alyeko" data-post="1" data-topic="158839">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alyeko/48/49123_2.png" class="avatar"> alyeko:</div>
<blockquote>
<p>I am confused about the 64 value in the output shape [-1, 64, 256, 256] as I believe the <code>n_channels</code> value of the input image is 3</p>
</blockquote>
</aside>
<p><code>nn.Conv2d</code> layer define the <code>in_channels</code> as the number of channels of the input activation and <code>out_channels</code> as the number of channels of the output activation (and thus the number of filters) which is set to 64 in the first conv layer.</p>

username: alyeko
cooked: <p>Thanks a lot for your help <a class="mention" href="/u/ptrblck">@ptrblck</a>. Also, can it be said that Conv2d-1, BatchNorm2d-2 and ReLU-3 consist of the input layer of the network?</p>

username: ptrblck
cooked: <p>Most likely <code>Conv2d-1</code> would be the input layer to the model, but I don’t know how exactly <code>summary</code> creates the order of modules.<br>
E.g. using the order of module initialization could be wrong, since you can use any order to initialize the modules in the <code>__init__</code> method and use another order in the <code>forward</code>.<br>
The safest approach would be to check the <code>forward</code> method directly and see which layer is used first.</p>

username: alyeko
cooked: <p>I’ll try that, thanks a lot.</p>