Skip to content

Instantly share code, notes, and snippets.

@alsrgv
Created March 15, 2018 02:51
Show Gist options
  • Save alsrgv/1a83c7953cb04676f6a0b3ec3917a18c to your computer and use it in GitHub Desktop.
Save alsrgv/1a83c7953cb04676f6a0b3ec3917a18c 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))
@AlexYiningLiu
Copy link

I tried to apply your code to this pbtxt file here:
https://github.com/google/mediapipe/blob/master/mediapipe/graphs/hand_tracking/multi_hand_tracking_mobile.pbtxt
and received the error:

google.protobuf.text_format.ParseError: 6:1 : Message type "tensorflow.GraphDef" has no field named "input_stream".

Can you please see if this is fixable? Thanks.

@kgediya
Copy link

kgediya commented Jul 29, 2020

I tried to apply your code to this pbtxt file here:
https://github.com/google/mediapipe/blob/master/mediapipe/graphs/hand_tracking/multi_hand_tracking_mobile.pbtxt
and received the error:

google.protobuf.text_format.ParseError: 6:1 : Message type "tensorflow.GraphDef" has no field named "input_stream".

Can you please see if this is fixable? Thanks.

Any fix yet?

@alexst07
Copy link

alexst07 commented Dec 2, 2020

I tried to apply your code to this pbtxt file here:
https://github.com/google/mediapipe/blob/master/mediapipe/graphs/hand_tracking/multi_hand_tracking_mobile.pbtxt
and received the error:

google.protobuf.text_format.ParseError: 6:1 : Message type "tensorflow.GraphDef" has no field named "input_stream".

Can you please see if this is fixable? Thanks.

Same error here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment