Doubt regarding usage of model.eval() function in renet18 architecture

here is the code snippet that I used to calculate the error and accuracy of the data. Not sure if the accuracy logic is correct or not.

  1. I read that model.eval() helps to change the functionality of dropout and batch normalization but not sure what it really means.
  2. Can I calculate error and accuracy of renet18 model without using model.eval()?

The behaviour of certain layers changes when the model is in inference mode i.e. model.eval(). For dropout, this means the dropout layer won’t drop out any neurons. For batch normalization, this means the layer’s summary statistics won’t be updated with the given data. You can calculate your metrics without putting the model in evaluation mode, but there is no good reason to do that.

To try it yourself: if you’re not using model.eval(), you’ll notice that your evaluation metrics (and loss) will change across multiple runs of your evaluation script.