TensorFlow无法将类型为string的Tensor复制到设备

2024-03-28 08:17:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道这里发生了什么问题。安装TensorFlow GPU 2.0后,出现以下最小示例问题:

import tensorflow as tf
if tf.test.is_gpu_available():
    with tf.device("/gpu:0"):
        tf_string_array = tf.constant(["TensorFlow", "Deep Learning", "AI"])
    tf_string_array.device

在执行我的代码之后。我得到这个错误:

RuntimeError: Can't copy Tensor with type string to device /job:localhost/replica:0/task:0/device:GPU:0.

enter image description here

我安装tensorflow是为了关注这个博客: installing-tensorflow-with-cuda-cudnn-and-gpu-support-on-windows-10


Tags: testimport示例stringifgpuisdevice
1条回答
网友
1楼 · 发布于 2024-03-28 08:17:07

使用以下步骤验证tensorflow GPU的正确安装

  • 你能检查tensorflow是否使用GPU吗

    import tensorflow as tf print(tf.test.is_gpu_available())

  • 要找出使用的设备,可以启用日志设备放置 像这样:

    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

  • 您可以尝试将计算分配给gpu,并查看是否有错误

    import tensorflow as tf with tf.device('/gpu:0'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') c = tf.matmul(a, b) with tf.Session() as sess: print (sess.run(c))

相关问题 更多 >