PatWie/tensorflow-cmake

Different outputs in example.py and inference_c.py

iurilarosa opened this issue · 2 comments

Hi,
I thought I figured how the C code works but trying your examples i noticed the the original python code gives as output tensor
output [[2.1963656]]
while the executable file from the C code gives
output -0.871704

Should they have the same values, or did I not understand something and it is intended?
Thanks

They are the same here. Note, each time you run example.py the graph and weights change. In the order of:

  • example.py
  • inference_*
  • inference_*
  • inference_*

all outputs should and are the same.

Yes i noticed, thank you. I tried also using a slightly different example with a similar graph structure:

import tensorflow as tf
import numpy as np
tf.reset_default_graph()
x = tf.placeholder(tf.float32, shape=[1, 2], name='input')
variab = tf.Variable([1.0,1.0], name='var')
output = tf.add(x,variab, name='output')

val = np.array([[1, 1]], dtype=np.float32)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    # save graph
    saver = tf.train.Saver(tf.global_variables())
    saver.save(sess, './exported/my_model')

    tf.train.write_graph(sess.graph, '.', "./exported/graph.pb", as_text=False)

    x1 = tf.get_default_graph().get_tensor_by_name('input:0')
    t1 = tf.get_default_graph().get_tensor_by_name('output:0')

   out= sess.run(t1, feed_dict={x1: val})

    print(tf.global_variables())
    print("out           " ,out)

and it works properly. Thank you again.