问题:one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4, 2, 224, 224]], which is output 0 of SigmoidBackward, is at version 2; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
解决方法:
在确定ReLU 中inplace参数设置为False之后
应该将
# 下面的操作也是inplace操作
feat_map_a[feat_map_a >= 0.5] = 1
feat_map_a[feat_map_a < 0.5] = 0
替换成
mask = torch.round(feat_map_a)