錯誤:RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [6,128,60,80]], which is output 0 of SoftmaxBackward, is at version 1; 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).
變量的計(jì)算中包含了inplace操作,在SoftmaxBackward出。
報(bào)錯位置:損失反向傳遞時,猜測可能在計(jì)算梯度時發(fā)生錯誤。錯誤原因可能是inplace的原因。
方法1:將inplce=True的地方全部改為False,主要是在ReLU處,經(jīng)過修改發(fā)現(xiàn)對我沒有用。
方法2:將所有的a+=b的地方改為a=a+b,對我沒有用。
方法3:將代碼中nn.Sigmoid函數(shù)刪除掉,用其他的歸一化方法。解決問題。文章來源:http://www.zghlxwxcb.cn/news/detail-714240.html
方法4:參考別的大佬文章,都是sigmoid函數(shù)處出錯,大佬鏈接因?yàn)槲业拇a已經(jīng)運(yùn)行起來了,就不想暫停,下次再跑試驗(yàn)一下這個方法。文章來源地址http://www.zghlxwxcb.cn/news/detail-714240.html
到了這里,關(guān)于解決RuntimeError: one of the variables needed for gradient computation has been modified by an inplace的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!