Accessing layers inside Bottleneck module of pretrained ResNet model

I was trying to load the pretrained ResNet-50 model and then seeing the layers available using the code:

curNetwork = models.resnet50(pretrained=True)
for child in curNetwork.children():
print(child)

One of the children I get is:

Bottleneck(
(conv1): Conv2d (256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
(conv2): Conv2d (64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
(conv3): Conv2d (64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)
(bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
(relu): ReLU(inplace)
)

How can I access the weights of the individual layers within this Bottleneck layers, by name?

Thanks!

If your child is the current Bottleneck layer, you could use child.conv1.weight, child.bn1.weight, etc.

2 Likes