Hello Pytorchers,
I am having an issue with trained model. In training, model after time performed very good, but after it was saved and loaded (state_dicts), it could not even give 1 valid prediction.
Are you using the same data to evaluate your model?
How was the training and validation error?
Did you make sure to call model.eval() before evaluating the model? Your current model probably doesn’t need it, because it doesn’t contain any Dropout or BatchNorm, but it’s recommended anyway.
Thanks for your answer, Ptrblck!
I am creating AI player and train it by playing the game.
Yes, first I train it with the best move possible. After that I use predict and check if it is correct. If not, repeat, else move and continue with game. In training, after like 15 generations ( 50 * 15 * ~7000 moves ) I reach first models with 100% accuracy.
Yes, i tried model.eval(), it does not change anything.
Hi SimonW,
There is nothing special with my save&load.
I save model in hardcoded times in data/time/modelname.pkl
# Save the Model
end = time.time()
for i in range(6):
if (end - self.start >= self.savedTimes[i] and not self.saved[i]):
self.saved[i] = True
os.makedirs(os.path.dirname('data/' + time.strftime("%Y%m%d-%H%M%S", time.localtime(self.start)) + str("/") + self.savedFileNames[i]), exist_ok=True)
torch.save(self.player.state_dict(), 'data/' + time.strftime("%Y%m%d-%H%M%S", time.localtime(self.start)) + str("/") + self.savedFileNames[i])
You’re saving torch.player., but restoring into state.model. There’s nothing to say that that is not correct, but it seems … unintuitive/inconsistent. Might be worth making these names consistent, just in case this is masking the actual bug somehow?