Accuracy decrease after load the saved model

Hi. Can you tell me why accuracy of my model decreases when I save and load it to predict. My accuracy after training is about 88%

I use resnet model of pytorch

model_ft = models.resnet34(pretrained=True)
num_ftrs = model_ft.fc.in_features

# replace the last fc layer with an untrained one (requires grad by default)
model_ft.fc = nn.Linear(num_ftrs, 216)
model_ft = model_ft.to(device)

# uncomment this block for half precision model
# """
model_ft = model_ft.half()


for layer in model_ft.modules():
    if isinstance(layer, nn.BatchNorm2d):
        layer.float()
# """
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model_ft.parameters(), lr=0.01, momentum=0.9)

lrscheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='max', patience=3, threshold = 0.9)

I use this code to save the model

PATH = './car_classifier.pth'
torch.save(model_ft.state_dict(), PATH)

then I load it with


Thanks in advanced!

My guess is here model accuracy was depend on the batches that go through the testing phase so instead of performing once test for 5 time and average it then save the model and then redo it

Sorry I don’t really understand what you want me to do. Can you make it more clearly

I use this code to transform the input images.
image

How large is the decrease in accuracy?
Are you using the same data for both use cases or are you loading another dataset for the validation use case?

I trained the model on jupyter note book and get 88% validation accuracy. Then I use it to predict some random images and it go well. After that I save and load it to my web app to predict. But none of them is correct. Is that because of the way I load my model to the web app?

can you please help me with it

Hi
I Have the same problem with ResNet50?
my validation and train accuracy decreased 50% when I loaded the saved model with load_state_dict() function !!!
However when I save training results everything was OK