Saving layer activations

I am trying to save activations of one of the final conv layers of a resnet101. I intend to visualize these using t_SNE. I am new to this stuff so would be really grateful if someone could help.

This is the layer I want to save :
layer = list(learn.model.modules())[-15]

This is the hook on the layer from above :
activation = {}
def get_activation(name):
def hook(model, input, output):
activation[name] = output.detach()
return hook
hook1 = layer.register_forward_hook(get_activation(layer))

This however keeps giving me error ‘NoneType’ object is not callable :frowning_face:

My understanding is that these predictions should generate activations that i can then visualize. Right ? Thank you for your time

I’m going to assume you’re using fastai v2 here, let me know if you are not.

In v2 you’re get_preds should look like: learn.get_preds(dl=data.valid)

No I am not. I see I have asked this question at the wrong place. Apologies for that

All good! In general it’s best to specify your version in the question along with creating your thread in #fastai-users (I changed it for you this time :wink: )