标签: machine-learning pytorch
我需要计算网络输出相对于输入的梯度(而不是损耗),但是出现错误grad can be implicitly created only for scalar outputs。我正在尝试重现this paper中描述的内容,我需要我提到的渐变来执行步骤7
grad can be implicitly created only for scalar outputs
这就是我想要做的:
out = netD(input).view(-1) out.backward(retain_graph=True) grad = input.grad