RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn (from pytorch)
Pytorch中, tensor需要定义成require_grad的类型才能求梯度。
可以在定义变量的时候加上“requires_grad=True”
或者,某tensor, tensor_X = tensor_X.requires_grad_()
转载
2019-09-18 15:03:38 ·
5916 阅读 ·
0 评论