-
state_dict():打印model中所有參數(shù)名。 -
named_parameters():打印model中所有參數(shù)名及具體的值(包括通過繼承得到的父類中的參數(shù))。
例如:
for i in vgg16.state_dict():
print(i)
--->:
features.0.weight
features.0.bias
features.2.weight
features.2.bias
features.5.weight
features.5.bias
features.7.weight
features.7.bias
features.10.weight
features.10.bias
features.12.weight
features.12.bias
features.14.weight
features.14.bias
features.17.weight
features.17.bias
features.19.weight
features.19.bias
features.21.weight
features.21.bias
features.24.weight
features.24.bias
features.26.weight
features.26.bias
features.28.weight
features.28.bias
classifier.0.weight
classifier.0.bias
classifier.2.weight
classifier.2.bias
for i in vgg16.named_parameters():
print(i)
--->:
('features.0.weight', Parameter containing:
tensor([[[[ 0.0127, 0.0487, -0.0666],
[-0.0592, -0.0727, -0.0318],
[ 0.0827, -0.0082, 0.0370]],
[[ 0.0085, 0.0518, -0.0087],
[-0.0441, 0.0153, -0.0195],
[-0.0196, 0.0171, 0.0646]],
[[ 0.0397, 0.0833, -0.0057],
[-0.0172, -0.0321, 0.0299],
[-0.0123, -0.0519, 0.0072]]],
[[[-0.0123, -0.0609, 0.0419],
[ 0.0354, -0.0212, 0.0122],
[ 0.1548, 0.0201, 0.0246]],
[[ 0.0438, -0.0392, 0.0622],
[-0.0725, -0.0245, -0.0494],
[-0.0317, -0.0456, -0.0172]],
[[-0.0294, -0.0741, -0.1305],
[-0.0059, 0.0049, 0.0335],
[ 0.0149, -0.1573, -0.0210]]],
[[[ 0.1935, 0.0101, 0.0346],
[-0.0562, 0.0544, -0.0360],
[ 0.0240, 0.0016, 0.0440]],
[[-0.0224, -0.0113, -0.0398],
[ 0.0704, -0.0365, 0.0653],
[-0.0386, 0.0000, -0.0737]],
[[-0.0986, -0.1198, 0.0811],
[-0.0682, -0.1098, -0.0657],
[-0.0464, -0.0666, 0.0243]]],
...,
[[[ 0.0326, 0.0028, 0.1384],
[ 0.0115, 0.0783, -0.0807],
[ 0.0495, 0.0720, 0.0003]],
[[-0.0928, 0.0867, -0.0458],
[-0.0947, -0.1125, 0.0175],
[-0.0481, -0.0281, 0.0382]],
[[ 0.0915, -0.0230, 0.0183],
[-0.0087, 0.0531, 0.0239],
[ 0.0055, -0.0206, -0.0359]]],
[[[-0.0474, -0.1023, -0.0838],
[-0.0141, 0.0862, 0.0237],
[-0.0291, 0.0596, 0.1063]],
[[ 0.0717, 0.0451, 0.0128],
[-0.0125, 0.0393, -0.0334],
[-0.0251, 0.0019, 0.0190]],
[[ 0.0889, -0.0214, -0.0017],
[-0.1193, 0.0661, -0.0899],
[ 0.1141, 0.0078, -0.1057]]],
[[[ 0.0543, 0.0077, 0.0896],
[ 0.0599, -0.0046, -0.1301],
[ 0.0571, 0.0428, 0.0043]],
[[ 0.0225, -0.0695, 0.0255],
[ 0.0152, -0.0052, 0.0053],
[ 0.0403, -0.0195, -0.1257]],
[[-0.0477, 0.0524, 0.0556],
[-0.0164, 0.0376, -0.0557],
[-0.0701, 0.0206, -0.0171]]]], device='cuda:0', requires_grad=True))
('features.0.bias', Parameter containing:
tensor([-0.0094, 0.0380, 0.0197, -0.0335, 0.0608, 0.0188, 0.0016, -0.0594,
0.0013, 0.0113, -0.0049, -0.0264, 0.0162, -0.0051, -0.0509, 0.0386,
-0.0312, 0.0331, -0.0095, -0.0071, -0.0047, -0.0243, 0.0334, 0.0168,
0.0079, -0.0006, 0.0290, -0.0035, -0.0096, 0.0210, 0.0242, -0.0074,
0.0257, -0.0024, -0.0203, 0.0212, -0.0031, 0.0023, -0.0011, 0.0172,
-0.0118, -0.0020, 0.0098, -0.0351, -0.0042, -0.0016, 0.0154, -0.0218,
0.0051, 0.0058, 0.0003, 0.0106, -0.0525, 0.0591, 0.0082, -0.0209,
0.0151, 0.0025, 0.0030, 0.0288, 0.0479, 0.0343, -0.0237, -0.0011],
device='cuda:0', requires_grad=True))
...