启用Eager Execution后,TensorFlow平方根函数的tf.sqrt()结果为InternalError。import tensorflow as tf# enable eager executiontf.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_fromInternalError: 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/
3 回答

慕妹3146593
TA贡献1820条经验 获得超9个赞
在这种情况下,值只是int,仅使用numpy可能是一个好主意。
如果您仍然想使用TensorFlow,可以这样做:
tf.math.sqrt(tf.convert_to_tensor(4, dtype='float32'))
或者
tf.sqrt(tf.convert_to_tensor(4, dtype='float32'))
在TensorFlow 2上测试
添加回答
举报
0/150
提交
取消