Pytorch之parameters的使用

1.预构建网络

class Net(nn.Module):
  def __init__(self):
    super(Net, self).__init__()
    # 1 input image channel, 6 output channels, 5*5 square convolution
    # kernel

    self.conv1 = nn.Conv2d(1, 6, 5)
    self.conv2 = nn.Conv2d(6, 16, 5)
    # an affine operation: y = Wx + b
    self.fc1 = nn.Linear(16 * 5 * 5, 120)
    self.fc2 = nn.Linear(120, 84)
    self.fc3 = nn.Linear(84, 10)

  def forward(self, x):
    # max pooling over a (2, 2) window
    x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
    # If size is a square you can only specify a single number
    x = F.max_pool2d(F.relu(self.conv2(x)), 2)
    x = x.view(-1, self.num_flat_features(x))
    x = F.relu(self.fc1(x))
    x = F.relu(self.fc2(x))
    x = self.fc3(x)
    return x

  def num_flat_features(self, x):
    size = x.size()[1:] # all dimensions except the batch dimension
    num_features = 1
    for s in size:
      num_features *= s
    return num_features

net = Net()

网络结构

Net(
 (conv1): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1))
 (conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))
 (fc1): Linear(in_features=400, out_features=120, bias=True)
 (fc2): Linear(in_features=120, out_features=84, bias=True)
 (fc3): Linear(in_features=84, out_features=10, bias=True)
)

2.net.parameters()

构建好神经网络后,网络的参数都保存在parameters()函数当中

print(net.parameters())

输出 <generator object Module.parameters at 0x0000000003161200>

para = list(net.parameters())
print(para)
#len返回列表项个数
print(len(para))

输出

[Parameter containing:
tensor([[[[-0.0596, 0.1908, 0.1831, 0.0542, -0.0283],
     [-0.0542, -0.1680, 0.1566, 0.1036, -0.1756],
     [-0.1437, 0.0083, 0.0871, 0.1549, 0.1556],
     [ 0.1360, 0.0171, 0.1034, -0.1548, -0.1343],
     [-0.0978, -0.1803, -0.0701, -0.0377, 0.0290]]],

    [[[-0.1020, 0.0862, -0.1227, -0.1742, 0.1510],
     [ 0.0728, 0.1725, 0.0352, 0.1579, 0.0367],
     [ 0.0862, -0.0995, 0.1276, -0.1895, -0.1346],
     [ 0.1938, 0.1387, -0.1983, -0.1015, -0.0740],
     [-0.0248, -0.0546, 0.0849, 0.1510, -0.0066]]],

    [[[ 0.1333, 0.0300, 0.0969, -0.0295, 0.0879],
     [ 0.1216, -0.0864, 0.0259, 0.0157, -0.1330],
     [-0.1873, 0.1309, 0.1947, 0.1886, 0.1944],
     [-0.0647, 0.0957, 0.1592, 0.1894, 0.1862],
     [ 0.0896, 0.1287, -0.0650, 0.0684, 0.1182]]],

    [[[-0.0816, 0.0968, 0.1259, -0.1124, -0.0864],
     [-0.0450, 0.0737, 0.0483, 0.1180, -0.0933],
     [-0.0925, -0.0549, 0.1191, 0.0165, 0.1369],
     [-0.1771, -0.1937, 0.1542, 0.1105, 0.1572],
     [ 0.1163, -0.1577, 0.1426, 0.0431, -0.0362]]],

    [[[-0.0675, -0.1039, 0.0762, -0.1798, 0.0071],
     [-0.1794, 0.1942, 0.0540, 0.1887, 0.1413],
     [ 0.1366, 0.0682, 0.1230, 0.0184, -0.0980],
     [-0.1613, 0.1225, -0.0734, 0.1938, 0.1919],
     [ 0.1745, -0.1550, 0.0663, 0.0044, -0.0538]]],

    [[[-0.0926, 0.1146, 0.1008, 0.1644, 0.1046],
     [-0.1230, 0.0080, 0.0198, -0.1216, -0.1942],
     [ 0.0327, 0.0205, 0.0862, -0.1714, 0.0955],
     [ 0.0358, -0.1350, 0.1387, -0.1365, -0.1600],
     [ 0.0368, -0.1323, -0.0127, 0.0917, -0.1892]]]],
    requires_grad=True), Parameter containing:
tensor([-0.0229, -0.1387, -0.1571, -0.0381, -0.1559, 0.0946], requires_grad=True), Parameter containing:
tensor([[[[-0.0497, -0.0356, -0.0272, -0.0519, 0.0451],
     [-0.0247, 0.0228, 0.0705, -0.0341, -0.0454],
     [ 0.0129, -0.0385, 0.0682, -0.0613, 0.0497],
     [-0.0394, 0.0218, -0.0056, 0.0204, -0.0668],
     [ 0.0469, 0.0649, -0.0470, 0.0138, -0.0686]],

     [[ 0.0647, 0.0554, -0.0220, -0.0295, -0.0145],
     [ 0.0500, -0.0026, 0.0545, 0.0415, 0.0020],
     [-0.0802, 0.0742, -0.0291, 0.0679, -0.0657],
     [ 0.0309, 0.0729, -0.0158, -0.0495, -0.0220],
     [-0.0433, 0.0440, -0.0485, 0.0478, 0.0618]],

     [[ 0.0523, -0.0072, -0.0786, 0.0569, 0.0334],
     [-0.0254, -0.0043, -0.0113, 0.0755, -0.0590],
     [ 0.0113, -0.0170, 0.0318, -0.0764, -0.0210],
     [-0.0203, -0.0273, 0.0634, 0.0380, 0.0014],
     [-0.0112, 0.0555, -0.0129, -0.0395, 0.0624]],

     [[ 0.0387, 0.0189, -0.0007, -0.0604, 0.0114],
     [ 0.0481, 0.0551, 0.0182, 0.0474, 0.0390],
     [ 0.0152, -0.0106, -0.0381, -0.0630, -0.0645],
     [ 0.0092, -0.0295, -0.0616, 0.0571, 0.0562],
     [ 0.0418, -0.0372, 0.0269, 0.0109, -0.0758]],

     [[-0.0751, -0.0610, 0.0269, -0.0331, -0.0193],
     [ 0.0577, 0.0430, -0.0201, -0.0017, -0.0408],
     [-0.0590, -0.0148, 0.0790, 0.0575, -0.0786],
     [ 0.0168, 0.0335, 0.0170, -0.0792, 0.0344],
     [-0.0738, 0.0193, -0.0732, -0.0666, -0.0734]],

     [[ 0.0154, 0.0712, 0.0540, -0.0429, 0.0573],
     [-0.0423, 0.0424, -0.0488, 0.0317, 0.0808],
     [ 0.0605, 0.0324, -0.0020, -0.0538, 0.0664],
     [ 0.0243, -0.0452, 0.0070, -0.0287, -0.0476],
     [ 0.0087, 0.0561, -0.0076, -0.0391, 0.0795]]],

    [[[ 0.0773, 0.0748, -0.0133, 0.0651, 0.0659],
     [ 0.0254, 0.0222, 0.0017, -0.0722, 0.0667],
     [ 0.0357, -0.0677, 0.0085, -0.0005, -0.0313],
     [ 0.0672, -0.0359, -0.0243, -0.0811, -0.0726],
     [ 0.0011, 0.0226, 0.0278, -0.0615, -0.0410]],

     [[ 0.0202, 0.0519, 0.0527, -0.0086, -0.0683],
     [ 0.0694, 0.0434, 0.0746, 0.0754, 0.0073],
     [ 0.0036, -0.0692, -0.0732, -0.0250, -0.0470],
     [-0.0669, 0.0609, 0.0649, -0.0158, 0.0189],
     [-0.0564, 0.0370, 0.0464, -0.0530, 0.0487]],

     [[ 0.0068, 0.0722, 0.0629, -0.0214, 0.0673],
     [-0.0384, 0.0799, -0.0350, 0.0816, 0.0586],
     [-0.0111, 0.0696, 0.0145, -0.0397, -0.0784],
     [-0.0120, 0.0555, 0.0021, -0.0494, -0.0344],
     [-0.0335, 0.0502, -0.0490, -0.0701, 0.0135]],

     [[-0.0365, 0.0733, 0.0610, 0.0028, 0.0292],
     [ 0.0552, -0.0674, 0.0176, -0.0131, 0.0688],
     [ 0.0147, -0.0432, 0.0473, -0.0231, -0.0314],
     [-0.0194, 0.0508, -0.0475, 0.0599, 0.0286],
     [ 0.0055, 0.0287, -0.0391, -0.0543, 0.0778]],

     [[-0.0241, -0.0322, 0.0704, -0.0758, -0.0562],
     [-0.0675, -0.0265, -0.0444, -0.0370, 0.0581],
     [-0.0577, 0.0462, 0.0165, 0.0146, -0.0317],
     [ 0.0047, 0.0666, -0.0365, 0.0749, 0.0677],
     [ 0.0557, 0.0098, 0.0451, 0.0306, -0.0628]],

     [[ 0.0529, 0.0167, 0.0501, 0.0679, 0.0505],
     [-0.0006, -0.0432, -0.0128, 0.0794, -0.0794],
     [ 0.0016, -0.0504, -0.0252, 0.0266, 0.0635],
     [ 0.0305, -0.0807, -0.0236, -0.0810, -0.0010],
     [-0.0423, -0.0285, -0.0559, 0.0560, 0.0796]]],

    [[[-0.0504, 0.0634, 0.0504, -0.0440, 0.0425],
     [ 0.0517, -0.0268, -0.0517, 0.0646, 0.0693],
     [ 0.0566, 0.0194, 0.0426, -0.0787, 0.0163],
     [-0.0661, -0.0457, 0.0691, -0.0058, -0.0073],
     [ 0.0794, 0.0645, 0.0367, -0.0625, -0.0731]],

     [[ 0.0190, 0.0393, 0.0145, -0.0073, 0.0478],
     [ 0.0405, 0.0038, -0.0349, -0.0022, 0.0202],
     [ 0.0346, -0.0622, 0.0194, -0.0151, 0.0220],
     [ 0.0002, -0.0663, 0.0730, -0.0462, -0.0182],
     [ 0.0311, -0.0079, 0.0720, 0.0517, -0.0601]],

     [[-0.0039, -0.0102, -0.0599, -0.0220, -0.0467],
     [-0.0495, -0.0265, 0.0484, 0.0497, 0.0090],
     [-0.0260, 0.0256, 0.0476, -0.0585, 0.0411],
     [-0.0505, -0.0447, -0.0002, -0.0121, -0.0170],
     [ 0.0400, 0.0457, 0.0709, 0.0195, 0.0762]],

     [[ 0.0732, -0.0100, 0.0115, -0.0046, -0.0133],
     [ 0.0333, -0.0065, 0.0115, 0.0057, 0.0370],
     [ 0.0328, -0.0513, 0.0648, 0.0588, 0.0230],
     [ 0.0154, 0.0261, 0.0579, 0.0118, 0.0050],
     [ 0.0089, 0.0468, -0.0763, -0.0314, 0.0676]],

     [[ 0.0428, -0.0646, -0.0339, 0.0185, -0.0042],
     [-0.0480, 0.0639, -0.0366, -0.0537, 0.0241],
     [-0.0572, 0.0309, -0.0761, 0.0227, -0.0385],
     [-0.0546, -0.0338, 0.0277, -0.0650, -0.0081],
     [ 0.0690, -0.0083, 0.0295, 0.0088, 0.0360]],

     [[ 0.0514, 0.0622, -0.0556, -0.0048, -0.0279],
     [ 0.0112, -0.0413, -0.0483, 0.0166, 0.0690],
     [-0.0433, 0.0410, -0.0335, -0.0458, -0.0055],
     [ 0.0229, 0.0289, 0.0695, 0.0574, 0.0075],
     [ 0.0651, -0.0337, -0.0130, -0.0381, 0.0272]]],

    ...,

    [[[-0.0538, 0.0321, 0.0302, 0.0222, -0.0062],
     [ 0.0050, -0.0461, 0.0084, -0.0448, -0.0604],
     [-0.0457, 0.0455, -0.0773, -0.0437, 0.0446],
     [ 0.0691, 0.0390, -0.0040, 0.0035, -0.0133],
     [ 0.0545, 0.0517, -0.0067, 0.0314, -0.0448]],

     [[ 0.0029, -0.0675, -0.0254, -0.0168, -0.0563],
     [ 0.0163, -0.0621, -0.0561, -0.0151, -0.0306],
     [-0.0021, 0.0389, -0.0429, 0.0778, 0.0451],
     [-0.0578, 0.0123, 0.0049, -0.0728, -0.0408],
     [ 0.0722, 0.0388, 0.0177, 0.0526, -0.0291]],

     [[ 0.0369, 0.0502, 0.0646, 0.0388, -0.0091],
     [ 0.0066, 0.0501, 0.0114, 0.0243, -0.0455],
     [ 0.0494, 0.0495, -0.0257, 0.0165, -0.0024],
     [-0.0476, -0.0552, 0.0029, -0.0813, 0.0698],
     [-0.0704, -0.0590, -0.0641, 0.0284, 0.0578]],

     [[ 0.0180, 0.0794, -0.0090, -0.0081, 0.0570],
     [-0.0529, 0.0517, 0.0045, -0.0580, -0.0192],
     [-0.0289, 0.0261, 0.0107, 0.0180, -0.0062],
     [-0.0162, 0.0607, 0.0154, 0.0450, 0.0694],
     [ 0.0324, 0.0418, -0.0199, -0.0357, 0.0104]],

     [[ 0.0525, -0.0401, 0.0803, -0.0453, -0.0534],
     [ 0.0628, 0.0120, 0.0147, 0.0294, -0.0351],
     [ 0.0773, -0.0587, -0.0713, 0.0125, -0.0125],
     [-0.0288, -0.0623, 0.0547, 0.0390, -0.0603],
     [ 0.0105, -0.0003, -0.0773, 0.0167, 0.0386]],

     [[ 0.0721, -0.0047, 0.0238, 0.0489, 0.0183],
     [-0.0127, -0.0090, -0.0588, 0.0641, 0.0460],
     [-0.0194, -0.0753, -0.0349, 0.0186, 0.0156],
     [ 0.0248, -0.0801, -0.0794, 0.0811, 0.0644],
     [-0.0415, 0.0127, -0.0120, -0.0724, -0.0800]]],

    [[[-0.0781, 0.0279, 0.0056, -0.0164, -0.0423],
     [ 0.0446, 0.0030, 0.0590, 0.0276, -0.0720],
     [ 0.0647, -0.0414, -0.0306, -0.0477, 0.0041],
     [-0.0647, 0.0124, 0.0166, -0.0592, 0.0164],
     [ 0.0789, -0.0673, -0.0583, 0.0493, 0.0306]],

     [[-0.0105, 0.0707, -0.0790, -0.0334, 0.0620],
     [ 0.0095, 0.0763, 0.0055, -0.0716, -0.0078],
     [ 0.0141, -0.0645, 0.0380, -0.0282, -0.0557],
     [ 0.0489, 0.0073, 0.0203, 0.0568, -0.0352],
     [-0.0299, 0.0681, -0.0300, 0.0178, -0.0101]],

     [[ 0.0401, -0.0572, 0.0219, 0.0427, 0.0276],
     [-0.0683, 0.0192, 0.0689, 0.0217, -0.0365],
     [-0.0140, -0.0361, -0.0562, 0.0528, 0.0029],
     [ 0.0213, 0.0464, 0.0525, -0.0804, 0.0599],
     [ 0.0770, -0.0657, 0.0655, 0.0741, 0.0462]],

     [[ 0.0479, 0.0648, -0.0050, 0.0530, -0.0746],
     [-0.0671, 0.0635, 0.0360, -0.0642, -0.0573],
     [ 0.0176, -0.0783, -0.0781, -0.0027, 0.0405],
     [ 0.0057, -0.0685, 0.0673, 0.0697, -0.0792],
     [-0.0449, -0.0773, -0.0756, -0.0524, 0.0378]],

     [[ 0.0201, 0.0407, -0.0442, -0.0007, -0.0174],
     [-0.0779, 0.0032, -0.0650, 0.0172, -0.0081],
     [ 0.0796, -0.0781, -0.0364, 0.0141, -0.0198],
     [ 0.0270, 0.0519, -0.0578, -0.0515, 0.0225],
     [ 0.0212, 0.0231, 0.0071, 0.0190, 0.0285]],

     [[ 0.0311, 0.0148, 0.0181, 0.0617, 0.0037],
     [ 0.0754, -0.0596, -0.0498, 0.0388, -0.0612],
     [ 0.0318, -0.0068, -0.0725, -0.0671, -0.0531],
     [ 0.0446, 0.0793, 0.0193, 0.0033, -0.0685],
     [ 0.0426, 0.0017, 0.0477, 0.0556, 0.0341]]],

    [[[ 0.0264, 0.0640, 0.0658, -0.0286, 0.0150],
     [-0.0585, 0.0256, -0.0657, 0.0341, 0.0521],
     [ 0.0732, 0.0577, -0.0740, 0.0150, 0.0718],
     [-0.0311, -0.0343, 0.0234, -0.0110, 0.0344],
     [ 0.0698, -0.0613, -0.0400, 0.0648, 0.0735]],

     [[-0.0569, 0.0414, 0.0089, 0.0080, -0.0155],
     [-0.0289, -0.0245, -0.0732, 0.0417, 0.0205],
     [-0.0235, -0.0650, -0.0624, -0.0615, -0.0798],
     [ 0.0679, 0.0393, 0.0494, -0.0063, 0.0646],
     [-0.0303, -0.0782, 0.0025, 0.0761, -0.0034]],

     [[ 0.0738, -0.0106, 0.0397, -0.0621, -0.0492],
     [ 0.0518, 0.0812, 0.0331, 0.0730, 0.0802],
     [-0.0672, -0.0441, -0.0760, 0.0190, -0.0191],
     [ 0.0746, -0.0377, 0.0753, 0.0669, -0.0648],
     [-0.0325, -0.0538, 0.0273, -0.0089, 0.0195]],

     [[-0.0117, 0.0272, 0.0785, 0.0456, -0.0539],
     [ 0.0032, 0.0351, 0.0479, 0.0014, -0.0471],
     [ 0.0423, 0.0394, -0.0310, -0.0511, 0.0784],
     [-0.0053, -0.0243, -0.0048, 0.0709, -0.0030],
     [ 0.0415, 0.0264, 0.0010, -0.0056, 0.0069]],

     [[ 0.0320, -0.0181, 0.0360, -0.0439, -0.0279],
     [ 0.0479, -0.0807, 0.0018, -0.0336, 0.0605],
     [-0.0263, 0.0114, -0.0287, -0.0145, 0.0242],
     [ 0.0662, 0.0028, -0.0437, 0.0128, 0.0656],
     [-0.0760, 0.0179, 0.0657, -0.0070, -0.0182]],

     [[-0.0080, 0.0249, 0.0577, -0.0293, -0.0743],
     [ 0.0087, -0.0072, 0.0067, 0.0361, 0.0340],
     [ 0.0071, -0.0265, -0.0689, -0.0633, -0.0563],
     [ 0.0011, -0.0760, -0.0101, -0.0151, 0.0370],
     [-0.0111, 0.0191, -0.0481, 0.0536, -0.0312]]]],
    requires_grad=True), Parameter containing:
tensor([ 0.0811, 0.0474, 0.0688, 0.0393, 0.0037, 0.0488, 0.0750, 0.0471,
    -0.0719, -0.0324, 0.0389, 0.0586, -0.0008, 0.0676, 0.0294, -0.0628],
    requires_grad=True), Parameter containing:
tensor([[-0.0475, -0.0082, -0.0437, ..., -0.0330, 0.0490, 0.0475],
    [-0.0275, 0.0477, -0.0164, ..., -0.0029, 0.0100, -0.0315],
    [-0.0226, -0.0392, -0.0472, ..., -0.0402, -0.0272, -0.0432],
    ...,
    [-0.0246, -0.0008, 0.0447, ..., 0.0406, -0.0298, -0.0262],
    [ 0.0467, 0.0372, 0.0408, ..., -0.0421, -0.0001, -0.0135],
    [-0.0282, 0.0223, 0.0194, ..., -0.0097, -0.0319, 0.0396]],
    requires_grad=True), Parameter containing:
tensor([ 0.0312, 0.0236, 0.0176, 0.0037, -0.0012, -0.0042, 0.0425, 0.0405,
     0.0321, 0.0227, 0.0208, -0.0116, 0.0476, -0.0051, 0.0387, -0.0304,
     0.0043, 0.0238, 0.0025, 0.0380, 0.0364, 0.0444, 0.0352, 0.0125,
    -0.0236, -0.0201, 0.0044, 0.0127, -0.0117, 0.0066, 0.0128, -0.0357,
     0.0495, 0.0009, -0.0232, 0.0040, -0.0159, -0.0448, 0.0313, 0.0298,
    -0.0172, -0.0153, -0.0001, 0.0011, -0.0480, -0.0373, 0.0089, -0.0285,
     0.0373, -0.0390, 0.0039, -0.0410, 0.0361, -0.0379, -0.0024, 0.0319,
    -0.0204, 0.0499, 0.0245, 0.0405, -0.0188, 0.0363, -0.0243, -0.0254,
    -0.0162, 0.0027, -0.0361, -0.0312, -0.0237, 0.0039, 0.0370, 0.0016,
     0.0022, 0.0490, -0.0024, -0.0360, -0.0159, 0.0279, 0.0083, 0.0165,
    -0.0160, 0.0078, -0.0434, 0.0045, -0.0073, -0.0083, 0.0435, 0.0065,
     0.0092, -0.0196, -0.0220, -0.0032, -0.0253, -0.0129, 0.0335, 0.0439,
     0.0313, 0.0008, -0.0024, -0.0006, 0.0498, -0.0476, 0.0132, 0.0282,
    -0.0258, 0.0244, -0.0256, 0.0442, -0.0401, 0.0172, 0.0345, -0.0403,
     0.0404, 0.0330, 0.0240, -0.0060, -0.0173, 0.0332, 0.0438, 0.0324],
    requires_grad=True), Parameter containing:
tensor([[ 0.0682, 0.0148, 0.0024, ..., -0.0304, -0.0359, 0.0675],
    [-0.0736, 0.0799, 0.0328, ..., 0.0723, 0.0668, 0.0532],
    [ 0.0756, 0.0187, -0.0489, ..., 0.0413, -0.0153, 0.0911],
    ...,
    [ 0.0413, 0.0286, 0.0177, ..., -0.0861, -0.0364, 0.0363],
    [-0.0617, -0.0420, -0.0562, ..., -0.0488, 0.0451, -0.0753],
    [-0.0725, 0.0668, 0.0668, ..., -0.0901, 0.0577, -0.0083]],
    requires_grad=True), Parameter containing:
tensor([-0.0349, -0.0341, -0.0790, -0.0458, -0.0911, -0.0866, -0.0378, -0.0243,
    -0.0168, 0.0630, 0.0241, -0.0474, -0.0521, 0.0237, 0.0651, -0.0527,
    -0.0368, -0.0609, 0.0420, -0.0536, 0.0297, -0.0591, 0.0113, -0.0748,
     0.0217, 0.0540, 0.0677, 0.0161, -0.0137, 0.0009, 0.0039, -0.0293,
     0.0421, -0.0546, 0.0261, -0.0099, -0.0604, 0.0771, 0.0284, -0.0701,
    -0.0909, 0.0134, 0.0243, 0.0267, 0.0157, 0.0064, -0.0422, -0.0399,
     0.0850, -0.0752, 0.0048, -0.0739, 0.0360, -0.0775, 0.0242, 0.0187,
    -0.0077, 0.0587, 0.0575, 0.0811, 0.0098, 0.0193, 0.0817, 0.0226,
     0.0253, -0.0416, -0.0515, 0.0295, 0.0209, -0.0443, -0.0472, -0.0393,
     0.0170, -0.0864, 0.0637, 0.0264, -0.0822, -0.0534, -0.0441, -0.0410,
     0.0409, -0.0429, 0.0747, 0.0825], requires_grad=True), Parameter containing:
tensor([[ 0.0933, -0.0207, -0.0625, 0.0699, -0.0453, -0.0761, -0.0832, 0.0625,
     0.0088, -0.0761, -0.1056, -0.0030, -0.0689, -0.0944, 0.0860, 0.0847,
     0.0142, -0.0269, 0.0735, -0.0080, -0.0654, 0.0801, -0.0691, 0.0459,
     0.0287, 0.0508, -0.0854, 0.0158, -0.0010, -0.0982, 0.1022, 0.0983,
     -0.0577, 0.0037, -0.0862, 0.0950, 0.0595, -0.0366, -0.0567, -0.0346,
     0.0438, 0.0595, -0.0157, -0.0865, -0.0474, 0.0600, 0.0583, -0.0653,
     0.0962, -0.0919, -0.0094, -0.0529, 0.0105, -0.0262, -0.0430, -0.0617,
     0.0215, -0.0279, -0.0643, -0.0058, 0.0924, -0.0948, 0.0948, 0.1033,
     -0.0855, 0.0897, -0.0782, 0.0540, -0.0881, -0.0235, 0.0202, 0.0043,
     0.0427, 0.0609, 0.0642, 0.0931, -0.0185, -0.0504, -0.0069, 0.0574,
     -0.0265, -0.0505, 0.0262, 0.0494],
    [-0.0647, 0.0410, -0.0029, 0.0659, 0.0350, -0.0190, 0.0848, 0.0323,
     0.0249, -0.0729, -0.0899, 0.0368, 0.0960, -0.0329, -0.0825, -0.0920,
     -0.0124, -0.0553, -0.1004, -0.0076, 0.0704, -0.0279, 0.0950, 0.0774,
     -0.0640, -0.0858, -0.0032, 0.0328, -0.0961, 0.0209, 0.0067, -0.0628,
     0.1069, 0.0609, -0.0934, -0.0328, 0.0601, 0.0520, 0.0434, -0.1076,
     0.0327, 0.0708, 0.0961, 0.0427, -0.0130, -0.0341, -0.0425, -0.1044,
     -0.0677, -0.0760, -0.0531, 0.0128, 0.0123, -0.1091, 0.0852, -0.0368,
     0.0506, -0.0759, 0.0528, 0.0647, 0.0838, -0.0256, 0.0565, 0.0753,
     -0.0559, 0.0647, -0.0420, -0.0116, -0.0191, -0.0427, 0.0681, -0.0582,
     0.0391, -0.0757, 0.0098, 0.0503, 0.0191, -0.0063, -0.0429, -0.0566,
     -0.0739, -0.0428, 0.0544, 0.0183],
    [ 0.0067, 0.0380, -0.0176, -0.0715, -0.0549, 0.0962, 0.0355, -0.0906,
     0.0202, 0.0709, 0.0023, 0.0755, -0.0993, 0.0541, -0.0550, 0.0248,
     -0.0932, -0.0260, 0.1029, -0.0231, -0.0964, -0.0891, -0.0211, -0.0722,
     0.0446, 0.0500, 0.0587, 0.0497, -0.1061, -0.0997, -0.0102, 0.0313,
     0.0623, 0.0050, -0.0069, 0.0673, -0.0658, 0.1083, -0.0012, 0.0709,
     -0.0975, -0.0847, 0.0578, 0.0997, -0.0887, 0.0487, 0.0191, -0.0873,
     -0.0008, -0.0942, -0.0485, 0.0261, -0.0089, 0.0594, -0.0690, 0.0987,
     0.0836, -0.0318, 0.0439, 0.0591, 0.0820, 0.0010, -0.0838, 0.0104,
     -0.0534, -0.0732, -0.0150, 0.0793, 0.0686, -0.0508, 0.0454, 0.0869,
     0.0133, 0.0598, -0.0043, -0.0390, 0.0614, -0.0297, 0.0352, 0.0652,
     -0.0774, -0.0156, -0.0226, 0.0355],
    [ 0.0012, -0.0315, 0.0838, 0.0080, 0.0325, 0.0805, -0.0054, -0.0746,
     -0.0250, -0.0120, -0.0037, -0.0950, 0.0746, 0.0066, -0.1013, 0.0301,
     -0.0776, -0.0181, 0.0938, 0.0627, 0.0888, -0.0217, 0.1007, -0.0174,
     0.0960, -0.0866, -0.0873, 0.0747, 0.0552, -0.0443, 0.0784, 0.1001,
     -0.0328, 0.0386, 0.0802, 0.0276, -0.0714, 0.0509, -0.0348, -0.0464,
     0.0676, 0.0938, 0.0685, -0.0985, 0.0432, -0.0987, -0.0563, 0.0582,
     -0.0138, 0.0509, 0.0392, 0.0908, 0.0376, -0.0579, 0.1034, 0.0461,
     -0.0510, 0.0745, -0.0447, 0.0248, -0.1040, -0.0600, -0.0639, -0.0350,
     -0.0812, 0.0287, -0.0342, 0.0274, 0.0212, 0.0190, 0.0673, -0.0570,
     -0.0320, -0.0476, -0.0152, 0.0154, 0.0199, -0.0973, 0.0614, -0.0794,
     0.0210, -0.0102, -0.0125, 0.1074],
    [ 0.1063, -0.1013, 0.0380, -0.0271, -0.0457, 0.0205, -0.0071, 0.0985,
     0.0569, -0.0283, 0.0494, -0.0548, 0.0142, 0.0047, 0.0646, -0.0903,
     -0.0089, -0.0945, 0.0050, -0.0304, -0.0058, 0.0833, -0.1055, 0.0071,
     0.0397, -0.0592, -0.0156, -0.0940, -0.0198, 0.0241, -0.0241, -0.0299,
     -0.0764, 0.0725, 0.0215, -0.0002, 0.0380, 0.0081, 0.0422, -0.0312,
     -0.0346, 0.0854, -0.0751, 0.0749, -0.0767, 0.0197, 0.0360, 0.0932,
     0.0818, -0.0416, -0.0079, -0.0982, -0.1081, 0.1002, 0.0007, 0.0047,
     0.0829, -0.0354, -0.0034, 0.0529, -0.0712, 0.0277, 0.0826, -0.0883,
     -0.0738, 0.0713, 0.0276, -0.0088, 0.1027, 0.0437, 0.0649, -0.0988,
     0.0022, 0.0367, -0.0122, 0.1037, 0.0424, 0.0078, 0.0673, -0.0672,
     0.0365, -0.0655, -0.0897, -0.0060],
    [ 0.0624, -0.1046, 0.0262, -0.1060, -0.0777, 0.0284, -0.0273, -0.0677,
     0.0551, 0.0854, -0.1024, -0.0598, -0.0534, -0.0248, -0.0260, 0.0670,
     -0.0736, 0.0003, 0.0888, 0.0071, 0.0255, -0.0868, 0.0522, -0.1004,
     -0.0999, 0.0138, 0.0931, 0.0567, 0.0954, 0.0333, -0.0543, -0.0247,
     0.1058, 0.0855, -0.0132, -0.0682, -0.0004, 0.0740, -0.0042, 0.0707,
     0.0549, -0.0046, -0.0439, -0.0504, 0.0302, 0.1058, 0.0606, -0.0812,
     -0.0082, -0.0801, -0.0320, 0.0691, 0.0740, -0.0344, -0.0354, 0.0713,
     -0.0984, -0.0976, -0.0726, -0.0398, 0.0096, 0.0115, -0.0570, 0.0385,
     -0.0697, -0.0370, 0.0772, -0.1068, 0.0097, -0.0927, 0.0767, 0.0889,
     -0.0755, 0.0978, -0.0471, -0.0240, -0.0996, -0.1091, 0.0211, -0.0500,
     0.0238, 0.0725, 0.0794, -0.0496],
    [-0.0850, 0.0658, -0.0064, 0.0097, 0.0650, 0.0075, -0.0627, -0.0538,
     -0.0123, 0.1041, -0.0837, -0.0620, 0.0620, 0.0814, -0.0696, -0.0535,
     0.0680, -0.0468, -0.0347, -0.0950, -0.0020, -0.0560, -0.0118, 0.0160,
     0.0525, -0.0800, 0.0152, 0.0780, 0.0692, 0.0145, 0.0298, 0.0668,
     -0.0857, 0.0379, 0.0262, -0.0240, -0.0002, 0.0358, 0.1027, -0.0882,
     -0.0120, -0.0364, 0.0450, -0.0409, 0.0734, -0.0147, 0.0104, -0.0638,
     -0.0831, 0.0770, -0.0336, -0.0944, 0.0570, -0.0359, -0.0376, -0.0563,
     0.0341, -0.0075, -0.0501, 0.0724, -0.0501, -0.0783, 0.0453, -0.0150,
     -0.0106, 0.0109, -0.0479, 0.0527, -0.0272, 0.0638, -0.0136, -0.0106,
     0.0710, 0.0281, -0.0600, 0.0202, -0.0595, -0.1032, 0.0891, 0.0308,
     0.0624, 0.0160, 0.0935, -0.0290],
    [-0.0420, 0.0642, 0.0096, 0.0056, -0.0954, -0.0231, 0.0536, 0.0239,
     0.0520, 0.0656, 0.0722, -0.0495, 0.0226, 0.0359, 0.0317, 0.0162,
     -0.0188, -0.0342, -0.0720, 0.1008, -0.0424, -0.0066, -0.0008, 0.0624,
     0.0443, -0.0553, 0.0651, 0.0434, -0.0318, -0.0192, -0.1064, -0.0319,
     -0.0928, 0.0799, 0.0007, -0.0114, -0.0520, 0.0240, 0.0953, -0.0619,
     -0.0639, 0.0366, -0.0255, -0.0736, -0.0933, -0.0315, -0.1080, -0.1062,
     0.0589, 0.0623, 0.0540, 0.0721, -0.0768, 0.0105, -0.0027, 0.0621,
     -0.0751, 0.0233, -0.0751, -0.0806, -0.0826, 0.0300, -0.0291, 0.0383,
     -0.0808, 0.1007, -0.0543, 0.0035, -0.0561, 0.0085, -0.0836, -0.1047,
     0.0627, -0.1059, 0.0810, -0.0403, -0.0432, -0.1090, 0.0539, 0.0472,
     0.0431, -0.0725, 0.0756, 0.0827],
    [-0.0824, -0.0121, -0.0877, 0.1064, 0.0574, 0.0816, -0.0948, -0.0348,
     -0.0750, 0.0935, -0.0948, 0.0401, -0.0775, 0.0102, -0.1091, -0.0275,
     0.0953, 0.0511, 0.0871, 0.1013, -0.0493, 0.0454, -0.0099, -0.0197,
     0.0263, -0.0975, -0.0862, -0.0693, 0.0910, -0.0355, -0.0826, -0.0047,
     -0.0917, 0.0405, 0.0405, 0.1026, 0.0680, 0.0931, -0.1053, -0.0651,
     -0.0820, 0.0002, 0.0001, -0.0373, -0.1021, -0.1002, 0.0142, 0.0693,
     -0.0751, -0.0405, -0.0484, -0.0259, 0.0772, 0.0777, 0.0067, -0.0434,
     -0.0317, 0.0415, -0.0672, 0.1077, 0.0045, 0.0755, 0.0651, 0.0079,
     -0.0981, -0.0223, 0.0464, 0.0021, 0.0144, -0.0223, -0.0271, 0.0137,
     -0.0451, -0.0577, -0.0458, 0.0913, 0.0558, 0.0918, 0.0410, -0.0722,
     -0.0629, -0.0514, -0.0731, -0.0570],
    [ 0.1043, 0.1052, 0.0250, -0.0043, 0.0986, -0.0534, -0.1024, 0.0554,
     -0.0078, -0.0471, 0.0544, 0.0681, -0.0622, -0.0091, 0.0758, 0.0934,
     -0.0542, -0.0845, -0.0403, -0.1076, -0.0085, 0.0910, -0.0098, 0.0186,
     -0.0303, 0.0304, -0.0351, -0.0248, 0.0187, -0.0322, -0.0920, 0.0445,
     -0.0500, 0.0889, 0.0710, 0.0989, 0.0297, -0.0436, 0.0269, -0.0728,
     -0.0240, 0.0733, 0.0580, 0.0733, 0.0953, -0.0651, -0.0860, 0.0124,
     0.1046, 0.0657, -0.0190, -0.0595, 0.0981, 0.1066, -0.0814, -0.0410,
     -0.0362, 0.0359, -0.0863, -0.0438, 0.0252, 0.0351, 0.1041, -0.0746,
     0.0200, 0.0790, -0.1074, 0.0858, -0.0384, -0.0569, 0.0093, 0.1086,
     0.0327, 0.0278, -0.0765, -0.0221, 0.0803, 0.0598, -0.0706, 0.0766,
     0.0773, -0.0794, -0.0625, -0.0219]], requires_grad=True), Parameter containing:
tensor([-0.1061, -0.0962, 0.0518, 0.0545, -0.0188, -0.0293, -0.0951, 0.0373,
    -0.0218, -0.0068], requires_grad=True)]
10

逐列表项输出列表元素和index

利用enumerate函数实现

#逐列表项输出参数和当前参数位于列表的第几项
for num,temp in enumerate(para):
  print('number:',num)
  print(temp)

输出

number: 0
Parameter containing:
tensor([[[[-0.0596, 0.1908, 0.1831, 0.0542, -0.0283],
     [-0.0542, -0.1680, 0.1566, 0.1036, -0.1756],
     [-0.1437, 0.0083, 0.0871, 0.1549, 0.1556],
     [ 0.1360, 0.0171, 0.1034, -0.1548, -0.1343],
     [-0.0978, -0.1803, -0.0701, -0.0377, 0.0290]]],

    [[[-0.1020, 0.0862, -0.1227, -0.1742, 0.1510],
     [ 0.0728, 0.1725, 0.0352, 0.1579, 0.0367],
     [ 0.0862, -0.0995, 0.1276, -0.1895, -0.1346],
     [ 0.1938, 0.1387, -0.1983, -0.1015, -0.0740],
     [-0.0248, -0.0546, 0.0849, 0.1510, -0.0066]]],

    [[[ 0.1333, 0.0300, 0.0969, -0.0295, 0.0879],
     [ 0.1216, -0.0864, 0.0259, 0.0157, -0.1330],
     [-0.1873, 0.1309, 0.1947, 0.1886, 0.1944],
     [-0.0647, 0.0957, 0.1592, 0.1894, 0.1862],
     [ 0.0896, 0.1287, -0.0650, 0.0684, 0.1182]]],

    [[[-0.0816, 0.0968, 0.1259, -0.1124, -0.0864],
     [-0.0450, 0.0737, 0.0483, 0.1180, -0.0933],
     [-0.0925, -0.0549, 0.1191, 0.0165, 0.1369],
     [-0.1771, -0.1937, 0.1542, 0.1105, 0.1572],
     [ 0.1163, -0.1577, 0.1426, 0.0431, -0.0362]]],

    [[[-0.0675, -0.1039, 0.0762, -0.1798, 0.0071],
     [-0.1794, 0.1942, 0.0540, 0.1887, 0.1413],
     [ 0.1366, 0.0682, 0.1230, 0.0184, -0.0980],
     [-0.1613, 0.1225, -0.0734, 0.1938, 0.1919],
     [ 0.1745, -0.1550, 0.0663, 0.0044, -0.0538]]],

    [[[-0.0926, 0.1146, 0.1008, 0.1644, 0.1046],
     [-0.1230, 0.0080, 0.0198, -0.1216, -0.1942],
     [ 0.0327, 0.0205, 0.0862, -0.1714, 0.0955],
     [ 0.0358, -0.1350, 0.1387, -0.1365, -0.1600],
     [ 0.0368, -0.1323, -0.0127, 0.0917, -0.1892]]]],
    requires_grad=True)
number: 1
Parameter containing:
tensor([-0.0229, -0.1387, -0.1571, -0.0381, -0.1559, 0.0946], requires_grad=True)
number: 2
Parameter containing:
tensor([[[[-0.0497, -0.0356, -0.0272, -0.0519, 0.0451],
     [-0.0247, 0.0228, 0.0705, -0.0341, -0.0454],
     [ 0.0129, -0.0385, 0.0682, -0.0613, 0.0497],
     [-0.0394, 0.0218, -0.0056, 0.0204, -0.0668],
     [ 0.0469, 0.0649, -0.0470, 0.0138, -0.0686]],

     [[ 0.0647, 0.0554, -0.0220, -0.0295, -0.0145],
     [ 0.0500, -0.0026, 0.0545, 0.0415, 0.0020],
     [-0.0802, 0.0742, -0.0291, 0.0679, -0.0657],
     [ 0.0309, 0.0729, -0.0158, -0.0495, -0.0220],
     [-0.0433, 0.0440, -0.0485, 0.0478, 0.0618]],

     [[ 0.0523, -0.0072, -0.0786, 0.0569, 0.0334],
     [-0.0254, -0.0043, -0.0113, 0.0755, -0.0590],
     [ 0.0113, -0.0170, 0.0318, -0.0764, -0.0210],
     [-0.0203, -0.0273, 0.0634, 0.0380, 0.0014],
     [-0.0112, 0.0555, -0.0129, -0.0395, 0.0624]],

     [[ 0.0387, 0.0189, -0.0007, -0.0604, 0.0114],
     [ 0.0481, 0.0551, 0.0182, 0.0474, 0.0390],
     [ 0.0152, -0.0106, -0.0381, -0.0630, -0.0645],
     [ 0.0092, -0.0295, -0.0616, 0.0571, 0.0562],
     [ 0.0418, -0.0372, 0.0269, 0.0109, -0.0758]],

     [[-0.0751, -0.0610, 0.0269, -0.0331, -0.0193],
     [ 0.0577, 0.0430, -0.0201, -0.0017, -0.0408],
     [-0.0590, -0.0148, 0.0790, 0.0575, -0.0786],
     [ 0.0168, 0.0335, 0.0170, -0.0792, 0.0344],
     [-0.0738, 0.0193, -0.0732, -0.0666, -0.0734]],

     [[ 0.0154, 0.0712, 0.0540, -0.0429, 0.0573],
     [-0.0423, 0.0424, -0.0488, 0.0317, 0.0808],
     [ 0.0605, 0.0324, -0.0020, -0.0538, 0.0664],
     [ 0.0243, -0.0452, 0.0070, -0.0287, -0.0476],
     [ 0.0087, 0.0561, -0.0076, -0.0391, 0.0795]]],

    [[[ 0.0773, 0.0748, -0.0133, 0.0651, 0.0659],
     [ 0.0254, 0.0222, 0.0017, -0.0722, 0.0667],
     [ 0.0357, -0.0677, 0.0085, -0.0005, -0.0313],
     [ 0.0672, -0.0359, -0.0243, -0.0811, -0.0726],
     [ 0.0011, 0.0226, 0.0278, -0.0615, -0.0410]],

     [[ 0.0202, 0.0519, 0.0527, -0.0086, -0.0683],
     [ 0.0694, 0.0434, 0.0746, 0.0754, 0.0073],
     [ 0.0036, -0.0692, -0.0732, -0.0250, -0.0470],
     [-0.0669, 0.0609, 0.0649, -0.0158, 0.0189],
     [-0.0564, 0.0370, 0.0464, -0.0530, 0.0487]],

     [[ 0.0068, 0.0722, 0.0629, -0.0214, 0.0673],
     [-0.0384, 0.0799, -0.0350, 0.0816, 0.0586],
     [-0.0111, 0.0696, 0.0145, -0.0397, -0.0784],
     [-0.0120, 0.0555, 0.0021, -0.0494, -0.0344],
     [-0.0335, 0.0502, -0.0490, -0.0701, 0.0135]],

     [[-0.0365, 0.0733, 0.0610, 0.0028, 0.0292],
     [ 0.0552, -0.0674, 0.0176, -0.0131, 0.0688],
     [ 0.0147, -0.0432, 0.0473, -0.0231, -0.0314],
     [-0.0194, 0.0508, -0.0475, 0.0599, 0.0286],
     [ 0.0055, 0.0287, -0.0391, -0.0543, 0.0778]],

     [[-0.0241, -0.0322, 0.0704, -0.0758, -0.0562],
     [-0.0675, -0.0265, -0.0444, -0.0370, 0.0581],
     [-0.0577, 0.0462, 0.0165, 0.0146, -0.0317],
     [ 0.0047, 0.0666, -0.0365, 0.0749, 0.0677],
     [ 0.0557, 0.0098, 0.0451, 0.0306, -0.0628]],

     [[ 0.0529, 0.0167, 0.0501, 0.0679, 0.0505],
     [-0.0006, -0.0432, -0.0128, 0.0794, -0.0794],
     [ 0.0016, -0.0504, -0.0252, 0.0266, 0.0635],
     [ 0.0305, -0.0807, -0.0236, -0.0810, -0.0010],
     [-0.0423, -0.0285, -0.0559, 0.0560, 0.0796]]],

    [[[-0.0504, 0.0634, 0.0504, -0.0440, 0.0425],
     [ 0.0517, -0.0268, -0.0517, 0.0646, 0.0693],
     [ 0.0566, 0.0194, 0.0426, -0.0787, 0.0163],
     [-0.0661, -0.0457, 0.0691, -0.0058, -0.0073],
     [ 0.0794, 0.0645, 0.0367, -0.0625, -0.0731]],

     [[ 0.0190, 0.0393, 0.0145, -0.0073, 0.0478],
     [ 0.0405, 0.0038, -0.0349, -0.0022, 0.0202],
     [ 0.0346, -0.0622, 0.0194, -0.0151, 0.0220],
     [ 0.0002, -0.0663, 0.0730, -0.0462, -0.0182],
     [ 0.0311, -0.0079, 0.0720, 0.0517, -0.0601]],

     [[-0.0039, -0.0102, -0.0599, -0.0220, -0.0467],
     [-0.0495, -0.0265, 0.0484, 0.0497, 0.0090],
     [-0.0260, 0.0256, 0.0476, -0.0585, 0.0411],
     [-0.0505, -0.0447, -0.0002, -0.0121, -0.0170],
     [ 0.0400, 0.0457, 0.0709, 0.0195, 0.0762]],

     [[ 0.0732, -0.0100, 0.0115, -0.0046, -0.0133],
     [ 0.0333, -0.0065, 0.0115, 0.0057, 0.0370],
     [ 0.0328, -0.0513, 0.0648, 0.0588, 0.0230],
     [ 0.0154, 0.0261, 0.0579, 0.0118, 0.0050],
     [ 0.0089, 0.0468, -0.0763, -0.0314, 0.0676]],

     [[ 0.0428, -0.0646, -0.0339, 0.0185, -0.0042],
     [-0.0480, 0.0639, -0.0366, -0.0537, 0.0241],
     [-0.0572, 0.0309, -0.0761, 0.0227, -0.0385],
     [-0.0546, -0.0338, 0.0277, -0.0650, -0.0081],
     [ 0.0690, -0.0083, 0.0295, 0.0088, 0.0360]],

     [[ 0.0514, 0.0622, -0.0556, -0.0048, -0.0279],
     [ 0.0112, -0.0413, -0.0483, 0.0166, 0.0690],
     [-0.0433, 0.0410, -0.0335, -0.0458, -0.0055],
     [ 0.0229, 0.0289, 0.0695, 0.0574, 0.0075],
     [ 0.0651, -0.0337, -0.0130, -0.0381, 0.0272]]],

    ...,

    [[[-0.0538, 0.0321, 0.0302, 0.0222, -0.0062],
     [ 0.0050, -0.0461, 0.0084, -0.0448, -0.0604],
     [-0.0457, 0.0455, -0.0773, -0.0437, 0.0446],
     [ 0.0691, 0.0390, -0.0040, 0.0035, -0.0133],
     [ 0.0545, 0.0517, -0.0067, 0.0314, -0.0448]],

     [[ 0.0029, -0.0675, -0.0254, -0.0168, -0.0563],
     [ 0.0163, -0.0621, -0.0561, -0.0151, -0.0306],
     [-0.0021, 0.0389, -0.0429, 0.0778, 0.0451],
     [-0.0578, 0.0123, 0.0049, -0.0728, -0.0408],
     [ 0.0722, 0.0388, 0.0177, 0.0526, -0.0291]],

     [[ 0.0369, 0.0502, 0.0646, 0.0388, -0.0091],
     [ 0.0066, 0.0501, 0.0114, 0.0243, -0.0455],
     [ 0.0494, 0.0495, -0.0257, 0.0165, -0.0024],
     [-0.0476, -0.0552, 0.0029, -0.0813, 0.0698],
     [-0.0704, -0.0590, -0.0641, 0.0284, 0.0578]],

     [[ 0.0180, 0.0794, -0.0090, -0.0081, 0.0570],
     [-0.0529, 0.0517, 0.0045, -0.0580, -0.0192],
     [-0.0289, 0.0261, 0.0107, 0.0180, -0.0062],
     [-0.0162, 0.0607, 0.0154, 0.0450, 0.0694],
     [ 0.0324, 0.0418, -0.0199, -0.0357, 0.0104]],

     [[ 0.0525, -0.0401, 0.0803, -0.0453, -0.0534],
     [ 0.0628, 0.0120, 0.0147, 0.0294, -0.0351],
     [ 0.0773, -0.0587, -0.0713, 0.0125, -0.0125],
     [-0.0288, -0.0623, 0.0547, 0.0390, -0.0603],
     [ 0.0105, -0.0003, -0.0773, 0.0167, 0.0386]],

     [[ 0.0721, -0.0047, 0.0238, 0.0489, 0.0183],
     [-0.0127, -0.0090, -0.0588, 0.0641, 0.0460],
     [-0.0194, -0.0753, -0.0349, 0.0186, 0.0156],
     [ 0.0248, -0.0801, -0.0794, 0.0811, 0.0644],
     [-0.0415, 0.0127, -0.0120, -0.0724, -0.0800]]],

    [[[-0.0781, 0.0279, 0.0056, -0.0164, -0.0423],
     [ 0.0446, 0.0030, 0.0590, 0.0276, -0.0720],
     [ 0.0647, -0.0414, -0.0306, -0.0477, 0.0041],
     [-0.0647, 0.0124, 0.0166, -0.0592, 0.0164],
     [ 0.0789, -0.0673, -0.0583, 0.0493, 0.0306]],

     [[-0.0105, 0.0707, -0.0790, -0.0334, 0.0620],
     [ 0.0095, 0.0763, 0.0055, -0.0716, -0.0078],
     [ 0.0141, -0.0645, 0.0380, -0.0282, -0.0557],
     [ 0.0489, 0.0073, 0.0203, 0.0568, -0.0352],
     [-0.0299, 0.0681, -0.0300, 0.0178, -0.0101]],

     [[ 0.0401, -0.0572, 0.0219, 0.0427, 0.0276],
     [-0.0683, 0.0192, 0.0689, 0.0217, -0.0365],
     [-0.0140, -0.0361, -0.0562, 0.0528, 0.0029],
     [ 0.0213, 0.0464, 0.0525, -0.0804, 0.0599],
     [ 0.0770, -0.0657, 0.0655, 0.0741, 0.0462]],

     [[ 0.0479, 0.0648, -0.0050, 0.0530, -0.0746],
     [-0.0671, 0.0635, 0.0360, -0.0642, -0.0573],
     [ 0.0176, -0.0783, -0.0781, -0.0027, 0.0405],
     [ 0.0057, -0.0685, 0.0673, 0.0697, -0.0792],
     [-0.0449, -0.0773, -0.0756, -0.0524, 0.0378]],

     [[ 0.0201, 0.0407, -0.0442, -0.0007, -0.0174],
     [-0.0779, 0.0032, -0.0650, 0.0172, -0.0081],
     [ 0.0796, -0.0781, -0.0364, 0.0141, -0.0198],
     [ 0.0270, 0.0519, -0.0578, -0.0515, 0.0225],
     [ 0.0212, 0.0231, 0.0071, 0.0190, 0.0285]],

     [[ 0.0311, 0.0148, 0.0181, 0.0617, 0.0037],
     [ 0.0754, -0.0596, -0.0498, 0.0388, -0.0612],
     [ 0.0318, -0.0068, -0.0725, -0.0671, -0.0531],
     [ 0.0446, 0.0793, 0.0193, 0.0033, -0.0685],
     [ 0.0426, 0.0017, 0.0477, 0.0556, 0.0341]]],

    [[[ 0.0264, 0.0640, 0.0658, -0.0286, 0.0150],
     [-0.0585, 0.0256, -0.0657, 0.0341, 0.0521],
     [ 0.0732, 0.0577, -0.0740, 0.0150, 0.0718],
     [-0.0311, -0.0343, 0.0234, -0.0110, 0.0344],
     [ 0.0698, -0.0613, -0.0400, 0.0648, 0.0735]],

     [[-0.0569, 0.0414, 0.0089, 0.0080, -0.0155],
     [-0.0289, -0.0245, -0.0732, 0.0417, 0.0205],
     [-0.0235, -0.0650, -0.0624, -0.0615, -0.0798],
     [ 0.0679, 0.0393, 0.0494, -0.0063, 0.0646],
     [-0.0303, -0.0782, 0.0025, 0.0761, -0.0034]],

     [[ 0.0738, -0.0106, 0.0397, -0.0621, -0.0492],
     [ 0.0518, 0.0812, 0.0331, 0.0730, 0.0802],
     [-0.0672, -0.0441, -0.0760, 0.0190, -0.0191],
     [ 0.0746, -0.0377, 0.0753, 0.0669, -0.0648],
     [-0.0325, -0.0538, 0.0273, -0.0089, 0.0195]],

     [[-0.0117, 0.0272, 0.0785, 0.0456, -0.0539],
     [ 0.0032, 0.0351, 0.0479, 0.0014, -0.0471],
     [ 0.0423, 0.0394, -0.0310, -0.0511, 0.0784],
     [-0.0053, -0.0243, -0.0048, 0.0709, -0.0030],
     [ 0.0415, 0.0264, 0.0010, -0.0056, 0.0069]],

     [[ 0.0320, -0.0181, 0.0360, -0.0439, -0.0279],
     [ 0.0479, -0.0807, 0.0018, -0.0336, 0.0605],
     [-0.0263, 0.0114, -0.0287, -0.0145, 0.0242],
     [ 0.0662, 0.0028, -0.0437, 0.0128, 0.0656],
     [-0.0760, 0.0179, 0.0657, -0.0070, -0.0182]],

     [[-0.0080, 0.0249, 0.0577, -0.0293, -0.0743],
     [ 0.0087, -0.0072, 0.0067, 0.0361, 0.0340],
     [ 0.0071, -0.0265, -0.0689, -0.0633, -0.0563],
     [ 0.0011, -0.0760, -0.0101, -0.0151, 0.0370],
     [-0.0111, 0.0191, -0.0481, 0.0536, -0.0312]]]],
    requires_grad=True)
number: 3
Parameter containing:
tensor([ 0.0811, 0.0474, 0.0688, 0.0393, 0.0037, 0.0488, 0.0750, 0.0471,
    -0.0719, -0.0324, 0.0389, 0.0586, -0.0008, 0.0676, 0.0294, -0.0628],
    requires_grad=True)
number: 4
Parameter containing:
tensor([[-0.0475, -0.0082, -0.0437, ..., -0.0330, 0.0490, 0.0475],
    [-0.0275, 0.0477, -0.0164, ..., -0.0029, 0.0100, -0.0315],
    [-0.0226, -0.0392, -0.0472, ..., -0.0402, -0.0272, -0.0432],
    ...,
    [-0.0246, -0.0008, 0.0447, ..., 0.0406, -0.0298, -0.0262],
    [ 0.0467, 0.0372, 0.0408, ..., -0.0421, -0.0001, -0.0135],
    [-0.0282, 0.0223, 0.0194, ..., -0.0097, -0.0319, 0.0396]],
    requires_grad=True)
number: 5
Parameter containing:
tensor([ 0.0312, 0.0236, 0.0176, 0.0037, -0.0012, -0.0042, 0.0425, 0.0405,
     0.0321, 0.0227, 0.0208, -0.0116, 0.0476, -0.0051, 0.0387, -0.0304,
     0.0043, 0.0238, 0.0025, 0.0380, 0.0364, 0.0444, 0.0352, 0.0125,
    -0.0236, -0.0201, 0.0044, 0.0127, -0.0117, 0.0066, 0.0128, -0.0357,
     0.0495, 0.0009, -0.0232, 0.0040, -0.0159, -0.0448, 0.0313, 0.0298,
    -0.0172, -0.0153, -0.0001, 0.0011, -0.0480, -0.0373, 0.0089, -0.0285,
     0.0373, -0.0390, 0.0039, -0.0410, 0.0361, -0.0379, -0.0024, 0.0319,
    -0.0204, 0.0499, 0.0245, 0.0405, -0.0188, 0.0363, -0.0243, -0.0254,
    -0.0162, 0.0027, -0.0361, -0.0312, -0.0237, 0.0039, 0.0370, 0.0016,
     0.0022, 0.0490, -0.0024, -0.0360, -0.0159, 0.0279, 0.0083, 0.0165,
    -0.0160, 0.0078, -0.0434, 0.0045, -0.0073, -0.0083, 0.0435, 0.0065,
     0.0092, -0.0196, -0.0220, -0.0032, -0.0253, -0.0129, 0.0335, 0.0439,
     0.0313, 0.0008, -0.0024, -0.0006, 0.0498, -0.0476, 0.0132, 0.0282,
    -0.0258, 0.0244, -0.0256, 0.0442, -0.0401, 0.0172, 0.0345, -0.0403,
     0.0404, 0.0330, 0.0240, -0.0060, -0.0173, 0.0332, 0.0438, 0.0324],
    requires_grad=True)
number: 6
Parameter containing:
tensor([[ 0.0682, 0.0148, 0.0024, ..., -0.0304, -0.0359, 0.0675],
    [-0.0736, 0.0799, 0.0328, ..., 0.0723, 0.0668, 0.0532],
    [ 0.0756, 0.0187, -0.0489, ..., 0.0413, -0.0153, 0.0911],
    ...,
    [ 0.0413, 0.0286, 0.0177, ..., -0.0861, -0.0364, 0.0363],
    [-0.0617, -0.0420, -0.0562, ..., -0.0488, 0.0451, -0.0753],
    [-0.0725, 0.0668, 0.0668, ..., -0.0901, 0.0577, -0.0083]],
    requires_grad=True)
number: 7
Parameter containing:
tensor([-0.0349, -0.0341, -0.0790, -0.0458, -0.0911, -0.0866, -0.0378, -0.0243,
    -0.0168, 0.0630, 0.0241, -0.0474, -0.0521, 0.0237, 0.0651, -0.0527,
    -0.0368, -0.0609, 0.0420, -0.0536, 0.0297, -0.0591, 0.0113, -0.0748,
     0.0217, 0.0540, 0.0677, 0.0161, -0.0137, 0.0009, 0.0039, -0.0293,
     0.0421, -0.0546, 0.0261, -0.0099, -0.0604, 0.0771, 0.0284, -0.0701,
    -0.0909, 0.0134, 0.0243, 0.0267, 0.0157, 0.0064, -0.0422, -0.0399,
     0.0850, -0.0752, 0.0048, -0.0739, 0.0360, -0.0775, 0.0242, 0.0187,
    -0.0077, 0.0587, 0.0575, 0.0811, 0.0098, 0.0193, 0.0817, 0.0226,
     0.0253, -0.0416, -0.0515, 0.0295, 0.0209, -0.0443, -0.0472, -0.0393,
     0.0170, -0.0864, 0.0637, 0.0264, -0.0822, -0.0534, -0.0441, -0.0410,
     0.0409, -0.0429, 0.0747, 0.0825], requires_grad=True)
number: 8
Parameter containing:
tensor([[ 0.0933, -0.0207, -0.0625, 0.0699, -0.0453, -0.0761, -0.0832, 0.0625,
     0.0088, -0.0761, -0.1056, -0.0030, -0.0689, -0.0944, 0.0860, 0.0847,
     0.0142, -0.0269, 0.0735, -0.0080, -0.0654, 0.0801, -0.0691, 0.0459,
     0.0287, 0.0508, -0.0854, 0.0158, -0.0010, -0.0982, 0.1022, 0.0983,
     -0.0577, 0.0037, -0.0862, 0.0950, 0.0595, -0.0366, -0.0567, -0.0346,
     0.0438, 0.0595, -0.0157, -0.0865, -0.0474, 0.0600, 0.0583, -0.0653,
     0.0962, -0.0919, -0.0094, -0.0529, 0.0105, -0.0262, -0.0430, -0.0617,
     0.0215, -0.0279, -0.0643, -0.0058, 0.0924, -0.0948, 0.0948, 0.1033,
     -0.0855, 0.0897, -0.0782, 0.0540, -0.0881, -0.0235, 0.0202, 0.0043,
     0.0427, 0.0609, 0.0642, 0.0931, -0.0185, -0.0504, -0.0069, 0.0574,
     -0.0265, -0.0505, 0.0262, 0.0494],
    [-0.0647, 0.0410, -0.0029, 0.0659, 0.0350, -0.0190, 0.0848, 0.0323,
     0.0249, -0.0729, -0.0899, 0.0368, 0.0960, -0.0329, -0.0825, -0.0920,
     -0.0124, -0.0553, -0.1004, -0.0076, 0.0704, -0.0279, 0.0950, 0.0774,
     -0.0640, -0.0858, -0.0032, 0.0328, -0.0961, 0.0209, 0.0067, -0.0628,
     0.1069, 0.0609, -0.0934, -0.0328, 0.0601, 0.0520, 0.0434, -0.1076,
     0.0327, 0.0708, 0.0961, 0.0427, -0.0130, -0.0341, -0.0425, -0.1044,
     -0.0677, -0.0760, -0.0531, 0.0128, 0.0123, -0.1091, 0.0852, -0.0368,
     0.0506, -0.0759, 0.0528, 0.0647, 0.0838, -0.0256, 0.0565, 0.0753,
     -0.0559, 0.0647, -0.0420, -0.0116, -0.0191, -0.0427, 0.0681, -0.0582,
     0.0391, -0.0757, 0.0098, 0.0503, 0.0191, -0.0063, -0.0429, -0.0566,
     -0.0739, -0.0428, 0.0544, 0.0183],
    [ 0.0067, 0.0380, -0.0176, -0.0715, -0.0549, 0.0962, 0.0355, -0.0906,
     0.0202, 0.0709, 0.0023, 0.0755, -0.0993, 0.0541, -0.0550, 0.0248,
     -0.0932, -0.0260, 0.1029, -0.0231, -0.0964, -0.0891, -0.0211, -0.0722,
     0.0446, 0.0500, 0.0587, 0.0497, -0.1061, -0.0997, -0.0102, 0.0313,
     0.0623, 0.0050, -0.0069, 0.0673, -0.0658, 0.1083, -0.0012, 0.0709,
     -0.0975, -0.0847, 0.0578, 0.0997, -0.0887, 0.0487, 0.0191, -0.0873,
     -0.0008, -0.0942, -0.0485, 0.0261, -0.0089, 0.0594, -0.0690, 0.0987,
     0.0836, -0.0318, 0.0439, 0.0591, 0.0820, 0.0010, -0.0838, 0.0104,
     -0.0534, -0.0732, -0.0150, 0.0793, 0.0686, -0.0508, 0.0454, 0.0869,
     0.0133, 0.0598, -0.0043, -0.0390, 0.0614, -0.0297, 0.0352, 0.0652,
     -0.0774, -0.0156, -0.0226, 0.0355],
    [ 0.0012, -0.0315, 0.0838, 0.0080, 0.0325, 0.0805, -0.0054, -0.0746,
     -0.0250, -0.0120, -0.0037, -0.0950, 0.0746, 0.0066, -0.1013, 0.0301,
     -0.0776, -0.0181, 0.0938, 0.0627, 0.0888, -0.0217, 0.1007, -0.0174,
     0.0960, -0.0866, -0.0873, 0.0747, 0.0552, -0.0443, 0.0784, 0.1001,
     -0.0328, 0.0386, 0.0802, 0.0276, -0.0714, 0.0509, -0.0348, -0.0464,
     0.0676, 0.0938, 0.0685, -0.0985, 0.0432, -0.0987, -0.0563, 0.0582,
     -0.0138, 0.0509, 0.0392, 0.0908, 0.0376, -0.0579, 0.1034, 0.0461,
     -0.0510, 0.0745, -0.0447, 0.0248, -0.1040, -0.0600, -0.0639, -0.0350,
     -0.0812, 0.0287, -0.0342, 0.0274, 0.0212, 0.0190, 0.0673, -0.0570,
     -0.0320, -0.0476, -0.0152, 0.0154, 0.0199, -0.0973, 0.0614, -0.0794,
     0.0210, -0.0102, -0.0125, 0.1074],
    [ 0.1063, -0.1013, 0.0380, -0.0271, -0.0457, 0.0205, -0.0071, 0.0985,
     0.0569, -0.0283, 0.0494, -0.0548, 0.0142, 0.0047, 0.0646, -0.0903,
     -0.0089, -0.0945, 0.0050, -0.0304, -0.0058, 0.0833, -0.1055, 0.0071,
     0.0397, -0.0592, -0.0156, -0.0940, -0.0198, 0.0241, -0.0241, -0.0299,
     -0.0764, 0.0725, 0.0215, -0.0002, 0.0380, 0.0081, 0.0422, -0.0312,
     -0.0346, 0.0854, -0.0751, 0.0749, -0.0767, 0.0197, 0.0360, 0.0932,
     0.0818, -0.0416, -0.0079, -0.0982, -0.1081, 0.1002, 0.0007, 0.0047,
     0.0829, -0.0354, -0.0034, 0.0529, -0.0712, 0.0277, 0.0826, -0.0883,
     -0.0738, 0.0713, 0.0276, -0.0088, 0.1027, 0.0437, 0.0649, -0.0988,
     0.0022, 0.0367, -0.0122, 0.1037, 0.0424, 0.0078, 0.0673, -0.0672,
     0.0365, -0.0655, -0.0897, -0.0060],
    [ 0.0624, -0.1046, 0.0262, -0.1060, -0.0777, 0.0284, -0.0273, -0.0677,
     0.0551, 0.0854, -0.1024, -0.0598, -0.0534, -0.0248, -0.0260, 0.0670,
     -0.0736, 0.0003, 0.0888, 0.0071, 0.0255, -0.0868, 0.0522, -0.1004,
     -0.0999, 0.0138, 0.0931, 0.0567, 0.0954, 0.0333, -0.0543, -0.0247,
     0.1058, 0.0855, -0.0132, -0.0682, -0.0004, 0.0740, -0.0042, 0.0707,
     0.0549, -0.0046, -0.0439, -0.0504, 0.0302, 0.1058, 0.0606, -0.0812,
     -0.0082, -0.0801, -0.0320, 0.0691, 0.0740, -0.0344, -0.0354, 0.0713,
     -0.0984, -0.0976, -0.0726, -0.0398, 0.0096, 0.0115, -0.0570, 0.0385,
     -0.0697, -0.0370, 0.0772, -0.1068, 0.0097, -0.0927, 0.0767, 0.0889,
     -0.0755, 0.0978, -0.0471, -0.0240, -0.0996, -0.1091, 0.0211, -0.0500,
     0.0238, 0.0725, 0.0794, -0.0496],
    [-0.0850, 0.0658, -0.0064, 0.0097, 0.0650, 0.0075, -0.0627, -0.0538,
     -0.0123, 0.1041, -0.0837, -0.0620, 0.0620, 0.0814, -0.0696, -0.0535,
     0.0680, -0.0468, -0.0347, -0.0950, -0.0020, -0.0560, -0.0118, 0.0160,
     0.0525, -0.0800, 0.0152, 0.0780, 0.0692, 0.0145, 0.0298, 0.0668,
     -0.0857, 0.0379, 0.0262, -0.0240, -0.0002, 0.0358, 0.1027, -0.0882,
     -0.0120, -0.0364, 0.0450, -0.0409, 0.0734, -0.0147, 0.0104, -0.0638,
     -0.0831, 0.0770, -0.0336, -0.0944, 0.0570, -0.0359, -0.0376, -0.0563,
     0.0341, -0.0075, -0.0501, 0.0724, -0.0501, -0.0783, 0.0453, -0.0150,
     -0.0106, 0.0109, -0.0479, 0.0527, -0.0272, 0.0638, -0.0136, -0.0106,
     0.0710, 0.0281, -0.0600, 0.0202, -0.0595, -0.1032, 0.0891, 0.0308,
     0.0624, 0.0160, 0.0935, -0.0290],
    [-0.0420, 0.0642, 0.0096, 0.0056, -0.0954, -0.0231, 0.0536, 0.0239,
     0.0520, 0.0656, 0.0722, -0.0495, 0.0226, 0.0359, 0.0317, 0.0162,
     -0.0188, -0.0342, -0.0720, 0.1008, -0.0424, -0.0066, -0.0008, 0.0624,
     0.0443, -0.0553, 0.0651, 0.0434, -0.0318, -0.0192, -0.1064, -0.0319,
     -0.0928, 0.0799, 0.0007, -0.0114, -0.0520, 0.0240, 0.0953, -0.0619,
     -0.0639, 0.0366, -0.0255, -0.0736, -0.0933, -0.0315, -0.1080, -0.1062,
     0.0589, 0.0623, 0.0540, 0.0721, -0.0768, 0.0105, -0.0027, 0.0621,
     -0.0751, 0.0233, -0.0751, -0.0806, -0.0826, 0.0300, -0.0291, 0.0383,
     -0.0808, 0.1007, -0.0543, 0.0035, -0.0561, 0.0085, -0.0836, -0.1047,
     0.0627, -0.1059, 0.0810, -0.0403, -0.0432, -0.1090, 0.0539, 0.0472,
     0.0431, -0.0725, 0.0756, 0.0827],
    [-0.0824, -0.0121, -0.0877, 0.1064, 0.0574, 0.0816, -0.0948, -0.0348,
     -0.0750, 0.0935, -0.0948, 0.0401, -0.0775, 0.0102, -0.1091, -0.0275,
     0.0953, 0.0511, 0.0871, 0.1013, -0.0493, 0.0454, -0.0099, -0.0197,
     0.0263, -0.0975, -0.0862, -0.0693, 0.0910, -0.0355, -0.0826, -0.0047,
     -0.0917, 0.0405, 0.0405, 0.1026, 0.0680, 0.0931, -0.1053, -0.0651,
     -0.0820, 0.0002, 0.0001, -0.0373, -0.1021, -0.1002, 0.0142, 0.0693,
     -0.0751, -0.0405, -0.0484, -0.0259, 0.0772, 0.0777, 0.0067, -0.0434,
     -0.0317, 0.0415, -0.0672, 0.1077, 0.0045, 0.0755, 0.0651, 0.0079,
     -0.0981, -0.0223, 0.0464, 0.0021, 0.0144, -0.0223, -0.0271, 0.0137,
     -0.0451, -0.0577, -0.0458, 0.0913, 0.0558, 0.0918, 0.0410, -0.0722,
     -0.0629, -0.0514, -0.0731, -0.0570],
    [ 0.1043, 0.1052, 0.0250, -0.0043, 0.0986, -0.0534, -0.1024, 0.0554,
     -0.0078, -0.0471, 0.0544, 0.0681, -0.0622, -0.0091, 0.0758, 0.0934,
     -0.0542, -0.0845, -0.0403, -0.1076, -0.0085, 0.0910, -0.0098, 0.0186,
     -0.0303, 0.0304, -0.0351, -0.0248, 0.0187, -0.0322, -0.0920, 0.0445,
     -0.0500, 0.0889, 0.0710, 0.0989, 0.0297, -0.0436, 0.0269, -0.0728,
     -0.0240, 0.0733, 0.0580, 0.0733, 0.0953, -0.0651, -0.0860, 0.0124,
     0.1046, 0.0657, -0.0190, -0.0595, 0.0981, 0.1066, -0.0814, -0.0410,
     -0.0362, 0.0359, -0.0863, -0.0438, 0.0252, 0.0351, 0.1041, -0.0746,
     0.0200, 0.0790, -0.1074, 0.0858, -0.0384, -0.0569, 0.0093, 0.1086,
     0.0327, 0.0278, -0.0765, -0.0221, 0.0803, 0.0598, -0.0706, 0.0766,
     0.0773, -0.0794, -0.0625, -0.0219]], requires_grad=True)
number: 9
Parameter containing:
tensor([-0.1061, -0.0962, 0.0518, 0.0545, -0.0188, -0.0293, -0.0951, 0.0373,
    -0.0218, -0.0068], requires_grad=True)

以上这篇Pytorch之parameters的使用就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • pytorch中tensor张量数据类型的转化方式

    1.tensor张量与numpy相互转换 tensor ----->numpy import torch a=torch.ones([2,5]) tensor([[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]]) # ********************************** b=a.numpy() array([[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], dtype=float32) numpy --

  • Pytorch之view及view_as使用详解

    view()函数是在torch.Tensor.view()下的一个函数,可以有tensor调用,也可以有variable调用. 其作用在于返回和原tensor数据个数相同,但size不同的tensor [Numpy中的size是元素个数,但是在Pytorch中size等价为Numpy中的shape] view函数的-1参数的作用在于基于另一参数,自动计算该维度的大小 很重要的一点 view函数只能由于contiguous的张量上,具体而言,就是在内存中连续存储的张量. 具体而言,可以参看 htt

  • Pytorch 多块GPU的使用详解

    注:本文针对单个服务器上多块GPU的使用,不是多服务器多GPU的使用. 在一些实验中,由于Batch_size的限制或者希望提高训练速度等原因,我们需要使用多块GPU.本文针对Pytorch中多块GPU的使用进行说明. 1. 设置需要使用的GPU编号 import os os.environ["CUDA_VISIBLE_DEVICES"] = "0,4" ids = [0,1] 比如我们需要使用第0和第4块GPU,只用上述三行代码即可. 其中第二行指程序只能看到第1

  • pytorch中nn.Conv1d的用法详解

    先粘贴一段official guide:nn.conv1d官方 我一开始被in_channels.out_channels卡住了很久,结果发现就和conv2d是一毛一样的.话不多说,先粘代码(菜鸡的自我修养) class CNN1d(nn.Module): def __init__(self): super(CNN1d,self).__init__() self.layer1 = nn.Sequential( nn.Conv1d(1,100,2), nn.BatchNorm1d(100), nn

  • Pytorch之contiguous的用法

    contiguous tensor变量调用contiguous()函数会使tensor变量在内存中的存储变得连续. contiguous():view只能用在contiguous的variable上.如果在view之前用了transpose, permute等,需要用contiguous()来返回一个contiguous copy. 一种可能的解释是: 有些tensor并不是占用一整块内存,而是由不同的数据块组成,而tensor的view()操作依赖于内存是整块的,这时只需要执行contiguo

  • Pytorch之Variable的用法

    1.简介 torch.autograd.Variable是Autograd的核心类,它封装了Tensor,并整合了反向传播的相关实现 Variable和tensor的区别和联系 Variable是篮子,而tensor是鸡蛋,鸡蛋应该放在篮子里才能方便拿走(定义variable时一个参数就是tensor) Variable这个篮子里除了装了tensor外还有requires_grad参数,表示是否需要对其求导,默认为False Variable这个篮子呢,自身有一些属性 比如grad,梯度vari

  • Pytorch之parameters的使用

    1.预构建网络 class Net(nn.Module): def __init__(self): super(Net, self).__init__() # 1 input image channel, 6 output channels, 5*5 square convolution # kernel self.conv1 = nn.Conv2d(1, 6, 5) self.conv2 = nn.Conv2d(6, 16, 5) # an affine operation: y = Wx +

  • 在pytorch中如何查看模型model参数parameters

    目录 pytorch查看模型model参数parameters pytorch查看模型参数总结 1:DNN_printer 2:parameters 3:get_model_complexity_info() 4:torchstat pytorch查看模型model参数parameters 示例1:pytorch自带的faster r-cnn模型 import torch import torchvision model = torchvision.models.detection.faster

  • python PyTorch参数初始化和Finetune

    前言 这篇文章算是论坛PyTorch Forums关于参数初始化和finetune的总结,也是我在写代码中用的算是"最佳实践"吧.最后希望大家没事多逛逛论坛,有很多高质量的回答. 参数初始化 参数的初始化其实就是对参数赋值.而我们需要学习的参数其实都是Variable,它其实是对Tensor的封装,同时提供了data,grad等借口,这就意味着我们可以直接对这些参数进行操作赋值了.这就是PyTorch简洁高效所在. 所以我们可以进行如下操作进行初始化,当然其实有其他的方法,但是这种方法

  • Pytorch入门之mnist分类实例

    本文实例为大家分享了Pytorch入门之mnist分类的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'denny' __time__ = '2017-9-9 9:03' import torch import torchvision from torch.autograd import Variable import torch.utils.data.dataloader as Data

  • PyTorch快速搭建神经网络及其保存提取方法详解

    有时候我们训练了一个模型, 希望保存它下次直接使用,不需要下次再花时间去训练 ,本节我们来讲解一下PyTorch快速搭建神经网络及其保存提取方法详解 一.PyTorch快速搭建神经网络方法 先看实验代码: import torch import torch.nn.functional as F # 方法1,通过定义一个Net类来建立神经网络 class Net(torch.nn.Module): def __init__(self, n_feature, n_hidden, n_output):

  • PyTorch上搭建简单神经网络实现回归和分类的示例

    本文介绍了PyTorch上搭建简单神经网络实现回归和分类的示例,分享给大家,具体如下: 一.PyTorch入门 1. 安装方法 登录PyTorch官网,http://pytorch.org,可以看到以下界面: 按上图的选项选择后即可得到Linux下conda指令: conda install pytorch torchvision -c soumith 目前PyTorch仅支持MacOS和Linux,暂不支持Windows.安装 PyTorch 会安装两个模块,一个是torch,一个 torch

  • PyTorch上实现卷积神经网络CNN的方法

    一.卷积神经网络 卷积神经网络(ConvolutionalNeuralNetwork,CNN)最初是为解决图像识别等问题设计的,CNN现在的应用已经不限于图像和视频,也可用于时间序列信号,比如音频信号和文本数据等.CNN作为一个深度学习架构被提出的最初诉求是降低对图像数据预处理的要求,避免复杂的特征工程.在卷积神经网络中,第一个卷积层会直接接受图像像素级的输入,每一层卷积(滤波器)都会提取数据中最有效的特征,这种方法可以提取到图像中最基础的特征,而后再进行组合和抽象形成更高阶的特征,因此CNN在

  • 详解PyTorch批训练及优化器比较

    一.PyTorch批训练 1. 概述 PyTorch提供了一种将数据包装起来进行批训练的工具--DataLoader.使用的时候,只需要将我们的数据首先转换为torch的tensor形式,再转换成torch可以识别的Dataset格式,然后将Dataset放入DataLoader中就可以啦. import torch import torch.utils.data as Data torch.manual_seed(1) # 设定随机数种子 BATCH_SIZE = 5 x = torch.li

  • pytorch + visdom 处理简单分类问题的示例

    环境 系统 : win 10 显卡:gtx965m cpu :i7-6700HQ python 3.61 pytorch 0.3 包引用 import torch from torch.autograd import Variable import torch.nn.functional as F import numpy as np import visdom import time from torch import nn,optim 数据准备 use_gpu = True ones = n

  • PyTorch CNN实战之MNIST手写数字识别示例

    简介 卷积神经网络(Convolutional Neural Network, CNN)是深度学习技术中极具代表的网络结构之一,在图像处理领域取得了很大的成功,在国际标准的ImageNet数据集上,许多成功的模型都是基于CNN的. 卷积神经网络CNN的结构一般包含这几个层: 输入层:用于数据的输入 卷积层:使用卷积核进行特征提取和特征映射 激励层:由于卷积也是一种线性运算,因此需要增加非线性映射 池化层:进行下采样,对特征图稀疏处理,减少数据运算量. 全连接层:通常在CNN的尾部进行重新拟合,减

随机推荐