How to add activation histogram in tensorboard?

Currently this is how i add a histogram for my layer’s weights:

writer.add_histogram(f'Classifier/p/Weights',model.fc[-1].weight, epoch)

How can I add the activation histogram in a similar manner?

My assumption would be that I have to add it in the forward function after it passes through the relevant ReLU, softmax, etc. However what do I do when i don’t have access to the forward function directly (model imported from torchvision.models, or defined as a nn.Sequential).

Example of what i’m looking for taken from


You can use forward hooks to get the internal activation as described here.