java
java copied to clipboard
How to load a saved model which is saved from python and predict in new tensorflow java ?
System information
- TensorFlow version: 2.5.0
- Doc Link: https://www.tensorflow.org/jvm/install
Describe the documentation issue
The java document only contains a install
chapter , could you please add a load saved model and predict
chapter ?
You can see a short example of loading in a saved model and executing a function from it in the TF-Java test suite (https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SavedModelBundleTest.java#L285), and there are many more examples of that in the TF-Java models repo (https://github.com/tensorflow/java-models/tree/master/tensorflow-examples/src/main/java/org/tensorflow/model/examples).
We do need to improve the public facing docs, as admittedly these things are not easy to find if you start on tensorflow.org.
You can see a short example of loading in a saved model and executing a function from it in the TF-Java test suite (https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SavedModelBundleTest.java#L285), and there are many more examples of that in the TF-Java models repo (https://github.com/tensorflow/java-models/tree/master/tensorflow-examples/src/main/java/org/tensorflow/model/examples).
We do need to improve the public facing docs, as admittedly these things are not easy to find if you start on tensorflow.org.
This example TF-Java test suite load from a dir, have some example that load byte[] of .pb to SavedModelBundle?
You can't do that as the SavedModelBundle
format is a pb along with a checkpoint of the variables (well, it's conceptually a checkpoint). If you've got a frozen graph from TF 1 then you can load that directly as a GraphDef
and import it into a Graph
.