Hello,
When I try to store my model using keras, tensorflow or pytorch, I get a weird error message telling me I don't have the permission to write in the desired folder. I am using straight lines of code from the Documentation:
model_key = "model"
file_name = qb.ObjectStore.GetFilePath(model_key)
joblib.dump(model, file_name)
This is the error that I am getting:
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
Cell In[31], line 1
----> 1 joblib.dump(model, file_name)
File /opt/miniconda3/lib/python3.8/site-packages/joblib/numpy_pickle.py:552, in dump(value, filename, compress, protocol, cache_size)
550 NumpyPickler(f, protocol=protocol).dump(value)
551 elif is_filename:
--> 552 with open(filename, 'wb') as f:
553 NumpyPickler(f, protocol=protocol).dump(value)
554 else:
PermissionError: [Errno 13] Permission denied: '/home/jovyan/work/storage/model'
Thank you very much for your help!
Maxime
Mia Alissi
Hello Maxime,
The error message you're seeing is related to file permissions in your local environment, not with QuantConnect's platform. The code you're using is intended for use within the QuantConnect environment, where the
ObjectStore
is a special storage location provided by QuantConnect.When you call
qb.ObjectStore.GetFilePath(model_key)
, it returns a file path where the model will be stored in the QuantConnect environment. However, when you're running this code on your local machine, it seems like the path returned byGetFilePath
is not writable in your local environment, hence thePermissionError
.If you're trying to save your model locally, you can simply specify a local file path where you have write permissions. For example:
If you're trying to use QuantConnect's
ObjectStore
to save your model for use in a QuantConnect algorithm, you should run your code in the QuantConnect environment, either in a backtest or a research notebook.Please refer to the QuantConnect Documentation for more details on how to use the
ObjectStore
in QuantConnect.I hope this helps! Let me know if you have any other questions.
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.
Maxime Rosello
Hello and thank you for your answer,
However, I am not coding on my local environement but on QuantConnect's platform - and I am getting this error online, on the Jupyter notebook on the platform.
Kind regards,
Maxime
Mia Alissi
Hello Maxime,
I apologize for misunderstanding your initial question. If you're working in the QuantConnect research environment and encountering this issue, it seems like there might be a problem with the way the model is being saved.
In the QuantConnect environment, you should use the
SaveBytes
andReadBytes
methods of theObjectStore
to save and load your model. Here's an example of how you can do this with a scikit-learn model:And here's how you can load the model back from the
ObjectStore
:Please give this a try and let me know if you're still encountering issues.
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.
Maxime Rosello
Hello,
The issue remains, it seems that I can save and load the model remaining in the same Jupyter notebook, but as soon as I want save the model from the Jupyter notebook and load it in the .py file (same project), the model doesn't exist.
Mia Alissi
Hello Maxime,
Based on the information provided, it seems you're able to successfully save the model in the Jupyter notebook environment using QuantConnect's
ObjectStore
but are encountering issues when trying to access it from a.py
file within the same project. This scenario typically involves ensuring that the model is correctly saved and that the.py
file is correctly attempting to access the model.While the specific code to save and load models using
ObjectStore
in QuantConnect's environment was not directly provided in the extracts, the general approach to troubleshoot this issue involves a few steps:Ensure Model is Saved Correctly: In your Jupyter notebook, after saving the model to the
ObjectStore
, verify that it exists by checking the return value of theSaveBytes
orSave
method (depending on how you're saving the model). QuantConnect'sObjectStore
should returnTrue
if the operation was successful.Check ObjectStore Availability: In your
.py
file, before attempting to load the model, check if the model key exists in theObjectStore
. You can use theContainsKey
method for this purpose. This step is crucial to ensure that the model was saved correctly and is accessible.Load the Model Correctly: When loading the model in your
.py
file, ensure you're using the correct method (ReadBytes
orRead
depending on how the model was saved) and that you're correctly handling the data to reconstruct the model object.Since the specific code snippets for saving and loading models using
ObjectStore
were not provided in the extracts, I recommend referring to the QuantConnect documentation on Storing Data with ObjectStore for the exact methods and usage.If you're following these steps and still facing issues, it might be helpful to review any error messages or logs for more insights. Additionally, considering reaching out on the QuantConnect forum or support for more targeted assistance, especially if there might be a platform-specific issue at play.
I hope this guidance helps you troubleshoot the issue. If you have more specific error messages or code snippets, feel free to share them for more detailed assistance.
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.
Maxime Rosello
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!