【问题标题】:How to use other GPUs in Keras with a TensorFlow backend?如何在带有 TensorFlow 后端的 Keras 中使用其他 GPU?
【发布时间】:2016-12-19 17:54:05
【问题描述】:

这与 How to enable Keras with Theano to utilize multiple GPUs 有关,但我没有使用多个 GPU,而是有兴趣指定特定模型在哪个 GPU 上训练或运行。

我的nvidia-smi 输出如下所示:

+------------------------------------------------------+                       
| NVIDIA-SMI 361.42     Driver Version: 361.42         |                       
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 0000:03:00.0     Off |                    0 |
| N/A   38C    P0    60W / 149W |  11354MiB / 11519MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 0000:04:00.0     Off |                    0 |
| N/A   37C    P0    71W / 149W |    224MiB / 11519MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  GeForce GTX 750 Ti  Off  | 0000:06:00.0      On |                  N/A |
| 40%   29C    P8     1W /  38W |    120MiB /  2047MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

这个输出当然是什么都没有运行的时候。问题是我不确定在 Keras 中如何指定要在哪个 GPU 上运行。当然,使用 TensorFlow,我们可以只使用 with tf.device('/cpu:1'): 范式,但我不确定它如何与 Keras 集成。

谢谢!

【问题讨论】:

标签: machine-learning neural-network tensorflow deep-learning keras


【解决方案1】:

除了在 keras.json 文件中指定 tensorflow 作为后端之外,您还可以使用环境变量 CUDA_VISIBLE_DEVICES (http://acceleware.com/blog/cudavisibledevices-masking-gpus) 限制使用的 GPU 数量和/或使用特定的 GPU .您可以在此处指定要使用的 GPU。

【讨论】:

    【解决方案2】:

    基本上两个步骤,你必须遵循:

    1. 安装支持 GPU 的 tensorflow 版本。看到这个https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html

    2. Keras 默认使用 Theano 作为后端。你需要把它改成tensorflow

    vi ~/.keras/keras.json

    文件内容:{"epsilon": 1e-07, "floatx": "float32", "backend": "theano"}

    将“theano”改为“tensorflow”

    问题是您只需要安装启用 gpu 的 tensorflow 版本。它将自动使用您配置的 gpu。

    cuda和tensorflow的安装过程见此链接http://www.nvidia.com/object/gpu-accelerated-applications-tensorflow-installation.html

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 1970-01-01
      • 2021-11-28
      • 2018-09-26
      • 2018-10-02
      • 2020-06-13
      • 2018-07-18
      • 2023-03-14
      • 2019-04-10
      相关资源
      最近更新 更多