How to loop in a model and extract the weight for bn layers?

Hi,

how to loop in a model and extract the weight for bn layers?
The only way I can see to get the weight of a layer is by model.bn1.weight.data

however, in the loop, it will have some parameter contains the name for the layer i.e. n
model.n.weight.data

but this way doesn’t work, as the model doesn’t have contributed to n.

Thank you

you can check the type of the layer.

for example: if type(model.n) == torch.nn.BatchNorm2d: