1

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.

Sandeep
  • 369
  • 1
  • 5
  • 16
  • Possible duplicate of [Tensorflow: How to convert .meta, .data and .index model files into one graph.pb file](https://stackoverflow.com/questions/45864363/tensorflow-how-to-convert-meta-data-and-index-model-files-into-one-graph-pb) – Krunal V Apr 09 '19 at 08:50
  • Yes.. I also tried that code but didn't work out for me. – Sandeep Apr 09 '19 at 11:15
  • Try: `saver.restore(sess, 'path/to/model.ckpt')` – Krunal V Apr 09 '19 at 13:05
  • How can I find output node name of my model? – Sandeep Apr 10 '19 at 07:16
  • you can use [this link](https://lutzroeder.github.io/netron/) or try [this](https://stackoverflow.com/questions/43517959/given-a-tensor-flow-model-graph-how-to-find-the-input-node-and-output-node-name) answer. – Krunal V Apr 10 '19 at 08:14
  • @kruxx, I tried netron with .meta file but it didn't work out for me and also I do not have .pb model. I want to find input and output node name using checkpoint file. I tried [n.name for n in tf.get_default_graph().as_graph_def().node] with checkpoint file but didn't get the name of input and output node. – Sandeep Apr 10 '19 at 09:22

1 Answers1

0

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

feroult
  • 493
  • 5
  • 12