繁体   English   中英

list_local_device tensorflow 未检测到 gpu

[英]list_local_device tensorflow does not detect gpu

  1. 有没有办法检查我安装了GPU版本的Tensorflow
  2. !nvidia-smi

2017 年 12 月 18 日星期一 23:58:01

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.90                 Driver Version: 384.90                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:01:00.0  On |                  N/A |
| N/A   53C    P0    31W /  N/A |   1093MiB /  8105MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1068      G   /usr/lib/xorg/Xorg                           599MiB |
|    0      2925      G   compiz                                       290MiB |
|    0      3611      G   ...-token=11A9F5872A56620B72D1D5DF707CF1FC   200MiB |
|    0      5786      G   /usr/bin/nvidia-settings                       0MiB |
+-----------------------------------------------------------------------------+

但是当我尝试检测列表本地设备时,只检测到CPU

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

[name: "/cpu:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 3303842605833347443
]

我一定要设定别的东西来使用GPU进行KerasTensorflow

对于conda install tensorflow-gpu gpu 版本,使用pip install tensorflow-gpuconda install tensorflow-gpu 如果你使用 keras-gpu conda install -c anaconda keras-gpu命令会自动安装 tensorflow-gpu 版本。 在执行这些任何命令之前,请确保您卸载了正常的 tensorflow 。

你可能需要这个shell来配置你的 tensorflow-gpu。

如果你想检查 tensorflow-gpu,你可以运行它。

import tensorflow as tf
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)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print sess.run(c)

官方文档: Using GPUs

使用 tensorflow 的简单方法是:

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

使用 Keras:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()

我有同样的问题,但是此页面中的所有内容都无法解决我的问题。 我决定更新我的display adapter 按照这个方法:

Control Panel>Device Manager>display adapter>Right click>Update Driver

之后,您必须重新启动计算机,但您应该考虑这不仅是问题的根源。

我在使用适当的 tensorflow-gpu docker 容器并使用安装到容器内的 virtualenv 中的 tensorflow-gpu 时遇到了 subj。 这种组合很可能正确地屏蔽了 GPU 功能,否则,如果仅在没有 virtualenv 的容器中运行 python,则这些功能是可用的。

我认为您需要安装 cuda(它必须出现在您的 nvidia-smi 中)您是否检查了 cuda/CUDNN 版本和 tensorflow-gpu 之间的兼容性? 这可能对您有所帮助: https : //punndeeplearningblog.com/development/tensorflow-cuda-cudnn-compatibility/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM