Remove a whole block of layers

Hi everyone,
I’m running the Densenet121 Model. After loading weights. I have 2 unwanted blocks model.features.denseblock4 and model.features.transition3. I’m trying to remove these 2 blocks of layers. Could any please tell me the way to do it? I’ll very appreciate it.

An easy way would be to replace them with nn.Idenity layers (assuming their input shape matches their output shape). Alternatively, you could also override the forward in a custom module and skip these layers directly.

1 Like

Excuse my late reply. Thank you so much!