In my case, it was the data. The input to the model was changing on each run. At training time, I had set randomized data transforms which were appropriate for training. But, of course, this introduced randomness as I prepared the data for inference. So I changed
data_transforms = {
"train": transforms.Compose(
[
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
]
),
to:
data_transforms = {
"train": transforms.Compose(
[
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
which ensured consistency.