How to debug forward method of your custom model head?

I am pretty new to pytorch and neural networks. So far have only worked with pretrained model in pytorch. I want to implement a cusstom model to my already existing pipeline. I have found deeplabv3 plus implementation and trying to modify it for my pipeline. I have following implementation and I am getting this error.

class DeepLabHeadV3Plus(nn.Module):
    def __init__(self, in_channels, low_level_channels, num_classes, aspp_dilate=[12, 24, 36]):
        super(DeepLabHeadV3Plus, self).__init__()
        self.project = nn.Sequential( 
            nn.Conv2d(low_level_channels, 48, 1, bias=False),

        self.aspp = ASPP(in_channels, aspp_dilate)

        self.classifier = nn.Sequential(
            nn.Conv2d(304, 256, 3, padding=1, bias=False),
            nn.Conv2d(256, num_classes, 1)

    def forward(self, feature):
        low_level_feature = self.project( feature['low_level'] )
        output_feature = self.aspp(feature['out'])
        output_feature = F.interpolate(output_feature, size=low_level_feature.shape[2:], mode='bilinear', align_corners=False)
        return self.classifier( [ low_level_feature, output_feature ], dim=1 ) )

My error is:

low_level_feature = self.project( feature[‘low_level’] )
IndexError: too many indices for tensor of dimension 4

I get it that I have tensor of size 04 but I am trying to dimension it an extra. but how can I get rid of it. My dataloader has shape of tensor (B,C,H,W) = (32, 3, 320, 320). Any suggestion or help would be a lot of help.

you can stick in a pdb.set_trace() in forward to debug interactively. Of course don’t forget to import pdb.

def forward(self, feature):
        low_level_feature = self.project( feature['low_level'] )

from the error message, it seems your dataloader is giving you tensors with more than 4 dimensions. I would recommend double-checking your input loading and conversion.