Can someone include the input and output node names in the documentation please ? In particular, if it has any importance, I am using mobilenet backbone. (maybe the input tensor is different?).
I tried to use summarize_graph but it just don't work even with the last versions and so on. Building summarize_graph did work but as you can see below I cannot parse my .pb. If someone could just tell me the input and output node names it would save me some time.
I thought it was ImageTensor:0 and SemanticPredictions:0 but as I am building my .pb with a homemade "export_model.py" without using the deprecated slim, the input and output nodes may have other names.
PS: I need those names to build my client for tensorflow-serving
Thank you very much for helping me.
[libprotobuf ERROR external/protobuf_archive/src/google/protobuf/text_format.cc:288] Error parsing text-format tensorflow.GraphDef: 7:1: Expected identifier, got: <
2018-06-01 15:39:50.659145: E tensorflow/tools/graph_transforms/summarize_graph_main.cc:320] Loading graph 'saved_model.pb' failed with Can't parse saved_model.pb as binary proto
(both text and binary parsing failed for file saved_model.pb)
2018-06-01 15:39:50.659213: E tensorflow/tools/graph_transforms/summarize_graph_main.cc:322] usage: tensorflow/bazel-bin/tensorflow/tools/graph_transforms/summarize_graph
Flags:
--in_graph="" string input graph file name
--print_structure=false bool whether to print the network connections of the graph
"ImageTensor" and "SemanticPredictions" worked for me.
I get AssertionError: ImageTensor is not in graph (same for SemanticPredictions). I am using DeepLab with MobileNetv2
I can confirm SemanticPredictions works as Outputname at least to convert it to Tensorflowjs. I Had to put it without quotation marks tho.
This might just be for the xception_65 network, but using output node name 'semantic' worked for me. I found this looking in the deeplab/common.py file and found the line OUTPUT_TYPE = 'semantic'.
in case someone needs help, here is a snippet.
class DeepLabelModel:
def __init__(self, accuracy_over_speed = True):
self.EXE_DIR = os.getcwd() # example-XXXNet.exe 鞁ろ枆霅橂姅 瓴诫
self.BASE_DIR = os.path.dirname(os.path.abspath(__file__))
self.SLIM_DIR = os.path.join(self.BASE_DIR, 'slim')
sys.path.append(self.BASE_DIR)
sys.path.append(self.SLIM_DIR)
import ade20k_label_color # need BASE_DIR append
self.DEEP_LAB_DIR = os.path.join(self.BASE_DIR, 'deeplab')
self.WEIGHTS_DIR = os.path.join(self.DEEP_LAB_DIR, 'weights')
if accuracy_over_speed is True:
self.MODEL_NAME = 'deeplabv3_xception_ade20k_train'
self.INPUT_SIZE = (513, 513) # (Height, Width) tuple
else:
self.MODEL_NAME = 'deeplabv3_mnv2_ade20k_train_2018_12_03'
self.INPUT_SIZE = (257, 257) # (Height, Width) tuple
self.PATH_TO_CKPT = self.MODEL_NAME + '/frozen_inference_graph.pb'
self.PATH_TO_CKPT = os.path.join(self.WEIGHTS_DIR, self.PATH_TO_CKPT)
self.CLASS_LABEL = ade20k_label_color.ade20k_label
self.CLASS_COLOR = ade20k_label_color.ade20k_color
# Start TF
self.config = tf.ConfigProto()
self.config.allow_soft_placement = True
self.config.log_device_placement = False
self.config.gpu_options.allow_growth = True
self.sess = tf.Session(config=self.config)
with tf.gfile.GFile(self.PATH_TO_CKPT, 'rb') as fid:
graph_def = tf.GraphDef()
graph_def.ParseFromString(fid.read())
self.sess.graph.as_default()
tf.import_graph_def(graph_def, name='')
# specification of DeepLabel defined by google
self.INPUT_TENSOR_NAME = 'ImageTensor:0'
self.OUTPUT_TENSOR_NAME = 'SemanticPredictions:0'
self.input_tensor = self.sess.graph.get_tensor_by_name(self.INPUT_TENSOR_NAME)
self.output_tensor = self.sess.graph.get_tensor_by_name(self.OUTPUT_TENSOR_NAME)
def inferDeepLabel(self, input_image):
src_height, src_width = input_image.shape[:2] # original size
input_image = cv2.resize(input_image, self.INPUT_SIZE) # input tensor size
input_image = np.expand_dims(input_image, axis=0) # input tensor dim
#start = time.time()
result = self.sess.run(
self.output_tensor, feed_dict={self.INPUT_TENSOR_NAME: input_image}
)
result = np.squeeze(result, axis=0)
#end = time.time()
#print('inferDeepLabel FPS: ', 1 / (end - start))
result = cv2.resize(result, (src_width, src_height), interpolation=cv2.INTER_NEAREST) # original size
return result
def decorate(self, result):
src_height, src_width = result.shape[:2] # original size
visu = np.zeros((src_height, src_width, 3), np.uint8)
# loop over the image, pixel by pixel
for y in range(0, src_height):
for x in range(0, src_width):
# threshold the pixel
visu[y, x] = self.CLASS_COLOR[result[y, x]]
# return the decorated image
return visu
Input is a 513 by 513 image (BGR or RGB IDK) if xception, output is a same size matrix with label
Having hit this problem a few more times, the best way I have found to identify node names in tensorflow is by inspecting the graph with tensorboard. The tricky part for me was converting the ckpt files to tensorboard format. So I wrote a little piece of code to do that for me. Once this has created a tensorboard file, you can inspect it by running tensorboard --logdir /tmp/tensorboard_graphs, and opening your browser to localhost:6006. I haven't tested it with pb files, but I would expect that you could use something similar:
import tensorflow as tf
from absl import app, flags
FLAGS = flags.FLAGS
flags.DEFINE_string('ckpt_path', '/default/path/default_file.ckpt', 'path to ckpt files')
def main(argv):
ckpt_path = FLAGS.ckpt_path
tf.reset_default_graph()
saver = tf.train.import_meta_graph(ckpt_path + '.meta')
g = tf.get_default_graph()
with tf.Session() as sess:
saver.restore(sess, ckpt_path)
writer = tf.summary.FileWriter('/tmp/tensorboard_graphs')
writer.add_graph(sess.graph)
if __name__ == '__main__':
app.run(main)
Hi There,
We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing.
If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.
Most helpful comment
I get
AssertionError: ImageTensor is not in graph(same forSemanticPredictions). I am using DeepLab with MobileNetv2