How to find the name of layers in preloaded torchvision models?
I'm trying to use GradCAM with a Deeplabv3 resnet50 model preloaded from torchvision, but in Captum I need to say the name of the layer (of type nn.module). I can't find any documentation for how this is done, does anyone possibly have any ideas of how to get the name of the final ReLu layer?
Thanks in advance!

You can have a look at its representation and get an idea of where it's located by simply printing it:
&gt;&gt;&gt; model = torchvision.models.segmentation.deeplabv3_resnet50()
&gt;&gt;&gt; model
DeepLabV3(
  (backbone): IntermediateLayerGetter(
    (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(
        ...

To get the actual exact name of the layer you can loop over the modules with named_modules and only pick the nn.ReLU layers:
&gt;&gt;&gt; relus = [name for name, module in model.named_modules() if isinstance(module, nn.ReLU)]

&gt;&gt;&gt; relus
['backbone.relu',
 'backbone.layer1.0.relu',
 'backbone.layer1.1.relu',
 'backbone.layer1.2.relu',
 'backbone.layer2.0.relu',
 'backbone.layer2.1.relu',
 'backbone.layer2.2.relu',
 'backbone.layer2.3.relu',
 'backbone.layer3.0.relu',
 'backbone.layer3.1.relu',
 'backbone.layer3.2.relu',
 'backbone.layer3.3.relu',
 'backbone.layer3.4.relu',
 'backbone.layer3.5.relu',
 'backbone.layer4.0.relu',
 'backbone.layer4.1.relu',
 'backbone.layer4.2.relu',
 'classifier.0.convs.0.2',
 'classifier.0.convs.1.2',
 'classifier.0.convs.2.2',
 'classifier.0.convs.3.2',
 'classifier.0.convs.4.3',
 'classifier.0.project.2',
 'classifier.3']

Then pick the last one:
&gt;&gt;&gt; relus[-1]
'classifier.3'

