Skip to content

Instantly share code, notes, and snippets.

@atztao
Forked from alsrgv/pbtxt_to_pb.py
Created October 13, 2021 10:17
Show Gist options
  • Select an option

  • Save atztao/21698c2bc2c26e28f81829e0d400ec89 to your computer and use it in GitHub Desktop.

Select an option

Save atztao/21698c2bc2c26e28f81829e0d400ec89 to your computer and use it in GitHub Desktop.
Converter of graph.pbtxt to binary graph.pb
from __future__ import print_function
import os
import sys
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.framework import graph_io
if len(sys.argv) < 2:
print('Usage: %s <filename prefix>' % sys.argv[0])
sys.exit(-1)
filename = sys.argv[1]
with open(filename + '.pbtxt', 'r') as f:
graph_def = tf.GraphDef()
file_content = f.read()
text_format.Merge(file_content, graph_def)
graph_io.write_graph(graph_def,
os.path.dirname(filename),
os.path.basename(filename) + '.pb',
as_text=False)
print('Converted %s.pbtxt to %s.pb' % (filename, filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment