You could iterate all modules, check if the current module is an nn.Conv2d
modules, and register the hook using its name.
Here is a dummy code snippet for resnet:
model = models.resnet50()
for name, module in model.named_modules():
if isinstance(module, nn.Conv2d):
module.register_forward_hook(get_activation(name))
Note that you are registering the hook in the module to visualize the output activation.
The weight
and bias
parameter don’t give you the activation.
Let me know, if I misunderstood your use case.