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
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:pytorch 使用的时候的 model.train() 和 model.eval() - Python技术站