Finally, the other issue as you said if do not know the names, or for some reason, we don’t want to define the hook one at a time. So, the solution to this would be to use net.children() which gives an iterator over the layers in net:
>>> net.children()
<generator object Module.children at 0x7f411dad15e8>
>>> for layer in net.children():
...    print(layer)

Conv2d(3, 4, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
Conv2d(4, 8, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
Linear(in_features=512, out_features=256, bias=True)
Linear(in_features=256, out_features=10, bias=True)

So, we can define the hook for each layer in a loop (print_tensor_props is defined in the previous post):
>>> for layer in net.children():
...    layer.register_forward_hook(print_tensor_props)
... 
<torch.utils.hooks.RemovableHandle object at 0x7f4163193208>
<torch.utils.hooks.RemovableHandle object at 0x7f416140e7b8>
<torch.utils.hooks.RemovableHandle object at 0x7f4163193208>
<torch.utils.hooks.RemovableHandle object at 0x7f416140e7b8>

## testing: 
>>> out = net(x)
torch.Size([5, 3, 8, 8]) => torch.Size([5, 4, 8, 8])
torch.Size([5, 4, 8, 8]) => torch.Size([5, 8, 8, 8])
torch.Size([5, 512]) => torch.Size([5, 256])
torch.Size([5, 256]) => torch.Size([5, 10])