Access intermediate tensors of a model

Given a model and an input tensor, how do I access all the intermediate tensors? I have a network with multiple parallel (residual) branches in it. Are there any restrictions with such networks?

Appreciate your inputs, thanks!

Hi,

The simplest way to access such elements is usually to just access them during the foward pass of your network.

1 Like

@albanD, thanks for your response. I have a nested structure and additionally I am worried to put code in the forward function.

I was hoping if I can use some of the torch.jit utilities for this and if there is a good example that I can use. If I am able to construct a network graph then it would help me with handling different residual branches as well.

Appreciate some pointers on this one. Thanks!

Why are you worried about putting code in the forward function?
One of the main advantage of pytorch is actually that the forward is called at every iteration and you can do arbitrary code in there :slight_smile: