tensorflow / decision-forests

A collection of state-of-the-art algorithms for the training, serving and interpretation of Decision Forest models in Keras.
Apache License 2.0
663 stars 110 forks source link

KeyError: 'SimpleMLLoadModelFromPathWithHandle' while loading model #108

Closed jaya-shankar closed 2 years ago

jaya-shankar commented 2 years ago

Hey 👋,

I have been trying to load my saved Random Forest model for my flask application, I referred to the following article https://www.tensorflow.org/tfx/tutorials/serving/rest_simple and but when I load I get this error **FileNotFoundError: Op type not registered 'SimpleMLLoadModelFromPathWithHandle**' in binary running on b5d47309d41b. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.)tf.contrib.resamplershould be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. You may be trying to load on a different device from the computational device. Consider setting theexperimental_io_deviceoption intf.saved_model.LoadOptionsto the io_device such as '/job:localhost'.

I used the following code to save: model.save("/content/DSS_project/my_saved_model")

To load in another colab after uploading the saved model used the following code loaded_model = keras.models.load_model('/content/DSS_project/my_saved_model') loaded_model.compile(metrics=['accuracy'])

I ran the following code mentioned in the above article: !saved_model_cli show --dir "/content/DSS_project/my_saved_model" --all and got the same error as the above

To replicate the error here is my colab code : https://colab.research.google.com/drive/1CvUxWnmesTcTCSfki-8QLs5BjqVE1jRP?usp=sharing By running all cells you can see the total error message

Thank you!

rstz commented 2 years ago

Hi, thank you for the report and for sharing the colab, we will have a look at it. From a very initial look at the colab, I think root_path needs to become root_path = "/content/DSS_project/sample-ds" in order find filefinal_combined_df.csv`, is that correct?

jaya-shankar commented 2 years ago

hey @rstz yeah! apologies, I forgot to change the rooth_path, you are right! I have changed the root_path

rstz commented 2 years ago

What you're trying to do might require a bit of work.

TF-DF uses custom Tensorflow ops (e.g. SimpleMLLoadModelFromPathWithHandle). Statically compiled binaries such as saved_model_cli or TF Serving need to be recompiled with TF-DF as a dependency in order to recognize these ops. We have instructions on how to do this here: https://www.tensorflow.org/decision_forests/tensorflow_serving

rstz commented 2 years ago

Closing this since there exist instructions to partly address this issue.