GradCam Adaptation

chrishki: <p>I’m trying to use GradCam (<a href="https://github.com/jacobgil/pytorch-grad-cam" class="inline-onebox" rel="noopener nofollow ugc">GitHub - jacobgil/pytorch-grad-cam: Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.</a>) on my Densenet121 model, but am running into a size mismatch error I do not understand how to resolve. I am a beginner, so I believe I’m just missing something marginal.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/3/736ecdf1d4163824fa0478995d2c378d9f3d89d6.png" data-download-href="https://discuss.pytorch.org/uploads/default/736ecdf1d4163824fa0478995d2c378d9f3d89d6" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/3/736ecdf1d4163824fa0478995d2c378d9f3d89d6_2_690x204.png" alt="image" data-base62-sha1="gtaj0w8nURmkMtiBy7SvBh4RkOO" width="690" height="204" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/3/736ecdf1d4163824fa0478995d2c378d9f3d89d6_2_690x204.png, https://discuss.pytorch.org/uploads/default/original/3X/7/3/736ecdf1d4163824fa0478995d2c378d9f3d89d6.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/7/3/736ecdf1d4163824fa0478995d2c378d9f3d89d6.png 2x" data-dominant-color="421433"><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">image</span><span class="informations">903×268 134 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>I’m using the pretrained Densenet121 model from torchvision. I did not have any problems running the code with the Resnet50 model that was provided, but I am unable to adapt the code to work with my model.</p>
<pre data-code-wrap="python"><code class="lang-python">model = pretrainedmodels.__dict__['densenet121'](num_classes=1000,pretrained='imagenet')
            dim_feats = model.last_linear.in_features
            model.last_linear = nn.Sequential(nn.Linear(dim_feats, 3))
grad_cam = GradCam(model=model, feature_module=model.__dict__['_modules']['features'].denseblock4, target_layer_names=['denselayer16'], use_cuda=args.use_cuda)
</code></pre>
<p>Thanks in advance for any help.</p>

chrishki: <p>The image I am using is 224x224, like the one provided in the examples. I did not run into any errors when using it with the Resnet50 model.</p>

chrishki: <p>For reference, this is the architecture of the ResNet model:</p>
<pre><code class="lang-python">OrderedDict([('conv1',
              Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)),
             ('bn1',
              BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)),
             ('relu', ReLU(inplace=True)),
             ('maxpool',
              MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)),
             ('layer1',
              Sequential(
                (0): Bottleneck(
                  (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (downsample): Sequential(
                    (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  )
                )
                (1): Bottleneck(
                  (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (2): Bottleneck(
                  (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
              )),
             ('layer2',
              Sequential(
                (0): Bottleneck(
                  (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (downsample): Sequential(
                    (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
                    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  )
                )
                (1): Bottleneck(
                  (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (2): Bottleneck(
                  (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (3): Bottleneck(
                  (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
              )),
             ('layer3',
              Sequential(
                (0): Bottleneck(
                  (conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (downsample): Sequential(
                    (0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False)
                    (1): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  )
                )
                (1): Bottleneck(
                  (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (2): Bottleneck(
                  (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (3): Bottleneck(
                  (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (4): Bottleneck(
                  (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (5): Bottleneck(
                  (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
              )),
             ('layer4',
              Sequential(
                (0): Bottleneck(
                  (conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (downsample): Sequential(
                    (0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False)
                    (1): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  )
                )
                (1): Bottleneck(
                  (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
                (2): Bottleneck(
                  (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                )
              )),
             ('avgpool', AdaptiveAvgPool2d(output_size=(1, 1))),
             ('fc', Linear(in_features=2048, out_features=1000, bias=True))])
</code></pre>

chrishki: <p>And this is the architecture of the DenseNet model. The source of the error seems to be that there is an AdaptivePooling layer after the selected layer in the Resnet model; however, I’m not sure which layer to select in my DenseNet model. (Denseblock 2 was removed just so that the reply would post)</p>
<pre><code class="lang-python">OrderedDict([('features',
              Sequential(
                (conv0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
                (norm0): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                (relu0): ReLU(inplace=True)
                (pool0): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
                (denseblock1): _DenseBlock(
                  (denselayer1): _DenseLayer(
                    (norm1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(64, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer2): _DenseLayer(
                    (norm1): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(96, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer3): _DenseLayer(
                    (norm1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer4): _DenseLayer(
                    (norm1): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(160, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer5): _DenseLayer(
                    (norm1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer6): _DenseLayer(
                    (norm1): BatchNorm2d(224, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(224, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                )
                (transition1): _Transition(
                  (norm): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (pool): AvgPool2d(kernel_size=2, stride=2, padding=0)
                )

                &lt; removed denseblock2 &gt;

                (transition2): _Transition(
                  (norm): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (pool): AvgPool2d(kernel_size=2, stride=2, padding=0)
                )
                (denseblock3): _DenseBlock(
                  (denselayer1): _DenseLayer(
                    (norm1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer2): _DenseLayer(
                    (norm1): BatchNorm2d(288, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(288, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer3): _DenseLayer(
                    (norm1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(320, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer4): _DenseLayer(
                    (norm1): BatchNorm2d(352, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(352, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer5): _DenseLayer(
                    (norm1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(384, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer6): _DenseLayer(
                    (norm1): BatchNorm2d(416, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(416, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer7): _DenseLayer(
                    (norm1): BatchNorm2d(448, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(448, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer8): _DenseLayer(
                    (norm1): BatchNorm2d(480, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(480, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer9): _DenseLayer(
                    (norm1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer10): _DenseLayer(
                    (norm1): BatchNorm2d(544, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(544, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer11): _DenseLayer(
                    (norm1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(576, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer12): _DenseLayer(
                    (norm1): BatchNorm2d(608, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(608, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer13): _DenseLayer(
                    (norm1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(640, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer14): _DenseLayer(
                    (norm1): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(672, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer15): _DenseLayer(
                    (norm1): BatchNorm2d(704, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(704, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer16): _DenseLayer(
                    (norm1): BatchNorm2d(736, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(736, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer17): _DenseLayer(
                    (norm1): BatchNorm2d(768, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(768, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer18): _DenseLayer(
                    (norm1): BatchNorm2d(800, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(800, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer19): _DenseLayer(
                    (norm1): BatchNorm2d(832, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(832, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer20): _DenseLayer(
                    (norm1): BatchNorm2d(864, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(864, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer21): _DenseLayer(
                    (norm1): BatchNorm2d(896, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(896, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer22): _DenseLayer(
                    (norm1): BatchNorm2d(928, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(928, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer23): _DenseLayer(
                    (norm1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(960, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer24): _DenseLayer(
                    (norm1): BatchNorm2d(992, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(992, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                )
                (transition3): _Transition(
                  (norm): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                  (relu): ReLU(inplace=True)
                  (conv): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)
                  (pool): AvgPool2d(kernel_size=2, stride=2, padding=0)
                )
                (denseblock4): _DenseBlock(
                  (denselayer1): _DenseLayer(
                    (norm1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer2): _DenseLayer(
                    (norm1): BatchNorm2d(544, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(544, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer3): _DenseLayer(
                    (norm1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(576, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer4): _DenseLayer(
                    (norm1): BatchNorm2d(608, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(608, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer5): _DenseLayer(
                    (norm1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(640, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer6): _DenseLayer(
                    (norm1): BatchNorm2d(672, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(672, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer7): _DenseLayer(
                    (norm1): BatchNorm2d(704, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(704, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer8): _DenseLayer(
                    (norm1): BatchNorm2d(736, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(736, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer9): _DenseLayer(
                    (norm1): BatchNorm2d(768, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(768, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer10): _DenseLayer(
                    (norm1): BatchNorm2d(800, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(800, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer11): _DenseLayer(
                    (norm1): BatchNorm2d(832, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(832, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer12): _DenseLayer(
                    (norm1): BatchNorm2d(864, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(864, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer13): _DenseLayer(
                    (norm1): BatchNorm2d(896, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(896, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer14): _DenseLayer(
                    (norm1): BatchNorm2d(928, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(928, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer15): _DenseLayer(
                    (norm1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(960, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                  (denselayer16): _DenseLayer(
                    (norm1): BatchNorm2d(992, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu1): ReLU(inplace=True)
                    (conv1): Conv2d(992, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)
                    (norm2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
                    (relu2): ReLU(inplace=True)
                    (conv2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
                  )
                )
                (norm5): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
              )),
             ('last_linear',
              Sequential(
                (0): Linear(in_features=1024, out_features=3, bias=True)
              ))])
</code></pre>