java icon indicating copy to clipboard operation
java copied to clipboard

How to load a saved model which is saved from python and predict in new tensorflow java ?

Open DachuanZhao opened this issue 3 years ago • 3 comments

System information

Describe the documentation issue The java document only contains a install chapter , could you please add a load saved model and predict chapter ?

DachuanZhao avatar Aug 09 '21 02:08 DachuanZhao

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.

Craigacp avatar Aug 09 '21 03:08 Craigacp

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?

luobotaxinghu avatar Aug 19 '21 12:08 luobotaxinghu

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.

Craigacp avatar Aug 19 '21 14:08 Craigacp