Hi,
I am having some difficulty with getting my keras model loaded from ObjectStore. The Keras model was saved from the research environment. Specifically I am having trouble with getting the file location of the model. I have used just the original key it was saved with as well as {self.ProjectId}/my_key. However, neither of these work. Additionally, I tried moving the loading of the model from initialization into my EveryDayBeforeClose() function and it seemed to grab the model only on one iteration then failed to locate the file directory.
My model is saved to /home/jovyan/work/storage/MyFirstModel when I check within the research notebook. However, according to a backtest when calling ObjectStore from my main.py it is looking in QuantConnect/Backtesting/Storage/MyFirstModel and not locating it.
Thanks
Mia Alissi
Hi Chase,
It seems like you're having trouble loading your Keras model from the ObjectStore. Here are the steps you should follow to load your model:
ContainsKey
method with the model key. This method returns a boolean that represents if themodel_key
is in the ObjectStore. If the ObjectStore does not contain themodel_key
, you should save the model using themodel_key
before you proceed.GetFilePath
method with the model key.load_model
method with the file path.Please note that the file path you get from the
GetFilePath
method is the path where the model is stored in the ObjectStore, not the local file system. The model should be saved to the ObjectStore in the research environment before you can load it in the algorithm.If you're still having trouble, it might be helpful to print out the file path you get from the
GetFilePath
method to make sure it's correct.I hope this helps! Let me know if you have any other questions.
Sources:
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.
Chase Joyal
Hi,
I have tried the above and I get an error stating the model is not an attribute as the above is not actually locating my model file from its key. However, I can find the model in the Organization/Object Store tabs.
Mia Alissi
Hi Chase,
I'm sorry to hear that you're still having trouble. If you're sure that the model is in the Object Store (as you can see it in the Organization/Object Store tabs), then the issue might be with the key you're using to access it.
The key you use to retrieve the model from the Object Store should be the same as the one you used to save it. If you're using a different key or if there's a typo in the key, the
ContainsKey
method will returnFalse
and you won't be able to get the file path to the model.Here's how you can check if a key exists in the Object Store and get the file path to the model:
If the key does not exist, you'll need to check the key you're using and make sure it's the same as the one you used to save the model.
Once you have the correct file path, you can load the model with Keras'
load_model
function:I hope this helps! Let me know if you have any other questions.
Sources:
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.
Alexandre Catarino
Hi Chase Joyal
We have fixed the issue with the Object Store. Please retry and let us know if it happens again.
We apologize for the inconvenience.
Best regards,
Alex
Chase Joyal
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!