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

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


慕码人2483693
浏览 158回答 3
3回答

慕妹3146593

在这种情况下,值只是int,仅使用numpy可能是一个好主意。如果您仍然想使用TensorFlow,可以这样做:tf.math.sqrt(tf.convert_to_tensor(4,&nbsp;dtype='float32'))或者tf.sqrt(tf.convert_to_tensor(4,&nbsp;dtype='float32'))在TensorFlow 2上测试
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python