When training neural networks, we generally feed data into them in small batches, called mini-batches or just “batches” (for more information on mini-batch gradient descent, see my tutorial here). Keras has some handy functions which can extract training data automatically from a pre-supplied Python iterator/generator object and input it to the model. One of these Keras functions is called fit_generator. The first argument to fit_generator is the Python iterator function that we will create, and it will be used to extract batches of data during the training process. This function in Keras will handle all of the data extraction, input into the model, executing gradient steps, logging metrics such as accuracy and executing callbacks (these will be discussed later). The Python iterator function needs to have a form like: