【问题标题】:TensorFlow cannot copy Tensor with type string to deviceTensorFlow 无法将字符串类型的张量复制到设备
【发布时间】:2019-09-26 11:03:01
【问题描述】:

我无法弄清楚这里发生了什么问题。安装 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.

我正在安装 tensorflow 来关注这个博客: installing-tensorflow-with-cuda-cudnn-and-gpu-support-on-windows-10

【问题讨论】:

    标签: python tensorflow gpu


    【解决方案1】:

    使用以下步骤验证 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))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-19
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      相关资源
      最近更新 更多