Hello community,
I ran into the following problem. In the research notebook, I trained a Keras sequential model, then test and save It.
y_org = original_model.predict(X_test)
model_str = json.dumps(serialize_keras_object(original_model))
model_key = 'original_model'
qb.ObjectStore.Save(model_key, model_str)
Following this, I call the model from ObjectStore just like the Documentation says.
if qb.ObjectStore.ContainsKey(model_key):
model_str = qb.ObjectStore.Read(model_key)
config = json.loads(model_str)['config']
model_saved = Sequential.from_config(config)
To be sure that everything went well, I tested both models in the same notebook and with the same data (X_test).
original_model.predict(X_test), model_saved.predict(X_test)
But to my surprise, the results were different, additionally, every time that I call the model_saved from the ObjectStore the results change. It returns the same results as my original_model only when I train It again (clearly setting a specific seed), but I want to save the trained model so I do not have to train It on the backtest. Can someone tell me what I am doing wrong?
Thanks in advance.
Adam W
The `from_config()` method only reconstructs a new NN with the same architecture, so the weights are randomly initialized not the trained ones. The way I typically handle model saving is:
Andres tello
Hero!!! Thank you Adam, that did the job.
Andres tello
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!