model.eval(),results are wrong?
The results of the inference model and the training model are inconsistent
I use this script:
from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'mobilenetv4_conv_small.e2400_r224_in1k',
pretrained=True,
features_only=True,
)
model = model.eval()
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
input_tensor = transforms(img).unsqueeze(0)
with torch.no_grad():
output_eval = model(input_tensor)
model.train()
with torch.no_grad():
output_train = model(input_tensor)
for o_eval, o_train in zip(output_eval, output_train):
if not torch.allclose(o_eval, o_train, atol=1e-5):
print("Outputs differ between train and eval mode.")
else:
print("Outputs are consistent between train and eval mode.")
And find that Outputs differ between train and eval mode. I wonder why, thanks!