Visualise sequential model feature maps

I am extracting the feature maps from every activation layer after convolutions, and I am struggling to visualise the output:

def get_fmaps(input, model):
    fmaps = []
    for i in [0, 3, 6, 8, 10]:  ##conv2d index
        out = []
        for x in range(2,i+1):
        fmaps.append(model.features[i+1].forward(out[i])) ##output after activation function
    return fmaps

I’m not sure if this is the correct way to do it, but once I have returned fmaps, how do I visualise the feature maps?

I think the better way would be to use forward hooks as explained in this post. Your current approach could break, if you are using functional API calls inside the forward and you would need to add them.

Once you have the tensors, you could visualize them via e.g. matplotlib.

Thank you for the link.
From what I can tell, in the example you are calling them by name I.e “fc2”, is there a way instead to call by indexing, since I know which layers are Conv2d, and I would like to access every conv2d output

Something like this:

The get_activation method is just used for convenience to be able to pass names to it and you can use any name you want.
The actual registered hook is defined in the hook method inside get_activation.