首页 > 其他 > 详细

【E-03】RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

时间:2020-07-26 23:10:04      阅读:587      评论:0      收藏:0      [点我收藏+]

这个是因为没有将requires_grad设为True,l=LOSS(out,label)中的l默认是requires_grad为false,这个l其实也是一个张量Tensor类型,将其的requires_grad改为True后,使用backward函数就可以得到requires_grad为True的所有参数的梯度。

技术分享图片

上面的loss = loss.requires_grad_(),是我添加的部分。

本错误纠正的参考的内容如下:

技术分享图片

? ?

参考文献https://cloud.tencent.com/developer/article/1161882

【E-03】RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

原文:https://www.cnblogs.com/yifanrensheng/p/13381934.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!