To get a middle activation map

I was trying to visualize a layer of pretrained model but when I am trying to get the middle layer of model like alexnet then I am getting 2d tensor with one column but I am expecting a feature map with 3 dimensions.

To get this output I am replacing all the layer that follows the desired layer with following layer

class Identity(nn.Module):
    def __init__(self):
         super()
   def forward(self, x):
        return x

An easier way to get the intermediate activations would be forward hooks as described here.

I think you are seeing a flattened tensor, since you are only replacing the modules, while the functional API call in the forward (such as x = x.view(x.size(0), -1)) are still used.

1 Like

Thanks for the answer