python - 急于执行 - 内部错误 : Could not find valid device for node name: "Sqrt"

标签 python 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/

最佳答案

当我尝试通过卷积滤波器传递图像时,我遇到了类似的错误。结果按照P-Gn说的解决了,只需将其转换为float即可。

x = tf.cast(x, tf.float32)

关于python - 急于执行 - 内部错误 : Could not find valid device for node name: "Sqrt",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51846682/

相关文章:

python - 将初始状态输入 LSTMCell

tensorflow - NewRandomAccessFile 无法创建/打开 : output_inference_graph_v1. pb:访问被拒绝

python - 缺少测试覆盖率 pytest python 类

python - 创建并返回具有连续重复字母的所有国家/地区的元组

python - 如何在 numpy 数组中找到唯一的非 nan 值?

python - 从 Tensorflow 摘要获取 CSV

python - Keras model.fit() 发出 TypeError : 'NoneType' object is not callable

python - Tkinter 值得学习吗?

python - numpy 数组连接 : "ValueError: all the input arrays must have same number of dimensions"

python - tensorflow 将每一行除以不同的总和