Unable to load tensorflow model in Java that was originally created in python (file not found exception)

253 views Asked by At

I train a neural network in python 3.7 using tensorflow in version 1.14 and sonnet in version 1.34. After training, I want to export my neural network in order to use it in Java for predictions. Unfortunately, it always displays an error while trying to load the model in Java, saying the file cannot be found.

  • I double checked the model path a hundred times and it is correct (including transformation of slashes to backslashes because it runs on windows)
  • I tried several other export methods in python (including SavedModelBuilder and ModelSaver)

Below this you can see the Python code to export the model.

tf.saved_model.simple_save(sess,
                           path_graph_model_export_dir,
                           inputs=model_inputs, outputs={'sim': similarity})

This is the structure of the exported directory.

saved_model
---- saved_model.pb
---- variables
-------- variables.data-00000-of-00001
-------- variables.index

And the code in Java to load the model..

SavedModelBundle model = SavedModelBundle.load(modelPath, "serve")

results in this exception.

2019-09-17 10:59:03.905538: I tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: saved_model
2019-09-17 10:59:03.905997: I tensorflow/cc/saved_model/loader.cc:311] SavedModel load for tags { serve }; Status: fail. Took 457 microseconds.
org.tensorflow.TensorFlowException: Could not find SavedModel .pb or .pbtxt at supplied export directory path: saved_model

I cannot figure out why this exception appears when the file is clearly located at this directory. I hope someone can help me with this. Thanks in advance!

0

There are 0 answers