Kaustubh_Kulkarni:

Instead of model.eval(), I have used all code inside a torch.no_grad() block.


Note that these calls do not perform the same operations.
model.eval() changes the behavior of some layers (e.g. batchnorm layers will use their running stats and dropout will be disabled), while no_grad() disallows the gradient calculation and saves memory by not storing intermediate tensors, so you cannot use one instead of the other.