Model summary Unet

username: Jay_Super
cooked: <p>When I print summary(model,(1,512,512)) I get so many RELU printed out, while there should actually be only a few. I am assuming something is wrong with my model.py code. Can someone please help me out find whats wrong?</p>
<pre><code class="lang-python">class VGGBlock(nn.Module):
    def __init__(self, in_channels, middle_channels, out_channels, act_func=nn.ReLU(inplace=True)):
        super(VGGBlock, self).__init__()
        self.act_func = act_func
        self.conv1 = nn.Conv2d(in_channels, middle_channels, 3, padding=1)
        self.bn1 = nn.BatchNorm2d(middle_channels)
        self.conv2 = nn.Conv2d(middle_channels, out_channels, 3, padding=1)
        self.bn2 = nn.BatchNorm2d(out_channels)

    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.act_func(out)

        out = self.conv2(out)
        out = self.bn2(out)
        out = self.act_func(out)

        return out


class UNet(nn.Module):
    def __init__(self, args):
        super().__init__()

        self.args = args

        nb_filter = [32, 64, 128, 256, 512]

        self.pool = nn.MaxPool2d(2, 2)
        self.up = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)

        self.conv0_0 = VGGBlock(args['input_channels'], nb_filter[0], nb_filter[0])
        self.conv1_0 = VGGBlock(nb_filter[0], nb_filter[1], nb_filter[1])
        self.conv2_0 = VGGBlock(nb_filter[1], nb_filter[2], nb_filter[2])
        self.conv3_0 = VGGBlock(nb_filter[2], nb_filter[3], nb_filter[3])
        self.conv4_0 = VGGBlock(nb_filter[3], nb_filter[4], nb_filter[4])

        self.conv3_1 = VGGBlock(nb_filter[3]+nb_filter[4], nb_filter[3], nb_filter[3])
        self.conv2_2 = VGGBlock(nb_filter[2]+nb_filter[3], nb_filter[2], nb_filter[2])
        self.conv1_3 = VGGBlock(nb_filter[1]+nb_filter[2], nb_filter[1], nb_filter[1])
        self.conv0_4 = VGGBlock(nb_filter[0]+nb_filter[1], nb_filter[0], nb_filter[0])

        self.final = nn.Conv2d(nb_filter[0], 1, kernel_size=1)


    def forward(self, input):
        x0_0 = self.conv0_0(input)
        print(x0_0.shape)
        x1_0 = self.conv1_0(self.pool(x0_0))
        print(x1_0.shape)
        x2_0 = self.conv2_0(self.pool(x1_0))
        print(x2_0.shape)
        x3_0 = self.conv3_0(self.pool(x2_0))
        print(x3_0.shape)
        x4_0 = self.conv4_0(self.pool(x3_0))
        print(x4_0.shape)
        print(" ")
        x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1))
        print(x3_1.shape)
        x2_2 = self.conv2_2(torch.cat([x2_0, self.up(x3_1)], 1))
        print(x2_2.shape)
        x1_3 = self.conv1_3(torch.cat([x1_0, self.up(x2_2)], 1))
        print(x1_3.shape)
        x0_4 = self.conv0_4(torch.cat([x0_0, self.up(x1_3)], 1))
        print(x0_4.shape)

        output = self.final(x0_4)
        output = F.sigmoid(output)


        print("THE OUTPUT IS:" ,output.shape)
        return output
</code></pre>
<hr>
<pre><code>    Layer (type)               Output Shape         Param #
</code></pre>
<p>================================================================<br>
Conv2d-1         [-1, 32, 512, 512]             320<br>
BatchNorm2d-2         [-1, 32, 512, 512]              64<br>
ReLU-3         [-1, 32, 512, 512]               0<br>
ReLU-4         [-1, 32, 512, 512]               0<br>
ReLU-5         [-1, 32, 512, 512]               0<br>
ReLU-6         [-1, 32, 512, 512]               0<br>
ReLU-7         [-1, 32, 512, 512]               0<br>
ReLU-8         [-1, 32, 512, 512]               0<br>
ReLU-9         [-1, 32, 512, 512]               0<br>
ReLU-10         [-1, 32, 512, 512]               0<br>
ReLU-11         [-1, 32, 512, 512]               0<br>
Conv2d-12         [-1, 32, 512, 512]           9,248<br>
BatchNorm2d-13         [-1, 32, 512, 512]              64<br>
ReLU-14         [-1, 32, 512, 512]               0<br>
ReLU-15         [-1, 32, 512, 512]               0<br>
ReLU-16         [-1, 32, 512, 512]               0<br>
ReLU-17         [-1, 32, 512, 512]               0<br>
ReLU-18         [-1, 32, 512, 512]               0<br>
ReLU-19         [-1, 32, 512, 512]               0<br>
ReLU-20         [-1, 32, 512, 512]               0<br>
ReLU-21         [-1, 32, 512, 512]               0<br>
ReLU-22         [-1, 32, 512, 512]               0<br>
VGGBlock-23         [-1, 32, 512, 512]               0<br>
MaxPool2d-24         [-1, 32, 256, 256]               0<br>
Conv2d-25         [-1, 64, 256, 256]          18,496<br>
BatchNorm2d-26         [-1, 64, 256, 256]             128<br>
ReLU-27         [-1, 64, 256, 256]               0<br>
ReLU-28         [-1, 64, 256, 256]               0<br>
ReLU-29         [-1, 64, 256, 256]               0<br>
ReLU-30         [-1, 64, 256, 256]               0<br>
ReLU-31         [-1, 64, 256, 256]               0<br>
ReLU-32         [-1, 64, 256, 256]               0<br>
ReLU-33         [-1, 64, 256, 256]               0<br>
ReLU-34         [-1, 64, 256, 256]               0<br>
ReLU-35         [-1, 64, 256, 256]               0<br>
Conv2d-36         [-1, 64, 256, 256]          36,928<br>
BatchNorm2d-37         [-1, 64, 256, 256]             128<br>
ReLU-38         [-1, 64, 256, 256]               0<br>
ReLU-39         [-1, 64, 256, 256]               0<br>
ReLU-40         [-1, 64, 256, 256]               0<br>
ReLU-41         [-1, 64, 256, 256]               0<br>
ReLU-42         [-1, 64, 256, 256]               0<br>
ReLU-43         [-1, 64, 256, 256]               0<br>
ReLU-44         [-1, 64, 256, 256]               0<br>
ReLU-45         [-1, 64, 256, 256]               0<br>
ReLU-46         [-1, 64, 256, 256]               0<br>
VGGBlock-47         [-1, 64, 256, 256]               0<br>
MaxPool2d-48         [-1, 64, 128, 128]               0<br>
Conv2d-49        [-1, 128, 128, 128]          73,856<br>
BatchNorm2d-50        [-1, 128, 128, 128]             256<br>
ReLU-51        [-1, 128, 128, 128]               0<br>
ReLU-52        [-1, 128, 128, 128]               0<br>
ReLU-53        [-1, 128, 128, 128]               0<br>
ReLU-54        [-1, 128, 128, 128]               0<br>
ReLU-55        [-1, 128, 128, 128]               0<br>
ReLU-56        [-1, 128, 128, 128]               0<br>
ReLU-57        [-1, 128, 128, 128]               0<br>
ReLU-58        [-1, 128, 128, 128]               0<br>
ReLU-59        [-1, 128, 128, 128]               0<br>
Conv2d-60        [-1, 128, 128, 128]         147,584<br>
BatchNorm2d-61        [-1, 128, 128, 128]             256<br>
ReLU-62        [-1, 128, 128, 128]               0<br>
ReLU-63        [-1, 128, 128, 128]               0<br>
ReLU-64        [-1, 128, 128, 128]               0<br>
ReLU-65        [-1, 128, 128, 128]               0<br>
ReLU-66        [-1, 128, 128, 128]               0<br>
ReLU-67        [-1, 128, 128, 128]               0<br>
ReLU-68        [-1, 128, 128, 128]               0<br>
ReLU-69        [-1, 128, 128, 128]               0<br>
ReLU-70        [-1, 128, 128, 128]               0<br>
VGGBlock-71        [-1, 128, 128, 128]               0<br>
MaxPool2d-72          [-1, 128, 64, 64]               0<br>
Conv2d-73          [-1, 256, 64, 64]         295,168<br>
BatchNorm2d-74          [-1, 256, 64, 64]             512<br>
ReLU-75          [-1, 256, 64, 64]               0<br>
ReLU-76          [-1, 256, 64, 64]               0<br>
ReLU-77          [-1, 256, 64, 64]               0<br>
ReLU-78          [-1, 256, 64, 64]               0<br>
ReLU-79          [-1, 256, 64, 64]               0<br>
ReLU-80          [-1, 256, 64, 64]               0<br>
ReLU-81          [-1, 256, 64, 64]               0<br>
ReLU-82          [-1, 256, 64, 64]               0<br>
ReLU-83          [-1, 256, 64, 64]               0<br>
Conv2d-84          [-1, 256, 64, 64]         590,080<br>
BatchNorm2d-85          [-1, 256, 64, 64]             512<br>
ReLU-86          [-1, 256, 64, 64]               0<br>
ReLU-87          [-1, 256, 64, 64]               0<br>
ReLU-88          [-1, 256, 64, 64]               0<br>
ReLU-89          [-1, 256, 64, 64]               0<br>
ReLU-90          [-1, 256, 64, 64]               0<br>
ReLU-91          [-1, 256, 64, 64]               0<br>
ReLU-92          [-1, 256, 64, 64]               0<br>
ReLU-93          [-1, 256, 64, 64]               0<br>
ReLU-94          [-1, 256, 64, 64]               0<br>
VGGBlock-95          [-1, 256, 64, 64]               0<br>
MaxPool2d-96          [-1, 256, 32, 32]               0<br>
Conv2d-97          [-1, 512, 32, 32]       1,180,160<br>
BatchNorm2d-98          [-1, 512, 32, 32]           1,024<br>
ReLU-99          [-1, 512, 32, 32]               0<br>
ReLU-100          [-1, 512, 32, 32]               0<br>
ReLU-101          [-1, 512, 32, 32]               0<br>
ReLU-102          [-1, 512, 32, 32]               0<br>
ReLU-103          [-1, 512, 32, 32]               0<br>
ReLU-104          [-1, 512, 32, 32]               0<br>
ReLU-105          [-1, 512, 32, 32]               0<br>
ReLU-106          [-1, 512, 32, 32]               0<br>
ReLU-107          [-1, 512, 32, 32]               0<br>
Conv2d-108          [-1, 512, 32, 32]       2,359,808<br>
BatchNorm2d-109          [-1, 512, 32, 32]           1,024<br>
ReLU-110          [-1, 512, 32, 32]               0<br>
ReLU-111          [-1, 512, 32, 32]               0<br>
ReLU-112          [-1, 512, 32, 32]               0<br>
ReLU-113          [-1, 512, 32, 32]               0<br>
ReLU-114          [-1, 512, 32, 32]               0<br>
ReLU-115          [-1, 512, 32, 32]               0<br>
ReLU-116          [-1, 512, 32, 32]               0<br>
ReLU-117          [-1, 512, 32, 32]               0<br>
ReLU-118          [-1, 512, 32, 32]               0<br>
VGGBlock-119          [-1, 512, 32, 32]               0<br>
Upsample-120          [-1, 512, 64, 64]               0<br>
Conv2d-121          [-1, 256, 64, 64]       1,769,728<br>
BatchNorm2d-122          [-1, 256, 64, 64]             512<br>
ReLU-123          [-1, 256, 64, 64]               0<br>
ReLU-124          [-1, 256, 64, 64]               0<br>
ReLU-125          [-1, 256, 64, 64]               0<br>
ReLU-126          [-1, 256, 64, 64]               0<br>
ReLU-127          [-1, 256, 64, 64]               0<br>
ReLU-128          [-1, 256, 64, 64]               0<br>
ReLU-129          [-1, 256, 64, 64]               0<br>
ReLU-130          [-1, 256, 64, 64]               0<br>
ReLU-131          [-1, 256, 64, 64]               0<br>
Conv2d-132          [-1, 256, 64, 64]         590,080<br>
BatchNorm2d-133          [-1, 256, 64, 64]             512<br>
ReLU-134          [-1, 256, 64, 64]               0<br>
ReLU-135          [-1, 256, 64, 64]               0<br>
ReLU-136          [-1, 256, 64, 64]               0<br>
ReLU-137          [-1, 256, 64, 64]               0<br>
ReLU-138          [-1, 256, 64, 64]               0<br>
ReLU-139          [-1, 256, 64, 64]               0<br>
ReLU-140          [-1, 256, 64, 64]               0<br>
ReLU-141          [-1, 256, 64, 64]               0<br>
ReLU-142          [-1, 256, 64, 64]               0<br>
VGGBlock-143          [-1, 256, 64, 64]               0<br>
Upsample-144        [-1, 256, 128, 128]               0<br>
Conv2d-145        [-1, 128, 128, 128]         442,496<br>
BatchNorm2d-146        [-1, 128, 128, 128]             256<br>
ReLU-147        [-1, 128, 128, 128]               0<br>
ReLU-148        [-1, 128, 128, 128]               0<br>
ReLU-149        [-1, 128, 128, 128]               0<br>
ReLU-150        [-1, 128, 128, 128]               0<br>
ReLU-151        [-1, 128, 128, 128]               0<br>
ReLU-152        [-1, 128, 128, 128]               0<br>
ReLU-153        [-1, 128, 128, 128]               0<br>
ReLU-154        [-1, 128, 128, 128]               0<br>
ReLU-155        [-1, 128, 128, 128]               0<br>
Conv2d-156        [-1, 128, 128, 128]         147,584<br>
BatchNorm2d-157        [-1, 128, 128, 128]             256<br>
ReLU-158        [-1, 128, 128, 128]               0<br>
ReLU-159        [-1, 128, 128, 128]               0<br>
ReLU-160        [-1, 128, 128, 128]               0<br>
ReLU-161        [-1, 128, 128, 128]               0<br>
ReLU-162        [-1, 128, 128, 128]               0<br>
ReLU-163        [-1, 128, 128, 128]               0<br>
ReLU-164        [-1, 128, 128, 128]               0<br>
ReLU-165        [-1, 128, 128, 128]               0<br>
ReLU-166        [-1, 128, 128, 128]               0<br>
VGGBlock-167        [-1, 128, 128, 128]               0<br>
Upsample-168        [-1, 128, 256, 256]               0<br>
Conv2d-169         [-1, 64, 256, 256]         110,656<br>
BatchNorm2d-170         [-1, 64, 256, 256]             128<br>
ReLU-171         [-1, 64, 256, 256]               0<br>
ReLU-172         [-1, 64, 256, 256]               0<br>
ReLU-173         [-1, 64, 256, 256]               0<br>
ReLU-174         [-1, 64, 256, 256]               0<br>
ReLU-175         [-1, 64, 256, 256]               0<br>
ReLU-176         [-1, 64, 256, 256]               0<br>
ReLU-177         [-1, 64, 256, 256]               0<br>
ReLU-178         [-1, 64, 256, 256]               0<br>
ReLU-179         [-1, 64, 256, 256]               0<br>
Conv2d-180         [-1, 64, 256, 256]          36,928<br>
BatchNorm2d-181         [-1, 64, 256, 256]             128<br>
ReLU-182         [-1, 64, 256, 256]               0<br>
ReLU-183         [-1, 64, 256, 256]               0<br>
ReLU-184         [-1, 64, 256, 256]               0<br>
ReLU-185         [-1, 64, 256, 256]               0<br>
ReLU-186         [-1, 64, 256, 256]               0<br>
ReLU-187         [-1, 64, 256, 256]               0<br>
ReLU-188         [-1, 64, 256, 256]               0<br>
ReLU-189         [-1, 64, 256, 256]               0<br>
ReLU-190         [-1, 64, 256, 256]               0<br>
VGGBlock-191         [-1, 64, 256, 256]               0<br>
Upsample-192         [-1, 64, 512, 512]               0<br>
Conv2d-193         [-1, 32, 512, 512]          27,680<br>
BatchNorm2d-194         [-1, 32, 512, 512]              64<br>
ReLU-195         [-1, 32, 512, 512]               0<br>
ReLU-196         [-1, 32, 512, 512]               0<br>
ReLU-197         [-1, 32, 512, 512]               0<br>
ReLU-198         [-1, 32, 512, 512]               0<br>
ReLU-199         [-1, 32, 512, 512]               0<br>
ReLU-200         [-1, 32, 512, 512]               0<br>
ReLU-201         [-1, 32, 512, 512]               0<br>
ReLU-202         [-1, 32, 512, 512]               0<br>
ReLU-203         [-1, 32, 512, 512]               0<br>
Conv2d-204         [-1, 32, 512, 512]           9,248<br>
BatchNorm2d-205         [-1, 32, 512, 512]              64<br>
ReLU-206         [-1, 32, 512, 512]               0<br>
ReLU-207         [-1, 32, 512, 512]               0<br>
ReLU-208         [-1, 32, 512, 512]               0<br>
ReLU-209         [-1, 32, 512, 512]               0<br>
ReLU-210         [-1, 32, 512, 512]               0<br>
ReLU-211         [-1, 32, 512, 512]               0<br>
ReLU-212         [-1, 32, 512, 512]               0<br>
ReLU-213         [-1, 32, 512, 512]               0<br>
ReLU-214         [-1, 32, 512, 512]               0<br>
VGGBlock-215         [-1, 32, 512, 512]               0<br>
Conv2d-216          [-1, 1, 512, 512]              33</p>

username: ptrblck
cooked: <p>Your code looks alright.<br>
Could this be a bug from the summary lib you are using? Would you mind opening an issue on their GitHub and check, if that’s the case?</p>