Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在keras fit_generator()中定义最大队列大小、工人和使用多处理?_Python_Tensorflow_Machine Learning_Keras_Gpu - Fatal编程技术网

Python 如何在keras fit_generator()中定义最大队列大小、工人和使用多处理?

Python 如何在keras fit_generator()中定义最大队列大小、工人和使用多处理?,python,tensorflow,machine-learning,keras,gpu,Python,Tensorflow,Machine Learning,Keras,Gpu,我正在使用GPU版本的keras在预先培训的网络上应用迁移学习。我不明白如何定义参数最大队列大小,工作者,以及使用多处理。如果我更改这些参数(主要是为了加快学习),我不确定每个历元是否仍能看到所有数据 最大队列大小: 用于从生成器中“预切”样本的内部训练队列的最大大小 问题:这是否指CPU上准备了多少批?它与工人的关系如何?如何对其进行最佳定义 工人: 并行生成批处理的线程数。批处理在CPU上并行计算,并实时传递到GPU进行神经网络计算 问题:如何找出我的CPU可以/应该并行生成多少批

我正在使用GPU版本的keras在预先培训的网络上应用迁移学习。我不明白如何定义参数
最大队列大小
工作者
,以及
使用多处理
。如果我更改这些参数(主要是为了加快学习),我不确定每个历元是否仍能看到所有数据

最大队列大小

  • 用于从生成器中“预切”样本的内部训练队列的最大大小

  • 问题:这是否指CPU上准备了多少批?它与
    工人的关系如何?如何对其进行最佳定义

工人

  • 并行生成批处理的线程数。批处理在CPU上并行计算,并实时传递到GPU进行神经网络计算

  • 问题:如何找出我的CPU可以/应该并行生成多少批

使用多处理

  • 是否使用基于进程的线程

  • 问题:如果我更改
    工作者
    ,是否必须将此参数设置为true?它与CPU使用有关吗

相关问题可在此处找到:

我使用的是
fit\u generator()
,如下所示:

    history = model.fit_generator(generator=trainGenerator,
                                  steps_per_epoch=trainGenerator.samples//nBatches,     # total number of steps (batches of samples)
                                  epochs=nEpochs,                   # number of epochs to train the model
                                  verbose=2,                        # verbosity mode. 0 = silent, 1 = progress bar, 2 = one line per epoch
                                  callbacks=callback,               # keras.callbacks.Callback instances to apply during training
                                  validation_data=valGenerator,     # generator or tuple on which to evaluate the loss and any model metrics at the end of each epoch
                                  validation_steps=
                                  valGenerator.samples//nBatches,   # number of steps (batches of samples) to yield from validation_data generator before stopping at the end of every epoch
                                  class_weight=classWeights,                # optional dictionary mapping class indices (integers) to a weight (float) value, used for weighting the loss function
                                  max_queue_size=10,                # maximum size for the generator queue
                                  workers=1,                        # maximum number of processes to spin up when using process-based threading
                                  use_multiprocessing=False,        # whether to use process-based threading
                                  shuffle=True,                     # whether to shuffle the order of the batches at the beginning of each epoch
                                  initial_epoch=0)   
我的机器的规格是:

CPU : 2xXeon E5-2260 2.6 GHz
Cores: 10
Graphic card: Titan X, Maxwell, GM200
RAM: 128 GB
HDD: 4TB
SSD: 512 GB
问题0:

问题:这是否指CPU上准备了多少批?它与工人有什么关系?如何对其进行最佳定义

从您发布的消息中,您可以了解到您的CPU一直在创建批处理,直到队列达到最大队列大小或停止。您希望为GPU“获取”批处理做好准备,以便GPU不必等待CPU。 队列大小的理想值是使其足够大,使GPU始终在接近最大值的位置运行,而不必等待CPU准备新的批处理

问题1:

问题:如何找出我的CPU可以/应该并行生成多少批

如果您看到您的GPU处于空闲状态,正在等待批处理,请尝试增加工作人员的数量,或许还可以增加队列大小

问题2:

如果我更改工人,是否必须将此参数设置为true?它与CPU使用有关吗

是对设置为
True
False
时发生的情况的实用分析。建议将其设置为
False
以防止冻结(在我的设置中
True
无需冻结即可正常工作)。也许其他人可以增加我们对这个话题的理解

总之: 尽量不要有顺序设置,尽量使CPU为GPU提供足够的数据。


另外:您可以(应该?)在下次创建几个问题,以便更容易回答。

非常有用,但我不同意问题海报应该单独提出这些问题。这些问题是相关的,你在文章末尾做了一个一句话的总结就说明了这一点。