gpt4 book ai didi

python - TensorFlow 无法将字符串类型的 Tensor 复制到设备

转载 作者:行者123 更新时间:2023-12-05 08:06:49 24 4
gpt4 key购买 nike

我不知道这里发生了什么问题。安装 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

最佳答案

使用以下步骤验证 tensorflow-GPU 是否正确安装,

  • 你能检查一下 tensorflow 是否正在使用 GPU,

    将tensorflow导入为tf
    打印(tf.test.is_gpu_available())

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

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

  • 你可以尝试给gpu分配一个计算,看看是否有错误

    将tensorflow导入为tf
    使用 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)
    以 tf.Session() 作为 sess:
    打印(sess.run(c))

关于python - TensorFlow 无法将字符串类型的 Tensor 复制到设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58115407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com