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

这个是因为没有将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

posted @ 2020-07-26 20:37  忆凡人生  阅读(16049)  评论(0编辑  收藏  举报