google-research / pegasus

Apache License 2.0
1.61k stars 316 forks source link

Convert checkpoints to .pb for eventual running on the web #149

Open AdityaJain1030 opened 3 years ago

AdityaJain1030 commented 3 years ago

Hi Team, I would like to convert the checkpoint files of pegasus to a saved_model format, that I can eventually convert to something usable in Tensorflow.js. However, when attempting to convert the model with the following code:

    import tensorflow as tf
    tf.reset_default_graph()
    saver = tf.train.import_meta_graph('/content/pegasus/ckpt/pegasus_ckpt/model.ckpt-1500000.meta')
    builder = tf.saved_model.builder.SavedModelBuilder('/content')
    with tf.Session() as sess:
        # Restore variables from disk.
        saver.restore(sess, '/content/pegasus/ckpt/pegasus_ckpt/model.ckpt-1500000.data-00000-of-00001')
        print("Model restored.")
        builder.add_meta_graph_and_variables(sess,
                                       ['tfckpt2pb'],
                                       strip_default_attrs=False)
        builder.save()

,I get the error NodeDef mentions attr 'index' not in Op<name=TPUReplicatedInput; signature=inputs:N*T -> output:T; attr=N:int,min=1; attr=T:type>; NodeDef: {{node input0}}. (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.). I assume this means I have an incorrect version of tensorflow, but I'm using version 1.15.2, which is also listed as a dependency in the requirements.txt.

Any help would be greatly appreciated.

agenius5 commented 3 years ago

Try running it in colab after installing all the requirements on colab. On colab, at least you won't have any version mismatch issues.

AdityaJain1030 commented 3 years ago

I am too, but I still have the same errors. Could you link a working example I could reference?