Layer-wise output

I’m having a PyTorch densenet model for classification purpose.In order to get layer wise output for an image,I can make a submodel upto the relevant layer and donthe inferencenupto that layer.
PyTorch allow me to create a submodel with the required layer,if it is a child.
In case I have a child of block which having some convolution layers.How can I add the particular layer within the child block?or anyways to get output of a layer inside a child-block.
Eg.There are layers inside a denseblock,if I want to do the inference upto a particular layer within the dense block.

To get intermediate outputs you can use hooks.
Here is a tutorial

Yes I did use them,but it dumps the funcyion called in forward function.Is there alternate ways to dunps the output of layers within a child?

You can modify the sourcecode of the network to return any value that you need. In principle hooks are the way to get intermidiate outputs not modifying the network.
Another way is to save it in self during forward.