pytorch 使用的時候的 model.train() 和 model.eval()


Do need to use model.eval() when I test?
Sure, Dropout works as a regularization for preventing overfitting during training.
It randomly zeros the elements of inputs in Dropout layer on forward call.
It should be disabled during testing since you may want to use full model (no element is masked)

使用PyTorch進行訓練和測試時一定注意要把實例化的model指定train/eval,eval()時,框架會自動把BN和DropOut固定住,不會取平均,而是用訓練好的值,不然的話,一旦test的batch_size過小,很容易就會被BN層導致生成圖片顏色失真極大

model.train() :啟用 BatchNormalization 和 Dropout
model.eval() :不啟用 BatchNormalization 和 Dropout

參考:
https://blog.csdn.net/qq_23304241/article/details/99604739


免責聲明!

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



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