JiahuiYu / generative_inpainting

DeepFill v1/v2 with Contextual Attention and Gated Convolution, CVPR 2018, and ICCV 2019 Oral
http://jiahuiyu.com/deepfill/
Other
3.27k stars 788 forks source link

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

Open nichapman opened 3 years ago

nichapman commented 3 years ago

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?

erithwik commented 3 years ago

Were you able to make any progress on this?

buiduylinh commented 2 years ago

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

arnavmehta7 commented 2 years ago

I also need help guys!