python - Keras 没有使用完整的 CPU 内核进行训练

标签 python tensorflow machine-learning keras

我正在使用 Tensorflow 后端上的 Keras 在我机器上的一个非常庞大的数据集上训练 LSTM 模型。我的机器有 16 个内核。在训练模型时,我注意到所有核心的负载都低于 40%。

我通过不同的来源寻找解决方案,并尝试提供核心以在后端使用

config = tf.ConfigProto(device_count={"CPU": 16})
backend.tensorflow_backend.set_session(tf.Session(config=config))

即使在那之后,负载仍然相同。

这是因为模型很小吗?一个纪元大约需要 5 分钟。如果它使用全核,则可以提高速度。

如何告诉 Keras 或 Tensorflow 使用全部可用内核(即 16 个内核)来训练模型。??

我已经完成了这些 stackoverflow 问题并尝试了那里提到的解决方案。它没有帮助。

Limit number of cores used in Keras

最佳答案

您究竟是如何训练模型的?您可能想要研究使用 model.fit_generator() 但使用 Keras Sequence 对象而不是自定义生成器。这允许安全地使用多处理,并将导致所有内核都被使用。

您可以查看 Keras docs举个例子。

关于python - Keras 没有使用完整的 CPU 内核进行训练,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587279/

相关文章:

Python 转换日期时间以在 os.utime 中使用

python - "TypeError: Input ' global_step ' of ' ResourceApplyAdagradDA ' Op has type int32 that does not match expected type of int64."这是什么错误?

java - 异常: Filter didn't make the test instance immediately available

python - 是否可以使用 scikit-learn K-Means Clustering 指定您自己的距离函数?

python - keras 中的 MLP : overfitting or underfitting?

带有 Makefile 的 `extra` 包的 Python setuptools/distutils 自定义构建

python - 我的代码末尾明显有 'newline character'

python - 如何为 url 参数编写文档字符串

python - keras 序列模型中的多个输出

tensorflow - 为什么 LSTMCell 输入的维度必须与单元数匹配