pytorch获取网络的层数和每层的名字

#创建自己的网络
import models
model = models.__dict__["resnet50"](pretrained=True)

for index ,(name, param) in enumerate(model.named_parameters()):
    print( str(index) + " " +name)

结果如下:

0 conv1.weight
1 bn1.weight
2 bn1.bias
3 layer1.0.conv1.weight
4 layer1.0.bn1.weight
5 layer1.0.bn1.bias
6 layer1.0.conv2.weight
7 layer1.0.bn2.weight
8 layer1.0.bn2.bias
9 layer1.0.conv3.weight

你可能感兴趣的:(python,人工智能,计算机视觉,深度学习,神经网络)