第五章代码里更新权重的语句,不知道为啥例程不会错但是我自己写就报错了:
代码:
grads = tape.gradient(loss, [w1, b1, w2, b2, w3, b3]) # derivativefor p, g in zip([w1, b1, w2, b2, w3, b3], grads):p.assign_sub(lr * g) # update the parameters
Traceback (most recent call last):File "train.py", line 66, in <module>main()File "train.py", line 58, in mainp.assign_sub(lr * g) # update the parametersAttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'assign_sub'
第五章代码里更新权重的语句,不知道为啥例程不会错但是我自己写就报错了: 代码:
grads = tape.gradient(loss, [w1, b1, w2, b2, w3, b3]) # derivative
for p, g in zip([w1, b1, w2, b2, w3, b3], grads):
p.assign_sub(lr * g) # update the parameters
Traceback (most recent call last):
File "train.py", line 66, in <module>
main()
File "train.py", line 58, in main
p.assign_sub(lr * g) # update the parameters
AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'assign_sub'