1
votes

I have trained a seq2seq language translation model on tensorflow and save in the form of checkpoints with the following files in my train folder.

  • translate.ckpt-157450.data-00000-of-00001
  • translate.ckpt-157450.index
  • translate.ckpt-157450.meta and
  • checkpoint file

Now, I want to convert it to a protobuf file (.pb) for deployment purposes. Here is some code that I am using:

import tensorflow as tf
meta_path = "/home/i9/L-T_Model_Training/01_Apr_model/train/translate.ckpt-157450.meta"
with tf.Session() as sess:
saver = tf.train.import_meta_graph(meta_path)
saver.restore(sess, tf.train.latest_checkpoint('.'))
output_node_names =[n.name for n in tf.get_default_graph().as_graph_def().node]
frozen_graph = tf.graph_util.convert_variables_to_constants(sess, sess_graph_def, output_node_names)
with open("output_graph.pb", "wb") as f:
    f.write(frozen_graph.SerializeToString())

I am running this code inside my train folder. It shows me an error: ValueError: Can't load save_path when it is None.

I also tried freeze_graph.py script but could not get the model.

1
Yes.. I also tried that code but didn't work out for me. - Sandeep
Try: saver.restore(sess, 'path/to/model.ckpt') - Krunal V
How can I find output node name of my model? - Sandeep
you can use this link or try this answer. - Krunal V

1 Answers

0
votes

I did it for a NVIDIA/OpenSeq2Seq trained model, don't know if it is your case.

I created a gist file with the relevant code.

Basically, the sequence I did was:

  1. Load the model
  2. Call build_trt_forward_pass_graph (it's the only way I could get it working)
  3. Get the right output node
  4. Fix batch norm nodes
  5. Freeze the graph
  6. Save it

Please let me know if you have other ideas and if you try it, share the results with us.

Regards