title: How to define max_queue_size, workers and use_multiprocessing in keras fit_generator()?
body: <p>I am applying transfer-learning on a pre-trained network using the GPU version of keras. I don't understand how to define the parameters <strong><code>max_queue_size</code></strong>, <strong><code>workers</code></strong>, and <strong><code>use_multiprocessing</code></strong>. If I change these parameters (primarily to speed-up learning), I am unsure whether all data is still seen per epoch.</p>
  
  <p><strong><code>max_queue_size</code></strong>:</p>
  
  <ul>
  <li><p>maximum size of the internal training queue which is used to "precache" samples from the generator </p></li>
  <li><p><em>Question:</em> Does this refer to how many batches are prepared on CPU? How is it related to <code>workers</code>? How to define it optimally?</p></li>
  </ul>
  
  <p><strong><code>workers</code></strong>: </p>
  
  <ul>
  <li><p>number of threads generating batches in parallel. Batches are computed in parallel on the CPU and passed on the fly onto the GPU for neural network computations </p></li>
  <li><p><em>Question:</em> How do I find out how many batches my CPU can/should generate in parallel?</p></li>
  </ul>
  
  <p><strong><code>use_multiprocessing</code></strong>: </p>
  
  <ul>
  <li><p>whether to use process-based threading</p></li>
  <li><p><em>Question:</em> Do I have to set this parameter to true if I change <code>workers</code>? Does it relate to CPU usage?</p></li>
  </ul>
  
  <p><strong>Related questions</strong> can be found here:</p>
  
  <ul>
  <li><a href="https://github.com/keras-team/keras/issues/8540" rel="noreferrer">Detailed explanation of model.fit_generator() parameters: queue size, workers and use_multiprocessing</a></li>
  <li><p><a href="https://stackoverflow.com/questions/51790943/what-does-worker-mean-in-fit-generator-in-keras">What does worker mean in fit_generator in Keras?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/36986815/what-is-the-parameter-max-q-size-used-for-in-model-fit-generator/36989864#36989864">What is the parameter “max_q_size” used for in “model.fit_generator”?</a></p></li>
  <li><p><a href="https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly" rel="noreferrer">A detailed example of how to use data generators with Keras</a>.</p></li>
  </ul>
  
  <p>I am using <code>fit_generator()</code> as follows:</p>
  
  <pre><code>    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)   
  </code></pre>
  
  <p>The specs of my machine are:</p>
  
  <pre><code>CPU : 2xXeon E5-2260 2.6 GHz
  Cores: 10
  Graphic card: Titan X, Maxwell, GM200
  RAM: 128 GB
  HDD: 4TB
  SSD: 512 GB
  </code></pre>