简体   繁体   English

Keras没有使用完整的CPU内核进行培训

[英]Keras not using full CPU cores for training

I am training a LSTM model on a very huge dataset on my machine using Keras on Tensorflow backend. 我正在使用Tensorflow后端的Keras在我的机器上的一个非常庞大的数据集上训练LSTM模型。 My machine have 16 cores. 我的机器有16个核心。 While training the model I noticed that the load in all the cores are below 40%. 在训练模型时,我注意到所有核心的负载都低于40%。

I have gone through different sources looking for a solution and have tried providing the cores to use in the backend as 我已经找到了寻找解决方案的不同来源,并尝试提供在后端使用的内核

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

Even after that the load is still the same. 即便如此,负载仍然相同。

Is this because the model is very small.? 这是因为模型非常小。 It is taking around 5 minutes for an epoch. 一个时代需要大约5分钟。 If it uses full cores the speed can be improved. 如果它使用完整核心,则可以提高速度。

How to tell Keras or Tensorflow to use the full available cores ie 16 cores to train the model.?? 如何告诉Keras或Tensorflow使用完整的可用内核,即16个内核来训练模型。

I have went through these stackoverflow questions and tried the solutions mentioned there. 我已经完成了这些stackoverflow问题,并尝试了那里提到的解决方案。 It didn't help. 它没有帮助。

Limit number of cores used in Keras 限制Keras使用的核心数量

How are you training the model exactly? 你是如何准确地训练模型的? You might want to look into using model.fit_generator() but with a Keras Sequence object instead of a custom generator. 您可能希望使用model.fit_generator()但使用model.fit_generator() Sequence对象而不是自定义生成器。 This allows to safely use multiprocessing and will result in all cores being used. 这允许安全地使用多处理并且将导致使用所有核心。

You can checkout the Keras docs for an example. 您可以查看Keras文档以获取示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM