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)
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
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?
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