关于pytorch搭建 GAN 生成对抗网络 出现 RuntimeError 错误

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [128, 1]], which is output 0 of TBackward, 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).

最终解决方法:在生成器更新的代码前,加多一一句代码:

prob_fake = D(fake)  # 判别网络对生成数据的判断

这句代码在前面也出现过,你只要复制多一句放在这里就好了

关于pytorch搭建 GAN 生成对抗网络 出现 RuntimeError 错误_第1张图片

你可能感兴趣的:(笔记,python,pytorch)