EE2017
EE2017

Reputation: 59

How can you identify Input and Output name in tensorboard graph like this one in the pictures attached to this post?

I used the MobileNet_v1_1.0_224 tensorflow model for object detection. Now, I have my custom frozen graph (.pb file) that I need to convert to tflite extension so that I can use my model for mobile devices.

Can someone help me to identify the input and the output names in this tensorboard graph? I need them to use as input and output parameters to convert my frozen graph (.pb file) to tensorflow lite (.tflite) file

graph from tensorboard

same graph

Upvotes: 1

Views: 2570

Answers (2)

Ajinkya
Ajinkya

Reputation: 1887

You can use this code:

import tensorflow as tf
gf = tf.GraphDef()   
m_file = open('frozen_inference_graph.pb','rb')
gf.ParseFromString(m_file.read())

with open('somefile.txt', 'a') as the_file:
    for n in gf.node:
        the_file.write(n.name+'\n')

file = open('somefile.txt','r')
data = file.readlines()
print ("\noutput name = ")
print (data[len(data)-1])

print ("Input name = ")
file.seek ( 0 )
print (file.readline())

In my case I had

output name: SemanticPredictions
input name: ImageTensor

Upvotes: 5

Juliano S Assine
Juliano S Assine

Reputation: 101

You are looking for the summarize_graph tool. Run summarize_graph --in_graph=your_graph.pb and it will output. If you use docker you can find the summarize_graph on any tensorflow/tensorflow image with the devel tag. For example:

wget http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz
tar xvf mobilenet_v1_1.0_224.tgz
docker run --rm -it -v $PWD:/data tensorflow/tensorflow:1.10.1-devel-py3

# Inside docker
cd /tensorflow
bazel build tensorflow/tools/graph_transforms:summarize_graph # This may take a while, use --jobs 4
./bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=/data/mobilenet_v1_1.0_224_frozen.pb

The output will be:

Found 1 possible inputs: (name=input, type=float(1), shape=[?,224,224,3]) 
No variables spotted.
Found 1 possible outputs: (name=MobilenetV1/Predictions/Reshape_1, op=Reshape) 
Found 4254891 (4.25M) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 138 Const, 138 Identity, 27 FusedBatchNorm, 27 Relu6, 15 Conv2D, 13 DepthwiseConv2dNative, 2 Reshape, 1 AvgPool, 1 BiasAdd, 1 Placeholder, 1 Shape, 1 Softmax, 1 Squeeze
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=/data/mobilenet_v1_1.0_224_frozen.pb --show_flops --input_layer=input --input_layer_type=float --input_layer_shape=-1,224,224,3 --output_layer=MobilenetV1/Predictions/Reshape_1

Upvotes: 2

Related Questions