'Generates predictions for the input samples from a data generator.
The generator should return the same kind of data as accepted by
`predict_on_batch`.
# Arguments
generator: Generator yielding batches of input samples
or an instance of Sequence (keras.utils.Sequence)
object in order to avoid duplicate data
when using multiprocessing.
steps: Total number of steps (batches of samples)
to yield from `generator` before stopping.
max_queue_size: Maximum size for the generator queue.
workers: Maximum number of processes to spin up
when using process based threading
use_multiprocessing: If `True`, use process based threading.
Note that because
this implementation relies on multiprocessing,
you should not pass
non picklable arguments to the generator
as they can\'t be passed
easily to children processes.
verbose: verbosity mode, 0 or 1.
# Returns
Numpy array(s) of predictions.
# Raises
ValueError: In case the generator yields
data in an invalid format.'

@interfaces.legacy_generator_methods_support
def predict_generator(self, generator, steps, max_queue_size=10, workers=1, use_multiprocessing=False, verbose=0):

    self._make_predict_function()
    steps_done = 0
    wait_time = 0.01
    all_outs = []
    is_sequence = isinstance(generator, Sequence)
    if ((not is_sequence) and use_multiprocessing and (workers > 1)):
        warnings.warn(UserWarning('Using    a    generator    with    `use_multiprocessing=True`    and    multiple    workers    may    duplicate    your    data.    Please    consider    using    the`keras.utils.Sequence    class.'))
    enqueuer = None
    try:
        if is_sequence:
            enqueuer = OrderedEnqueuer(generator, use_multiprocessing=use_multiprocessing)
        else:
            enqueuer = GeneratorEnqueuer(generator, use_multiprocessing=use_multiprocessing, wait_time=wait_time)
        enqueuer.start(workers=workers, max_queue_size=max_queue_size)
        output_generator = enqueuer.get()
        if (verbose == 1):
            progbar = Progbar(target=steps)
        while (steps_done < steps):
            generator_output = next(output_generator)
            if isinstance(generator_output, tuple):
                if (len(generator_output) == 2):
                    (x, _) = generator_output
                elif (len(generator_output) == 3):
                    (x, _, _) = generator_output
                else:
                    raise ValueError(('Output    of    generator    should    be    a    tuple    `(x,    y,    sample_weight)`    or    `(x,    y)`.    Found:    ' + str(generator_output)))
            else:
                x = generator_output
            outs = self.predict_on_batch(x)
            if (not isinstance(outs, list)):
                outs = [outs]
            if (not all_outs):
                for out in outs:
                    all_outs.append([])
            for (i, out) in enumerate(outs):
                all_outs[i].append(out)
            steps_done += 1
            if (verbose == 1):
                progbar.update(steps_done)
    finally:
        if (enqueuer is not None):
            enqueuer.stop()
    if (len(all_outs) == 1):
        if (steps_done == 1):
            return all_outs[0][0]
        else:
            return np.concatenate(all_outs[0])
    if (steps_done == 1):
        return [out for out in all_outs]
    else:
        return [np.concatenate(out) for out in all_outs]
