PyTorch Model.Parameters()遍历时会产生错误

xs = [G.parameters(), D.parameters()]
for i in xs[0]:
    print(i)
print("+++++++")
for i in xs[0]:
    print(i)
print("++++++++++")

生成结果是:

Parameter containing:
tensor([[ 1.0000e+00,  7.8245e-11,  7.8229e-12,  ...,  3.5181e-11,
          4.7598e-11, -1.0584e-11],
        [ 7.5359e-11,  1.0000e+00, -2.6498e-11,  ..., -1.1916e-10,
         -1.6122e-10,  3.5851e-11],
        [-3.7384e-11,  1.3148e-10,  1.0000e+00,  ...,  5.9115e-11,
          7.9981e-11, -1.7785e-11],
        ...,
        [ 3.4832e-11, -1.2250e-10, -1.2248e-11,  ..., -5.5080e-11,
         -7.4521e-11,  1.6571e-11],
        [ 4.5728e-11, -1.6082e-10, -1.6079e-11,  ..., -7.2309e-11,
         -9.7831e-11,  2.1755e-11],
        [-5.3558e-11,  1.8836e-10,  1.8832e-11,  ...,  8.4690e-11,
          1.1458e-10, -2.5480e-11]], device='cuda:0')
Parameter containing:
tensor(1.00000e-09 *
       [ 0.5833, -1.9758,  0.9802, -0.9176,  0.2137,  1.8667,  0.3128,
        -0.9133, -1.1989,  1.4042], device='cuda:0')
+++++++
+++++++++

xs[0]在被调用一次以后就好像会被清空(结构依旧保留)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值