Tensorflow: InvalidArgumentError: Input ... incompatible with expected float_ref

The following code leads to a very useless error:

import tensor flow as tf

x = tf.Variable(tf.constant(0.), name="x") with tf.Session() as s: val = s.run(x.assign(1)) print(val) # 1 val = s.run(x, {x: 2}) print(val) # 2 val = s.run(x.assign(1), {x: 0.}) # InvalidArgumentError 

tensorflow.python.framework.errors_impl.InvalidArgumentError: input 0 from node Assign_1 passed float from _arg_x_0_0: 0 is incompatible with the expected value of float_ref.


How did I get this error?
Why am I getting this error?

0
source share
1 answer

Here is what I could do.

How did I get this error?
This error occurs when two conditions are met in the same session:

  • Tensorflow variable is set to
  • The same variable is also passed the value as part of feed_dict

That is why the first 2 runs of success (both of them simultaneously do not satisfy these two conditions).

Why am I getting this error?
I'm not sure, but I'm not the intentional choice of Google design. Here is my explanation:

First, the source code for TF (TensorFlow) resolves x.assign(1) to tf.assign(x, 1) , which gives us a hint to better understand the error message when it says Input 0 .
The error message applies to x when Input 0 specified for assignment op. It is further indicated that the first assignment argument is op was passed float from _arg_x_0_0:0 .

TL; DR
Thus, to run, where the TF variable is provided as a feed, this variable will no longer be considered as a variable (but instead as the value that it was assigned), and therefore any attempts to further assign it a value will be erroneous, since only TF variables can be assigned a value in the graph.

0
source

Source: https://habr.com/ru/post/1238108/


All Articles