I am encountering an issue when trying to load a Keras model in a Lean CLI algorithm run in a Docker container. The error message I receive is:
No file or directory found at C:\Users\beres\GRU\models\saved_model.pb
This error arises when I call the tf.keras.models.load_model function in my algorithm:
self.model = tf.keras.models.load_model('C:\\Users\\beres\\GRU\\models\\saved_model.pb')
The GRU directory is the lean cli project folder.
I have confirmed that the saved_model.pb file does exist at the specified path on my host machine. The model files are located in C:\Users\beres\GRU\models\ on my local machine, and they include saved_model.pb as well as the variables located in the variables subdirectory.
However, it seems that the Docker container running the Lean CLI does not have access to this directory. I understand that Docker containers are isolated and cannot access files outside of specific shared paths, but I am unsure how to make this directory available to the Lean CLI environment.
Both my current Lean CLI environment and my training environment used the same TensorFlow and Keras versions:
TensorFlow version: 2.12.0
Keras version: 2.12.0
I would appreciate any advice on how to correctly share my model files with the Docker container so that they can be loaded by the algorithm. Thank you for your help!
Mia Alissi
To load your Keras model in a Lean CLI algorithm run in a Docker container, you need to make sure that the Docker container has access to the directory where your model is stored.
In your case, the model files are located in
C:\Users\beres\GRU\models\
on your local machine. This directory needs to be shared with the Docker container.Here's how you can do it:
C:\Users\beres\GRU\models\
to the list.This process is mentioned in the Getting Started and Troubleshooting sections of the Lean CLI documentation.
Also, remember that the data directory is the only local directory that is mounted into all Docker containers ran by the CLI, so it must contain all the local files you want to read from your algorithms. You can get the path to this directory in your algorithm using the
Globals.DataFolder
variable. This is mentioned in the Format and Storage section of the Lean CLI documentation.So, in your algorithm, you should load your model like this:
This way, your algorithm will be able to access and load the model from the correct directory.
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.
Jack beresford
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!