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