I’m trying to register a forward hook function to the last conv layer of my network. I first printed out the names of the modules via:
for name, _ in model.named_modules():
    print(name)

Which gave me "0.conv" as the module name. However, when I tried to do the following, the above error was triggered by line 2:
def hook_feature(module, in_, out_):
    features.append(out_.cpu().data.numpy())

model._modules.get("0.conv").register_forward_hook(hook_feature)

What am I doing wrong and how do I fix it? Thanks!