What is the meaning of the training attribute?model.train() and model.eval()?

Hi,
When we train,we will use model.train(),so dropout and batch norm layer will work ? When we test,we will use model.eval(),so dropout and batch norm layer do not work ? I see in the model.eval(),it set all children’s attribute of training to False.Does this attribute only affect the dropout and batch norm layer?So,why model.eval() will also set the attribute of convolution、relu、and pooling layers?

1 Like

The method will call eval recursively on all modules just in case their behavior differs between the training and evaluation case. This approach is useful if you are writing a custom layer which also switches the behavior.

Dropout will be disabled during eval, so that nothing will be dropped, while BatchNorm will use the running estimates to normalize the data instead of the batch statistics.

1 Like