tom:

for name, m in model.named_modules()


I tried the way you have specified and got below output
bodyModel.model.0.0   Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
bodyModel.model.0.1   ReLU(inplace)
bodyModel.model.0.2   Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
bodyModel.model.0.3   ReLU(inplace)
bodyModel.model.0.4   MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
bodyModel.model.0.5   Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
but now when I try to use say ''bodyModel.model.0.5" as attribute name for registering hook it gives me error as the attribute is invalid.
model.bodyModel.model.0.21.register_forward_hook(get_activation('bodyModel.model.0.21'))