報錯RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed


訓練GAN net時經常遇到這個問題

RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling .backward() or autograd.grad() the first time.

翻譯一下就是 第二次嘗試在圖中向后遍歷時,保存的臨時變量已經被釋放

顯然,

GAN中有一個變量存在於gen和disc之間,就是fake

加上detach() 就行

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM