我不知道这里发生了什么问题。安装 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
最佳答案
使用以下步骤验证 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))
https://stackoverflow.com/questions/58115407/
相关文章:
postgresql - 如何为 linux、Fedora 安装 psycopg2
oauth-2.0 - 松弛 Oauth : Automatically authorize use
c# - OmniSharp MSBuild ProjectManager 无法更新我的 .cspr
asynchronous - 如何使 promise 因 clojure 错误而失败?
reactjs - react native : Module RCTLog is not a re
python - 如何使用 Pandas 计算数据框中的类标签频率?