-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I load and use trained tfdf model in Java? #81
Comments
Hi AudreyW0201, We have not yet experimented using TF-DF in Java, so take what I say with a gain of salt. It seems, that TF-Java relies on the core TF runtime. More clearly, TF-Java uses the same implementation as TF-Python. This means that TF-DF models can likely run in TF-Java seemingly. The most likely issue (if any) will be to configure TF-Java to use the TF-DF model custom op (which is compatible with the TF runtime). In TF-Python, this is done automatically when importing the TF-DF library. In TF-Java, you might have to read the documentation / ask the TF-Java people. If you have an error, don't hesitate to post it here. Maybe we can help figuring out. Alternatively, depending on your and other needs, it could be interesting to implement the TF-DF inference code directly in Java. A simple version of this code will be small (probably less than 20 lines of code; c++ example). |
Thanks @achoum for your reply! I tried to use java's function I also contacted TF-Java people and tried the method but it doesn't work. For your second suggestion, I'm wondering if I cannot load the model successfully using java, how can I do inference on it? |
Hi AudreyW0201, @Craigacp mentioned to use I think the solution should look like: Download the TF-DF Pip library corresponding to your OS at: https://pypi.org/project/tensorflow-decision-forests/#files For example, if you are working on Linux, download any version that ends in Alternatively, the file should already be on your computer if you installed TF-DF in Python. Open the .whl file. This is a classical archive Zip file. For example, use 7zip. Extract the file `/tensorflow_decision_forests/tensorflow/ops/inference/inference.so" from the archive. In your Java code, before the byte[] opList = TensorFlow.loadLibrary(path_to_library_so);
assertTrue(opList.length > 0); with For the second solution, you (or a contributor) would have to post the inference code in Java. It is likely more work though. |
Thank you @achoum and @Craigacp for your detailed instruction! However, when I tried to load my model using
Thanks! |
Hey @AudreyW0201 , just following up to see if you've found a solution or workaround for the above issue? |
This looks like an issue in TF-DF. The TF C API requires that ops have shape inference functions, but this is disabled by the TF Python API (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/ops.py#L3211). As that call isn't part of the public TF C API we can't use it in TF-Java, and so need full shape inference for all ops. |
All the TF-DF ops have been augmented with ShapeInference (example). Could you try again ? :) |
Thank you achoum! #81 (comment) helped me! |
Awesome :) |
If I were running this on Dataflow how would I do the same |
Hi I trained my tfdf model in python and want to use it in java for production.
For conventional NN model, we can load the model from SavedModelBundle and get prediction.
I'm currently trying to use my tfdf model and wondering if current tfdf support loading and inference in Java? Will the model's graph and useful info be loaded? I'm still trying to load it and wondering if anyone has clue? Thank you so much!
The text was updated successfully, but these errors were encountered: