How to access different layers of a sequential model?

Hi all…I have a deep sequential CNN model consisting of Conv, relu, batchNorm, maxPool stacked one after another. I was thinking if I could access the layers(like indexing) through a loop or by some other mechanism, so that I can perform some different operation to different layers.

Thank you

Hi @Kai123

To get an item of the Sequential use square brackets. You can even slice Sequential

import torch.nn as nn

my_model = nn.Sequential(nn.Identity(), nn.Identity(), nn.Identity())