Thank you for the reply sir. I tried the model on my cpu(8GB RAM, Windows):
Capture11306×73 5.17 KB
It states that it doesn’t have enough memory to allocate(Asks me to buy new RAM  ).I apologize for the blurred out image. The error starts in line 137 of new_resnet24.py, c2 = self.inconv2(l2) . I suspect, the same thing might be happening on Google Colab(12GB RAM). I have tried all kinds of methods to obtain  layer2  and  layer4 :

Forward hooks
Using a list of features of the model and then looping over the children of resnet50
Reducing the size of the dataset to reduce computational cost

None of the above methods have worked. Each time the program ended with ‘^C’ . If you can suggest  some more  methods to obtain the activations of the intermediate layers, I would be grateful.
PS: The code snippet in the original question is a part of the  forward()  method of ResNet in new_resnet24.py in this repository