What does “shuffle” do in fit_generator in Keras TensorFlow
In this tutorial, we will learn about one of the arguments of fit-generator namely shuffle using Keras API od TensorFlow. Before starting a discussion on shuffle, Let’s first understand what is fit_generator and why is it used?
Fit_generator is the function used to fit training data in the models. We use fit_generator when we have large datasets that need extra data augmentation and data normalization to get satisfactory results and avoid overfishing. Let’s see the syntax of how it is used.
fit_generator ( generator, steps_per_epoch: NoneType=None, epochs: int=1, verbose: int=1, callbacks: NoneType=None, validation_data: NoneType=None, validation_steps: NoneType=None, class_weight: NoneType=None, max_queue_size: int=10, workers: int=1, use_multiprocessing: bool=False, shuffle: bool=True, initial_epoch: int=0 )
A generator‘s output must be a list of the form:
- (inputs, targets)
- (input, targets, sample_weights)
It is used with sequential models.
steps_per_epoch: It tells us the steps taken in one epoch. As soon as one epoch is over next starts. It is used to regulate gradient descent.
epochs: Number of epochs that we want our model to train on.
validation_data: This data is used to evaluate the model’s accuracy and loss.
verbose: This tells us what output will be shown during training.
- It has a Boolean value i.e is it can either True or False. It is enabled when it is set as True.
- It decides whether to shuffle the order of the input before starting each epoch.
- It is used with Sequence modelling.
- So basically, The shuffles help to feed different data into the model during training,
- It has no effect when `steps_per_epoch` is defined.
- It helps with the accuracy of the model by getting different batches of input before each epoch. So the model is trained on a variety of dataset. To avoid Overfitting.