How to get the intermediate layers output 'model.feature_list(input)' for any customized CNN like we do it in a pretrained ResNet34?

I am using Resnet34 pre-trained model and trying to get the intermediate layer outputs by doing model.feature_list(input) (input.shape = [2,3,32,32]) the outputs are of shape [2, 64, 32, 32], [2, 64, 32, 32], [2, 128 16 16], [2,256,8, 8], and [2, 512, 4, 4].

How can I write a new customized CNN code which would respond to a “model.feature_list(input)” command and provides the intermediate layer outputs.

You could pass through each individual block. Something like this

x1 = model.layer1(input)
x2 = model.layer2(x1)
x3 = model.layer3(x2)
x4 = model.layer4(x3)

etc. Then return the intermediate values.