首页 > 解决方案 > Keras 在训练神经网络时不使用我的 Nvidia GPU

问题描述

Keras/TensorFlow 不使用我的 GPU。

为了让我的 GPU 与 tensorflow 一起工作,我尝试安装 tensorflow-gpu(我在 Windows 上使用 Python 3.6.8):

pip3 install tensorflow-gpu --user

python -m notebook

import tensorflow as tf

然后我得到以下错误:

ImportError ... Traceback (most recent call last),

ImportError: DLL load failed: Le module spécifié est introuvable.

ImportError ... Traceback (most recent call last)

然后我做pip3 install tensorflow, python - notebook,然后import tensorflow as tf工作,但当我继续:

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

print('Tensorflow: ', tf._ _ version _ _)

我得到:

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 587921620497715868
]
Tensorflow:  1.13.1

这意味着没有找到 GPU(我的 Lenovo Thinkpad P72 上有 Intel UHD Graphics P630 和 Nvidia Quadro P5200)。

另外,请注意,当我执行 !nvidia-smi 时,我看到检测到 Nvidia(作为 GPU [0]),所以我不明白为什么在训练神经网络时 Tensorflow/Keras 不使用它。

感谢您的帮助。

标签: pythontensorflowkerasgpu

解决方案


我想我解决了这个问题:)

安装 Anaconda3 后,我在 Anaconda powershell 中以这种方式进行:

conda create -n tensorflowgpuproject python=3.5 tensorflow-gpu=1.10.0 ipython=6.5.0 keras matplotlib jupyter scikit-learn numpy=1.14.5 setuptools=39.1.0 prompt_toolkit=1.0.15

conda 激活 tensorflowgpuproject

python -m pip install --upgrade pip --user

setx 路径 "%path%;C:\Users\n-bou\AppData\Roaming\Python\Python35\Scripts"

pip uninstall prompt_toolkit(最后一个命令是必要的,因为两个版本的 prompt_toolkit 之间存在冲突)

然后我能够执行我的 python 笔记本,其中包含使用 keras 的 UNet 代码,并在笔记本的开头使用通常的“import tensorflow as tf”(调用 tensorflow-gpu)。


推荐阅读