# This file is useful for reading the contents of the ops generated by ruby.
# You can read any graph defination in pb/pbtxt format generated by ruby
# or by python and then convert it back and forth from human readable to binary format.

import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.platform import gfile
import sys

if len(sys.argv) != 3:
    print("{} pb_path pbtxt_path".format(sys.argv[0]))

pbtxt_path = sys.argv[1]
pb_path= sys.argv[2]

print(tf.__version__)
def pbtxt_to_graphdef(pbtxt_path,pb_path):
      with open(pbtxt_path, 'r') as f:
          graph_def = tf.GraphDef()
          file_content = f.read()
          text_format.Merge(file_content, graph_def)
          tf.import_graph_def(graph_def, name='')
          tf.train.write_graph(graph_def, './', pb_path, as_text=False)

pbtxt_to_graphdef(pbtxt_path,pb_path)  # here you can write the name of the file to be converted
                                              # and then a new file will be made in pbtxt directory.

