【发布时间】:2018-05-03 17:35:22
【问题描述】:
我最近开始在 python 上使用 Tensorflow 进行编程。我想在我的笔记本电脑上使用我的 GTX 1050 来提高计算能力,但我没有成功......
安装完所有必需的库和软件(CUDA 9.0、CUDA 9.0 的 CuDNN、导入的:tensorflow 和 tensorflow-gpu...)后,我尝试了 Tensorflow 网站上的基本示例:
import tensorflow as tf
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)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))`
但这会返回以下答案(我在之后翻译它):
2018-05-03 19:15:59.540038: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Device mapping: no known devices.
2018-05-03 19:15:59.543664: I T:\src\github\tensorflow\tensorflow\core\common_runtime\direct_session.cc:284] Device mapping:
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:CPU:0
2018-05-03 19:15:59.546930: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:CPU:0
b: (Const): /job:localhost/replica:0/task:0/device:CPU:0
2018-05-03 19:15:59.547254: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] b: (Const)/job:localhost/replica:0/task:0/device:CPU:0
a: (Const): /job:localhost/replica:0/task:0/device:CPU:0
2018-05-03 19:15:59.547597: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] a: (Const)/job:localhost/replica:0/task:0/device:CPU:0
[[22. 28.]
[49. 64.]]
这条重要信息意味着我的笔记本电脑上唯一可用的设备是我的 CPU,但我有一个 GTX 1050。
我试图在开头添加这一行:
with tf.device("/device:gpu:0"):
我免除了命令行的所有侮辱,但它返回给我:
Operation was explicitly assigned to /device:gpu:0 but available devices are
[ /job:localhost/replica:0/task:0/device:CPU:0 ].
Make sure the device specification refers to a valid device.
有人知道我的问题的根源吗?或者有人曾经克服过这个问题并且可以帮助我吗?
【问题讨论】:
-
我对“imported : tensorflow and tensorflow-gpu”这句话感到困惑。你是用
pip install tensorflow还是pip install tensorflow-gpu安装 tensorflow 的? -
正如大卫所说,很可能没有选择正确版本的 tensorflow。通常 TF 在创建设备时会记录一些信息。它是否尝试创建 GPU 设备?如果您没有看到它,您可以启用一些调试日志记录,例如对于大多数日志(2、1、更少),将 TF_CPP_MIN_VLOG_LEVEL env var 设置为“3”。
-
嗨!我对 tensorflow 和 tensorflow-gpu 都使用 pip,我会尝试将此 env var 设置为“3”,但没有任何改变......我应该直接通过网站 dl TF 吗?
标签: python tensorflow