The code looks alright and you can check the results by accessing the dict after a forward pass where the activations would be stored.
To compare your approach you would also directly access the desired layers and register the hooks e.g. via model.layer4.register_forward_hook(...).