def make_finite(data_gen):
    'An adapter for Keras data generators that makes them finite.\n\n  The default behavior in Keras is to keep looping infinitely through\n  the data.\n\n  Args:\n    data_gen: An infinite Keras data generator.\n\n  Yields:\n    Same values as the parameter generator.\n  '
    num_samples = data_gen.samples
    num_processed = 0
    for batch in data_gen:
        batch_size = batch[0].shape[0]
        if ((batch_size + num_processed) > num_samples):
            batch_size = (num_samples - num_processed)
            should_stop = True
        else:
            should_stop = False
        if (batch_size == 0):
            return
        batch = tuple((x[:batch_size] for x in batch))
        (yield batch)
        num_processed += batch_size
        if should_stop:
            return
An adapter for Keras data generators that makes them finite.

The default behavior in Keras is to keep looping infinitely through
the data.

Args:
  data_gen: An infinite Keras data generator.

Yields:
  Same values as the parameter generator.
def make_finite(data_gen):
    'An adapter for Keras data generators that makes them finite.\n\n  The default behavior in Keras is to keep looping infinitely through\n  the data.\n\n  Args:\n    data_gen: An infinite Keras data generator.\n\n  Yields:\n    Same values as the parameter generator.\n  '
    num_samples = data_gen.samples
    num_processed = 0
    for batch in data_gen:
        batch_size = batch[0].shape[0]
        if ((batch_size + num_processed) > num_samples):
            batch_size = (num_samples - num_processed)
            should_stop = True
        else:
            should_stop = False
        if (batch_size == 0):
            return
        batch = tuple((x[:batch_size] for x in batch))
        (yield batch)
        num_processed += batch_size
        if should_stop:
            return