1
votes

I have a tensorflow graph which i saved as "saved_model.pb", using this code:

builder = tf.saved_model.builder.SavedModelBuilder('saved_location') 
with tf.Session(graph=tf.Graph()) as sess, open('logfile', 'wb') as log_file:
...
...
builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.SERVING])

i call builder.save() periodically. and see the saved_model.pb file being updated.

now when i try to import it for javascript, reference

>  tensorflowjs_converter --input_format=tf_saved_model 
 --output_format=tfjs_graph_model saved_location/  target

i get the following error:

File "/anaconda3/lib/python3.5/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 269, in convert_tf_saved_model model = load(saved_model_dir) File "/anaconda3/lib/python3.5/site-packages/tensorflow/python/saved_model/load.py",> line 108, in load

"Currently only SavedModels exported with tf.saved_model.save may be " NotImplementedError: Currently only SavedModels exported with tf.saved_model.save may be imported. Other SavedModels may eventually be supported via load().

  1. Where i am going wrong ?

  2. how can i convert the tensorflow graph model in a format that can be loaded in browsers for inference using javascript ?

Note: I am able to import the keras layers model to js and use it via loadLayersModel api but I am looking for a solution where i dont need to convert the entire code base to keras.

This exception should be fixed in more recent TF versions. You may have to use a nightly (pip install --upgrade tf-nightly or pip install --upgrade tf-nightly-2.0-preview). - Allen Lavoie