Tensorflow assign_sub 不更新值

原文标题Tensorflow assign_sub not updating values

我有两个形状相同的 TF 变量。当我在其中一个上调用 assign_sub 方法时,它似乎没有执行该操作。我使用 tf sub 得到了相同的结果。有谁知道为什么会发生这种情况以及我该如何解决?贝娄取自我的 jupyter 笔记本。

非常感谢您的帮助!

w1
<tf.Variable 'Variable:0' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169483, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>

w2
<tf.Tensor: shape=(784, 200), dtype=float32, numpy=
array([[ 2.11303495e-13,  8.10649508e-13, -2.57005734e-13, ...,
         5.05237399e-13, -1.01372578e-13,  1.07068786e-13],
       [ 1.18608231e-11, -9.10568062e-12, -6.91622454e-12, ...,
         8.96156760e-12, -6.27301726e-12, -9.66544986e-13],
       [ 1.00307686e-10, -1.66703994e-11, -1.10054750e-10, ...,
         1.12350018e-10, -1.54337272e-11,  2.23625597e-11],
       ...,
       [-1.18554699e-09, -1.32580569e-09,  1.17279297e-09, ...,
        -4.93490693e-10,  5.27944355e-09,  4.86970464e-10],
       [-1.39517775e-09, -1.04426978e-09,  2.03556771e-09, ...,
        -1.12062248e-09,  2.76391743e-10,  1.14915535e-10],
       [-6.50262344e-11, -1.25571095e-10,  1.51342119e-10, ...,
        -4.65945928e-11, -4.77228326e-11,  4.47814286e-11]], dtype=float32)>

w1.assign_sub(w2)
<tf.Variable 'UnreadVariable' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169482, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>

w1
<tf.Variable 'Variable:0' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169482, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>

原文链接:https://stackoverflow.com//questions/71681453/tensorflow-assign-sub-not-updating-values

回复

我来回复
  • Tou You的头像
    Tou You 评论

    我不认为 op assign_sub 有问题,但是 w2 的值太小了:-0.00517749 – 2.11303495e-13 = -0.00517749

    2年前 0条评论