How to save and load a trained model?
See original GitHub issueHi, after I learn a model I save it via
model.learn(total_timesteps=100000)
model.save("./data/PPO_MultiBinScaling.zip")
In another session I load it and apply the model on the same data it has been trained on (test=train) but receive completely different results.
model.load("./data/PPO_MultiBinScaling.zip")
Also I observed that the results differ between test (on train data) between trials.
Are there some strange seed somewhere, which make it inconvenient to reproduce the result after learning?
Thank you very much!
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Save and load models | TensorFlow Core
Model progress can be saved during and after training. This means a model can resume where it left off and avoid long training...
Read more >How to Save and Load Your Keras Deep Learning Model
You can save your model by calling the save() function on the model and specifying the filename. The example below demonstrates this by...
Read more >Save and load models in Tensorflow - GeeksforGeeks
Save and load models in Tensorflow ; Code to create the model; The trained weights for the model ; Using the inbuilt function...
Read more >Saving and Loading Models - PyTorch
When loading a model on a GPU that was trained and saved on CPU, set the map_location argument in the torch.load() function to...
Read more >Save and Load a Model with TensorFlow's Keras API
Saving and loading the model in its entirety ... If we want to save a model at its current state after it was...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yes, we have a warning about that in the “saving/loading” example in our doc: https://stable-baselines3.readthedocs.io/en/master/guide/examples.html#basic-usage-training-saving-loading
" load method re-creates the model from scratch and should be called on the Algorithm without instantiating it first, e.g. model = DQN.load(“dqn_lunar”, env=env) instead of model = DQN(env=env) followed by model.load(“dqn_lunar”). The latter will not work as load is not an in-place operation. If you want to load parameters without re-creating the model, e.g. to evaluate the same model with multiple different sets of parameters, consider using set_parameters instead. "
I had exactly the same issue! Thanks for the answers!😃