KhronosGroup / NNEF-Tools

The NNEF Tools repository contains tools to generate and consume NNEF documents
https://www.khronos.org/nnef
222 stars 58 forks source link

Input tensor is not saved in execute.py #133

Closed dvorotnev closed 4 years ago

dvorotnev commented 4 years ago

When I try to save an input tensor, which is randomly generated, during execution of simple example:

import tensorflow as tf
import nnef_tools.io.tf.graphdef as graphdef

def testnet_abs():
    x = tf.placeholder(tf.float32, shape=[6, 32, 32, 3], name='input')
    return tf.abs(x)

tf.reset_default_graph()
with tf.Session() as sess:
    result = testnet_abs()
    sess.run(tf.global_variables_initializer())
    graphdef.save_default_graph("model.pb", session=sess, outputs={result: "output"})

the script execute.py doesn't save it, because in TFExecutor::__call__ it is discarded by the condition if len(op.inputs) there. I think this condition should be if len(op.outputs), shouldn't it?

Steps to reproduse:

python3 ./test.py
python -m nnef_tools.convert --input-format=tf --output-format=nnef --input-model=./model.pb --optimize --keep-io-names --output-model=model.nnef
python -m nnef_tools.execute ./model.pb  --format=tf --random='uniform(0,1)' --output-names='{"input:0": "input", "output:0": "output"}' --output-path=./

python output:

Written ./output.dat

after fix python output is:

Written ./input.dat
Written ./output.dat
gyenesvi commented 4 years ago

No, that's not a mistake, that condition is exactly there to guard against outputting the inputs and constants. Not sure exactly why it was there, but it may have caused an error somewhere, let me think about it.

gyenesvi commented 4 years ago

I believe that the condition was a relic coming from the time before TFExecutor was refactored into a class, and got a separate init and call phase. The same condition is there in the init phase, when the implicit outputs of the model are enumerated, and it makes sense there. If I remove the condition altogether, the execution still succeeds, and I don't see a problem with it right now, so I have just removed it. The pull request can be discarded as it is fixed now. Let me know if it is saving fine on your side.

dvorotnev commented 4 years ago

It works. Thank you!