Repository: keras-team/keras

Issue:
TypeError: fit_generator() got an unexpected keyword argument 'shuffle'
New to keras so 🤞 this isn't user error.

Keras `v2.0.8` (installed from master just now)
Theano `v0.9.0` (couldn't install from master just yet, due to needing to upgrade to libgpuarray)

I'm following the docs here: https://keras.io/models/model/#fit_generator, which show that `fit_generator()` supports a `shuffle` keyword argument.

... but when I pass in `shuffle=True`:

```
history = model.fit_generator(
    TrainSequence(images=train_images, targets=train_targets, batch_size=batch_size),
    steps_per_epoch=len(train_images) // batch_size,
    epochs=epochs,
    shuffle=True,
    validation_data=ValidationSequence(images=validation_images, targets=validation_targets),
    validation_steps=len(validation_images) // batch_size
)
```

... I get this error:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-4b4e4616b417> in <module>()
     27         train_targets=y_train,
     28         validation_images=images_val,
---> 29         validation_targets=y_val
     30     )
     31 

<ipython-input-8-8b418f8cf20f> in train(train_images, train_targets, validation_images, validation_targets)
     19         shuffle=True,
     20         validation_data=ValidationSequence(images=validation_images, targets=validation_targets),
---> 21         validation_steps=len(validation_images) // batch_size
     22     )
     23 

/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     85                 warnings.warn('Update your `' + object_name +
     86                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 87             return func(*args, **kwargs)
     88         wrapper._original_function = func
     89         return wrapper

TypeError: fit_generator() got an unexpected keyword argument 'shuffle'
```


Discussion:
I can verify that this is an issue on Keras v2.0.8. This looks like a documentation error to me. I don't see shuffle as an argument in the [source](https://github.com/fchollet/keras/blob/master/keras/models.py). This does not seem too surprising to me as shuffling using a generator is much more complicated than shuffling data in-memory as in the case of `fit()`
Thanks, @whistler.

I found two different implementations of `fit_generator` in the keras source.  One [`fit_generator` implementation](https://github.com/fchollet/keras/blob/8ac788a5614570d222c484ab49cf9e878eeab9ff/keras/engine/training.py#L2001) supports the use of a `shuffle` option when using a [`Sequence`](https://keras.io/utils/#sequence).  The other [`fit_generator` implementation](https://github.com/fchollet/keras/blob/48b8676e64dfe4ca4b81cc4286300ae60f140dca/keras/models.py#L1029) doesn't support using a `Sequence` or the accompanying `shuffle` option. 

I'm not sure why keras chooses one implementation over another.  I'm looking into it now.  I do see the word "legacy" in the source next to `fit_generator`, but I actually see it next to both of these implementations, so I'm not sure if that gets me anywhere.

Resolving patch:
diff --git a/keras/models.py b/keras/models.py
--- a/keras/models.py
+++ b/keras/models.py
@@ -1037,6 +1037,7 @@ def fit_generator(self, generator,
                       max_queue_size=10,
                       workers=1,
                       use_multiprocessing=False,
+                      shuffle=False,
                       initial_epoch=0):
         """Fits the model on data generated batch-by-batch by a Python generator.
 
@@ -1086,6 +1087,9 @@ def fit_generator(self, generator,
                 non picklable arguments to the generator
                 as they can't be passed
                 easily to children processes.
+            shuffle: Whether to shuffle the data at the beginning of each
+                epoch. Only used with instances of `Sequence` (
+                keras.utils.Sequence).
             initial_epoch: Epoch at which to start training
                 (useful for resuming a previous training run).
 
@@ -1126,6 +1130,7 @@ def generate_arrays_from_file(path):
                                         max_queue_size=max_queue_size,
                                         workers=workers,
                                         use_multiprocessing=use_multiprocessing,
+                                        shuffle=shuffle,
                                         initial_epoch=initial_epoch)
 
     @interfaces.legacy_generator_methods_support


Test patch: