How to save and load a Q-Learning Agent
-
11-12-2020 - |
题
I know this may sound nooby, but how do I save a Deep Q-Learning agent's progress? I mean when I close at i.e. episode 500 when my agent is trained and I restart (in my case a pygame) my agent is going to load its data and it will continue with its progress ( does not start again very stupid :) ). How can it be done?
If you need more details/clarification, feel free to ask! :)
Thanks for any answer! I really do appreciate it!
解决方案
To save a model's state, it is enough to save the model's parameters. If you are using Torch, then you can save it as follows torch.save(model.state_dict(), path_to_save).
When you want to resume training with a saved model, you would have to first create the model instance, and then you can use model.load_state_dict(torch.load(path_of_saved_model)) to update the new instance with the parameter values of the saved model.
You can find more reference here: https://pytorch.org/tutorials/beginner/saving_loading_models.html
There will be something similar for Tensorflow or any other framework that you use.
You can also have an evaluation function that evaluates how good your model is after a certain number of iterations, and save the one which performs the best.
Hope that helps!