Sobes.tech
Middle

What will happen if you do not call model.eval() during validation?

sobes.tech AI

Answer from AI

If you do not call model.eval() during validation in PyTorch, the model remains in training mode (train), which leads to the following consequences:

  • Layers like Dropout and BatchNorm will behave as during training. Dropout will randomly zero parts of the input, and BatchNorm will use batch statistics instead of running averages.
  • This can lead to unstable and incorrect validation results because the model behaves differently than during inference.
  • As a result, quality metrics (e.g., accuracy or error) will be distorted and do not reflect the true performance.

Therefore, it is important to switch the model to evaluation mode using model.eval() before validation to ensure correct behavior of all layers and obtain reliable results.