Output shape from each layer in a Sequential model in pytorch

username: Sandeep_Kumar_GITAM
cooked: <p>SpinCNN(<br>
(conv_layer): Sequential(<br>
(0): Conv2d(30, 15, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(1): BatchNorm2d(15, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(2): ReLU(inplace=True)<br>
(3): Conv2d(15, 30, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(4): ReLU(inplace=True)<br>
(5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)<br>
(6): Conv2d(30, 60, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(7): BatchNorm2d(60, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(8): ReLU(inplace=True)<br>
(9): Conv2d(60, 60, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(10): ReLU(inplace=True)<br>
(11): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)<br>
(12): Dropout2d(p=0.05, inplace=False)<br>
(13): Conv2d(60, 120, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(14): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(15): ReLU(inplace=True)<br>
(16): Conv2d(120, 120, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))<br>
(17): ReLU(inplace=True)<br>
(18): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)<br>
)<br>
(fc_spin_layer1): Sequential(<br>
(0): Dropout(p=0.1, inplace=False)<br>
(1): Linear(in_features=60, out_features=20, bias=True)<br>
(2): ReLU(inplace=True)<br>
)<br>
(fc_spin_layer2): Sequential(<br>
(0): Dropout(p=0.1, inplace=False)<br>
(1): Linear(in_features=80, out_features=20, bias=True)<br>
(2): ReLU(inplace=True)<br>
)<br>
(fc_spin_layer3): Sequential(<br>
(0): Dropout(p=0.1, inplace=False)<br>
(1): Linear(in_features=80, out_features=20, bias=True)<br>
(2): ReLU(inplace=True)<br>
)<br>
(fc_spin_layer4): Sequential(<br>
(0): Dropout(p=0.1, inplace=False)<br>
(1): Linear(in_features=80, out_features=20, bias=True)<br>
(2): ReLU(inplace=True)<br>
)<br>
(fc_out): Sequential(<br>
(0): Dropout(p=0.1, inplace=False)<br>
(1): Linear(in_features=80, out_features=16, bias=True)<br>
)<br>
)<br>
Hello friends. Above is the model structure of a deep learning model . The summary for the above model: summary(model, (30, 15, 15))  is,</p>
<pre><code class="lang-auto">---------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1           [-1, 15, 15, 15]           4,065
       BatchNorm2d-2           [-1, 15, 15, 15]              30
              ReLU-3           [-1, 15, 15, 15]               0
            Conv2d-4           [-1, 30, 15, 15]           4,080
              ReLU-5           [-1, 30, 15, 15]               0
         MaxPool2d-6             [-1, 30, 7, 7]               0
            Conv2d-7             [-1, 60, 7, 7]          16,260
       BatchNorm2d-8             [-1, 60, 7, 7]             120
              ReLU-9             [-1, 60, 7, 7]               0
           Conv2d-10             [-1, 60, 7, 7]          32,460
             ReLU-11             [-1, 60, 7, 7]               0
        MaxPool2d-12             [-1, 60, 3, 3]               0
        Dropout2d-13             [-1, 60, 3, 3]               0
           Conv2d-14            [-1, 120, 3, 3]          64,920
      BatchNorm2d-15            [-1, 120, 3, 3]             240
             ReLU-16            [-1, 120, 3, 3]               0
           Conv2d-17            [-1, 120, 3, 3]         129,720
             ReLU-18            [-1, 120, 3, 3]               0
        MaxPool2d-19            [-1, 120, 1, 1]               0
          Dropout-20                   [-1, 60]               0
           Linear-21                   [-1, 20]           1,220
             ReLU-22                   [-1, 20]               0
          Dropout-23                   [-1, 80]               0
           Linear-24                   [-1, 20]           1,620
             ReLU-25                   [-1, 20]               0
          Dropout-26                   [-1, 80]               0
           Linear-27                   [-1, 20]           1,620
             ReLU-28                   [-1, 20]               0
          Dropout-29                   [-1, 80]               0
           Linear-30                   [-1, 20]           1,620
             ReLU-31                   [-1, 20]               0
          Dropout-32                   [-1, 80]               0
           Linear-33                   [-1, 16]           1,296
================================================================
Total params: 259,271
Trainable params: 259,271
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.03
Forward/backward pass size (MB): 0.36
Params size (MB): 0.99
Estimated Total Size (MB): 1.37
----------------------------------------------------------------
</code></pre>
<p>where Half_width =60 and layer_width = 20</p>
<p>I am unable to understand why the shape of the output within each convolution block is constant.</p>

username: mmg
cooked: <p>It is because you are using kernel_size = 3, stride=1, and padding=1. This will retain the image dimension since</p>
<pre><code class="lang-auto">output_size = (input_size + 2 * padding -kernel_size)/ stride +1
</code></pre>
<p>Hence, output_size = input_size. Try changing one of the parameters like stride or padding and the output dimensions will change.</p>
<p>Hope that helps!</p>