【发布时间】:2018-10-20 08:56:40
【问题描述】:
我在 Windows 10 上安装了 Anaconda-Navigator 和所有必要的 Nvidia/Cuda 软件包,创建了一个名为 tensorflow-gpu-env 的新环境,更新了 PATH 信息等。当我运行模型(使用 tensorflow.keras 构建)时,我看到 CPU 利用率显着增加,GPU 利用率为 0%,模型只是没有训练。
我运行了几个测试来确定事情的样子:
print(tf.test.is_built_with_cuda())
True
上面的输出 ('True') 看起来是正确的。
再试一次:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
输出:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 1634313269296444741
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 1478485606
locality {
bus_id: 1
links {
}
}
incarnation: 16493618810057409699
physical_device_desc: "device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0"
]
到目前为止一切顺利...稍后在我的代码中,我使用以下代码开始训练:
history = merged_model.fit_generator(generator=train_generator,
epochs=60,
verbose=2,
callbacks=[reduce_lr_on_plateau],
validation_data=val_generator,
use_multiprocessing=True,
max_queue_size=50,
workers=3)
我还尝试按以下方式进行培训:
with tf.device('/gpu:0'):
history = merged_model.fit_generator(generator=train_generator,
epochs=60,
verbose=2,
callbacks=[reduce_lr_on_plateau],
validation_data=val_generator,
use_multiprocessing=True,
max_queue_size=50,
workers=3)
无论我如何开始训练,它都不会开始训练,我一直看到 CPU 使用率增加,GPU 使用率为 0%。
为什么我的 tensorflow-gpu 安装只使用 CPU?花了 HOURS 几乎没有任何进展。
附录
当我在控制台上运行 conda list 时,我看到以下有关 tensorflow 的信息:
tensorflow-base 1.11.0 gpu_py36h6e53903_0
tensorflow-gpu 1.11.0 <pip>
这个 tensorflow-base 是什么?它会导致问题吗?在安装 tensorflow-gpu 之前,我确保我使用 conda 和 pip 卸载了 tensorflow 和 tensorflow-gpu;然后使用pip 安装 tensorflow-gpu。我不确定这个 tensorflow-base 是否与我的tensorflow-gpu 安装一起提供。
附录 2
看起来 tensorflow-base 是 conda 的一部分,因为我可以使用 conda uninstall tensorflow-base 卸载它。我仍然安装了 tensorflow-gpu,但我现在无法再导入 tensorflow。它说“没有名为 tensorflow 的模块”。看起来我的 conda 环境没有看到我的 tensorflor-gpu 安装。我现在很困惑。
【问题讨论】:
标签: tensorflow keras gpu