Given a tensor flow model graph, how to find the input node and output node names

Try this:

run python

>>> import tensorflow as tf
>>> gf = tf.GraphDef()
>>> gf.ParseFromString(open('/your/path/to/graphname.pb','rb').read())

and then

>>> [n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Placeholder')]

Then, you can get result similar to this:

['Mul=>Placeholder', 'final_result=>Softmax']

But I’m not sure it’s the problem of node names regarding the error messages.
I guess you provided wrong arguements when loading the graph file or your generated graph file is something wrong?

Check this part:

E/AndroidRuntime(16821): java.lang.IllegalArgumentException: Incompatible 
shapes: [1,224,224,3] vs. [32,1,1,2048]

UPDATE:
Sorry,
if you’re using (re)trained graph , then try this:

[n.name + '=>' +  n.op for n in gf.node if n.op in ( 'Softmax','Mul')]

It seems that (re)trained graph saves input/output op name as “Mul” and “Softmax”, while optimized and/or quantized graph saves them as “Placeholder” and “Softmax”.

BTW, using retrained graph in mobile environment is not recommended according to Peter Warden’s post: https://petewarden.com/2016/09/27/tensorflow-for-mobile-poets/ . It’s better to use quantized or memmapped graph due to performance and file size issue, I couldn’t find out how to load memmapped graph in android though…:(
(no problem loading optimized / quantized graph in android)

Leave a Comment