启用 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/