Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eager Execution - InternalError: Could not find valid device for node name: "Sqrt"

With Eager Execution enabled the TensorFlow square-root function tf.sqrt() results in an InternalError.

import tensorflow as tf

# enable eager execution
tf.enable_eager_execution()

> tf.pow(2,4)
'Out': <tf.Tensor: id=48, shape=(), dtype=int32, numpy=16>

> tf.sqrt(4)

>>> Traceback (most recent call last):

  File "<ipython-input-21-5dc8e2f4780c>", line 1, in <module>
    tf.sqrt(4)

  File "/Users/ekababisong/anaconda3/envs/py36_dl/lib/python3.6/site-packages/
     tensorflow/python/ops/math_ops.py", line 365, in sqrt
         return gen_math_ops.sqrt(x, name=name)

  File "/Users/ekababisong/anaconda3/envs/py36_dl/lib/python3.6/site-packages/
     tensorflow/python/ops/gen_math_ops.py", line 7795, in sqrt
        _six.raise_from(_core._status_to_exception(e.code, message), None)

  File "<string>", line 3, in raise_from

InternalError: Could not find valid device for node name: "Sqrt"
op: "Sqrt"
input: "dummy_input"
attr {
  key: "T"
  value {
    type: DT_INT32
  }
}
 [Op:Sqrt] name: Sqrt/
like image 285
Ekaba Bisong Avatar asked Aug 14 '18 17:08

Ekaba Bisong


3 Answers

I got a similar error when trying to pass an image through a convolutional filter. Turns out it was solved as P-Gn said, simply by convert it to float.

x = tf.cast(x, tf.float32)
like image 99
Djib2011 Avatar answered Oct 15 '22 14:10

Djib2011


Got a similar error when trying to find Nan Values in a dictionary, P-Gn's solution worked.

TF2.0 RC, Before (Internal Error : Could not find valid device for node) :

any(tf.math.is_nan(val) for val in dict.values())

After :

any(tf.math.is_nan(tf.cast(val, tf.float32) for val in dict.values())

Returns true / false

like image 24
yuva-rajulu Avatar answered Oct 15 '22 14:10

yuva-rajulu


In this case that the value is just int it might be a good idea just to use numpy.

In case you still want to use TensorFlow it can be done like this:

tf.math.sqrt(tf.convert_to_tensor(4, dtype='float32'))

or

tf.sqrt(tf.convert_to_tensor(4, dtype='float32'))

tested on TensorFlow 2

like image 29
ChaosPredictor Avatar answered Oct 15 '22 14:10

ChaosPredictor