急切执行-InternalError:找不到节点名称为“ Sqrt”的有效设备

Eka*_*ong 10 tensorflow

启用Eager Execution后,TensorFlow平方根函数tf.sqrt()结果为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/
Run Code Online (Sandbox Code Playgroud)

Dji*_*011 8

尝试通过卷积滤波器传递图像时出现类似错误。事实证明,正如P-Gn所说,解决了,只需将其转换为float即可。

x = tf.cast(x, tf.float32)
Run Code Online (Sandbox Code Playgroud)