Verify BigGAN generator architecture from torchsummary

username: Najeh_Nafti
cooked: <p>I would like to verify the architecture of the BigGAN generator based on summary output as presented below:</p>
<p>Generator Residual Block:</p>
<pre><code class="lang-auto"># Generator Block
# Generator Block
class GConvBlock(nn.Module):
    def __init__(self, in_channel, out_channel, kernel_size=3,  padding=1, stride=1, n_class=None,
                 activation=None, upsample= None):
        
        super().__init__()


        self.conv1 =  nn.utils.spectral_norm(nn.Conv2d(in_channel, out_channel, kernel_size, stride, padding))
        self.conv2 =  nn.utils.spectral_norm(nn.Conv2d(out_channel, out_channel, kernel_size, stride, padding))
        
        self.skip_proj = False
        if in_channel != out_channel or upsample :
            self.conv_skip =  nn.utils.spectral_norm(nn.Conv2d(in_channel, out_channel, 1, 1, 0))
            self.skip_proj = True

        self.upsample =  nn.Upsample(scale_factor=2)   

      #  self.downsample = downsample
        self.activation = nn.ReLU()
        
        self.norm1 = nn.BatchNorm2d(in_channel)
        self.norm2 = nn.BatchNorm2d(out_channel)

    def forward(self, input):
        
        out = self.norm1(input)
        out = self.activation(out)
        out = self.upsample(out)
        out = self.conv1(out)
        
        
        out = self.norm2(out)    
        out = self.activation(out)
        out = self.conv2(out)
        
        skip = self.upsample(input)
        if self.skip_proj:
            skip = self.conv_skip(skip)


        return out + skip
</code></pre>
<pre><code class="lang-auto">summary(G,(1,128))

==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
├─Linear: 1-1                            [-1, 1, 16384]            2,113,536
├─ModuleList: 1                          []                        --
|    └─GConvBlock: 2-1                   [-1, 1024, 8, 8]          --
|    |    └─BatchNorm2d: 3-1             [-1, 1024, 4, 4]          2,048
|    |    └─ReLU: 3-2                    [-1, 1024, 4, 4]          --
|    |    └─Upsample: 3-3                [-1, 1024, 8, 8]          --
|    |    └─Conv2d: 3-4                  [-1, 1024, 8, 8]          9,438,208
|    |    └─BatchNorm2d: 3-5             [-1, 1024, 8, 8]          2,048
|    |    └─ReLU: 3-6                    [-1, 1024, 8, 8]          --
|    |    └─Conv2d: 3-7                  [-1, 1024, 8, 8]          9,438,208
|    |    └─Upsample: 3-8                [-1, 1024, 8, 8]          --
|    └─GConvBlock: 2-2                   [-1, 512, 16, 16]         --
|    |    └─BatchNorm2d: 3-9             [-1, 1024, 8, 8]          2,048
|    |    └─ReLU: 3-10                   [-1, 1024, 8, 8]          --
|    |    └─Upsample: 3-11               [-1, 1024, 16, 16]        --
|    |    └─Conv2d: 3-12                 [-1, 512, 16, 16]         4,719,104
|    |    └─BatchNorm2d: 3-13            [-1, 512, 16, 16]         1,024
|    |    └─ReLU: 3-14                   [-1, 512, 16, 16]         --
|    |    └─Conv2d: 3-15                 [-1, 512, 16, 16]         2,359,808
|    |    └─Upsample: 3-16               [-1, 1024, 16, 16]        --
|    |    └─Conv2d: 3-17                 [-1, 512, 16, 16]         524,800
|    └─GConvBlock: 2-3                   [-1, 256, 32, 32]         --
|    |    └─BatchNorm2d: 3-18            [-1, 512, 16, 16]         1,024
|    |    └─ReLU: 3-19                   [-1, 512, 16, 16]         --
|    |    └─Upsample: 3-20               [-1, 512, 32, 32]         --
|    |    └─Conv2d: 3-21                 [-1, 256, 32, 32]         1,179,904
|    |    └─BatchNorm2d: 3-22            [-1, 256, 32, 32]         512
|    |    └─ReLU: 3-23                   [-1, 256, 32, 32]         --
|    |    └─Conv2d: 3-24                 [-1, 256, 32, 32]         590,080
|    |    └─Upsample: 3-25               [-1, 512, 32, 32]         --
|    |    └─Conv2d: 3-26                 [-1, 256, 32, 32]         131,328
|    └─GConvBlock: 2-4                   [-1, 128, 64, 64]         --
|    |    └─BatchNorm2d: 3-27            [-1, 256, 32, 32]         512
|    |    └─ReLU: 3-28                   [-1, 256, 32, 32]         --
|    |    └─Upsample: 3-29               [-1, 256, 64, 64]         --
|    |    └─Conv2d: 3-30                 [-1, 128, 64, 64]         295,040
|    |    └─BatchNorm2d: 3-31            [-1, 128, 64, 64]         256
|    |    └─ReLU: 3-32                   [-1, 128, 64, 64]         --
|    |    └─Conv2d: 3-33                 [-1, 128, 64, 64]         147,584
|    |    └─Upsample: 3-34               [-1, 256, 64, 64]         --
|    |    └─Conv2d: 3-35                 [-1, 128, 64, 64]         32,896
|    └─GConvBlock: 2-5                   [-1, 64, 128, 128]        --
|    |    └─BatchNorm2d: 3-36            [-1, 128, 64, 64]         256
|    |    └─ReLU: 3-37                   [-1, 128, 64, 64]         --
|    |    └─Upsample: 3-38               [-1, 128, 128, 128]       --
|    |    └─Conv2d: 3-39                 [-1, 64, 128, 128]        73,792
|    |    └─BatchNorm2d: 3-40            [-1, 64, 128, 128]        128
|    |    └─ReLU: 3-41                   [-1, 64, 128, 128]        --
|    |    └─Conv2d: 3-42                 [-1, 64, 128, 128]        36,928
|    |    └─Upsample: 3-43               [-1, 128, 128, 128]       --
|    |    └─Conv2d: 3-44                 [-1, 64, 128, 128]        8,256
├─Sequential: 1-2                        [-1, 3, 128, 128]         --
|    └─BatchNorm2d: 2-6                  [-1, 64, 128, 128]        128
|    └─ReLU: 2-7                         [-1, 64, 128, 128]        --
|    └─Conv2d: 2-8                       [-1, 3, 128, 128]         1,731
===================================================
</code></pre>