【发布时间】:2019-08-27 02:58:06
【问题描述】:
我正在使用 GPU 版本的 keras 在预训练网络上应用迁移学习。我不明白如何定义参数max_queue_size、workers和use_multiprocessing。如果我更改这些参数(主要是为了加快学习速度),我不确定每个 epoch 是否仍然可以看到所有数据。
max_queue_size:
用于从生成器“预缓存”样本的内部训练队列的最大大小
问题:这是指在 CPU 上准备了多少批次?它与
workers有什么关系?如何优化定义?
workers:
并行生成批次的线程数。批处理在 CPU 上并行计算,并即时传递到 GPU 上进行神经网络计算
问题:我如何知道我的 CPU 可以/应该并行生成多少批次?
use_multiprocessing:
是否使用基于进程的线程
问题:如果我更改
workers,是否必须将此参数设置为true?是否与 CPU 使用率有关?
相关问题可以在这里找到:
- Detailed explanation of model.fit_generator() parameters: queue size, workers and use_multiprocessing
What is the parameter “max_q_size” used for in “model.fit_generator”?
A detailed example of how to use data generators with Keras.
我使用fit_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
【问题讨论】:
标签: python tensorflow machine-learning keras gpu