generative_inpainting icon indicating copy to clipboard operation
generative_inpainting copied to clipboard

Unable to restore model from checkpoint format to SavedModel format and convert to Tensorflow.js format

Open nichapman opened this issue 4 years ago • 3 comments

I'm trying to convert this model to a tensorflow.js format so I can perform in-browser client-side inference of the model. To do this, the model needs to be in the SavedModel format as specified here.

By using a simple python script to restore the model and save it in this SavedModel format, I've managed to obtain a .pb file as expected:

import tensorflow as tf

trained_checkpoint_prefix = 'models/snap-0'
export_dir = os.path.join('export_dir', '0')

graph = tf.Graph()
with tf.compat.v1.Session(graph=graph) as sess:
    # Restore from checkpoint
    loader = tf.compat.v1.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
    loader.restore(sess, trained_checkpoint_prefix)

    # Export checkpoint to SavedModel
    builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
    builder.add_meta_graph_and_variables(sess, [tf.saved_model.SERVING], strip_default_attrs=True)
    builder.save()

However, when I try to then convert this SavedModel format with tfjs converter, it seems that it expects some SignatureDefs to be saved, which have been lost in the conversion process so I get these error messages:

RuntimeError: MetaGraphDef associated with tags 'serve' could not be found in SavedModel. ValueError: Signature 'serving_default' does not exist. The following signatures are available: KeysView(_SignatureMap({})) MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: #no output

It seems I need to provide some sort of signature for the inputs and outputs of the network, although I'm really unfamiliar with this process so am unsure how I would do so.

Does anybody have an insight into how I could solve this?

nichapman avatar Feb 06 '21 18:02 nichapman

Were you able to make any progress on this?

erithwik avatar Sep 14 '21 20:09 erithwik

i have the same problem @nichapman Have you found the solution yet?

buiduylinh avatar Apr 14 '22 09:04 buiduylinh

I also need help guys!

arnavmehta7 avatar Oct 11 '22 06:10 arnavmehta7