Loading model, test accuracy drops


#1

I have a PyTorch model that has test accuracy of about 97%. I save it using torch.save(my_model.state_dict(), PATH) , but whenever I try to reload it using my_model.load_state_dict(torch.load(PATH)) and test it on the same data using test_fn(my_model) my test accuracy goes down to about 0.06%. The same thing happens if I use test_fn(my_model.eval()) . Is there an extra step I need to take?


#2

Could you post a small executable code snippet, so that we can have a look?


#3
my_model = GraphConv(w2i, p2i, l2i, r2i, s2i, words, pos, lems, 512, 512, 3) ## Initialise model & params
my_model.cuda()
loss_function = nn.NLLLoss()
optimizer = optim.Adam(my_model.parameters(), lr=0.001)

for epoch in range(15):
    ...   ### Apply training steps
    print(test_fn(my_model))  ### Will be over 95%
    torch.save(my_model.state_dict(), PATH)

...
my_model2 = GraphConv(w2i, p2i, l2i, r2i, s2i, words, pos, lems, 512, 512, 3) ## Initialise new model
my_model2.load_state_dict(torch.load('PATH'))
print(test_fn(my_model2))  ### Is about 0.06%