【问题标题】:GPU nvidia is not availableGPU 英伟达不可用
【发布时间】:2018-10-01 00:40:32
【问题描述】:

我在具有 gpu gtx 1080 的笔记本电脑上使用 ubuntu 18.0.4。上次,我对其进行了测试,并通过运行此代码 test gpu 正确处理了张量流 今天我发现tensorflow无法识别GPU,当我输入nvidia-smi时,表明GPU是off。有什么问题以及如何纠正它。我尝试通过运行此代码来明确设置它,但映射不起作用:

    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)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

【问题讨论】:

  • 你为什么要用“with tf.device”来绑定cpu?
  • @WilliamD.Irons,抱歉打错了。我的意思是with tf.device('/gpu:0'):
  • 你是如何安装 tensorflow 的?使用点子?你安装的是 tensorflow 包还是 tensorflow-gpu 包? (我认为 pip list 会显示安装了哪个包?)
  • @WilliamD.Irons,我认为问题来自 python3。当我只用python (python --version =python 2.7) 运行脚本时,脚本运行良好!如何更改以使用 python3.6
  • 每个python版本都有自己的一套包,你必须安装带有pip的tensorflow-gpu和带有pip3的tensorflow?试试 pip3 卸载 tensorflow,pip3 安装 tensorflow-gpu。

标签: ubuntu tensorflow gpu nvidia


【解决方案1】:

运行以下代码,看看你的 gpu 是否可见

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

如果您只看到 CPU 而不是 GPU,请更新您的 cuda 和 cudnn 版本以匹配您的 tensorflow 版本。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    您是否暂停了您的笔记本电脑?尝试完全重启,因为挂起会使 GPU 在再次唤醒后不可用。

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多