【发布时间】: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