python - 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 不使用它。
感谢您的帮助。
解决方案
我想我解决了这个问题:)
安装 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)。
推荐阅读
- javascript - 单击特定元素时,如何为 onfocusout 事件提供异常?
- firebase - 使用 Flutter 查询 Firestore 的书签/收藏页面
- javascript - 创建和读取 JSON 文件
- javascript - 在 JavaScript 中为现有的 EventListener 添加样式
- javascript - 如何在 Vue 组件内访问通过 Vue 路由器传递的道具?
- javascript - 测试不在量角器中循环
- dataframe - 计算所选列中值与条件匹配的列数pyspark
- python - np.where 与列表元素选择
- python - TF2 - tf.function 和类变量中断
- java - 如何将随机生成的字符串保存到变量并计算距离?