Why EfficientNet same model return different predictions
!pip install efficientnet_pytorch -q


import torch 
import torch.nn as nn
import efficientnet_pytorch as efn



device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device



model = efn.EfficientNet.from_name('efficientnet-b0')
model = model.to(device)

img = torch.ones((2, 3, 680, 680))*0.5
img = img.to(device)
preds1 = model(img)
preds2 = model(img)
preds3 = model(img)

print(preds1[0][0])
print(preds2[0][0])
print(preds3[0][0])

del model, img, preds1, preds2, preds3

And preds1, preds2, and preds3 are different. I am confused about this point, model is same and input is same, why predictions are different?
tensor(0.2599, grad_fn=&lt;SelectBackward&gt;)
tensor(0.1364, grad_fn=&lt;SelectBackward&gt;)
tensor(0.1263, grad_fn=&lt;SelectBackward&gt;)


Wow, solved! I checked the Efficientnet-pytorch source code and suddendly found I should turn the model to eval() mode.
Now the predictions are same!!
model = efn.EfficientNet.from_name('efficientnet-b0')
model = model.to(device)
_ = model.eval()  ## hey, look here!!

img = torch.ones((2, 3, 680, 680))*0.5
img = img.to(device)
preds1 = model(img)
preds2 = model(img)
preds3 = model(img)

print(preds1[0][0])
print(preds2[0][0])
print(preds3[0][0])

