one of the variables needed for gradient :.....with torch.autograd.set_detect_anomaly(True).

一个很神奇的错误:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [16, 8, 1024]], which is output 0 of LeakyReluBackward1, is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
正常调试的时候正常,但是运行起来就报错
one of the variables needed for gradient :.....with torch.autograd.set_detect_anomaly(True)._第1张图片
开始百度说是激活函数的inplace=设置要为False,改过后发现好像不行。
通过仔细检查发现是在同一个位置写了两次激活函数导致梯度无法反向传播。。。。

你可能感兴趣的:(报错可能的解决方案,python,人工智能,计算机视觉,深度学习)