Repository: keras-team/keras

Issue:
predict_generator verbose option?
I think it would be really useful if the predict_generator method had a verbose option. I would like to see the progress as predictions are made.



Discussion:
yep. I have a test set of 500K images, and verbose would definitely help
+1 !!!
+1

If no one else is working on this, I'll work on a PR.

Resolving patch:
diff --git a/keras/engine/training.py b/keras/engine/training.py
--- a/keras/engine/training.py
+++ b/keras/engine/training.py
@@ -2021,7 +2021,8 @@ def evaluate_generator(self, generator, steps,
 
     @interfaces.legacy_generator_methods_support
     def predict_generator(self, generator, steps,
-                          max_q_size=10, workers=1, pickle_safe=False):
+                          max_q_size=10, workers=1,
+                          pickle_safe=False, verbose=0):
         """Generates predictions for the input samples from a data generator.
 
         The generator should return the same kind of data as accepted by
@@ -2041,6 +2042,7 @@ def predict_generator(self, generator, steps,
                 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.
@@ -2060,6 +2062,9 @@ def predict_generator(self, generator, steps,
             enqueuer = GeneratorEnqueuer(generator, pickle_safe=pickle_safe)
             enqueuer.start(workers=workers, max_q_size=max_q_size)
 
+            if verbose == 1:
+                progbar = Progbar(target=steps)
+
             while steps_done < steps:
                 generator_output = None
                 while enqueuer.is_running():
@@ -2097,6 +2102,8 @@ def predict_generator(self, generator, steps,
                 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:
diff --git a/keras/models.py b/keras/models.py
--- a/keras/models.py
+++ b/keras/models.py
@@ -1138,7 +1138,8 @@ def evaluate_generator(self, generator, steps,
 
     @interfaces.legacy_generator_methods_support
     def predict_generator(self, generator, steps,
-                          max_q_size=10, workers=1, pickle_safe=False):
+                          max_q_size=10, workers=1,
+                          pickle_safe=False, verbose=0):
         """Generates predictions for the input samples from a data generator.
 
         The generator should return the same kind of data as accepted by
@@ -1155,6 +1156,7 @@ def predict_generator(self, generator, steps,
                 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
             A Numpy array of predictions.
@@ -1164,7 +1166,8 @@ def predict_generator(self, generator, steps,
         return self.model.predict_generator(generator, steps,
                                             max_q_size=max_q_size,
                                             workers=workers,
-                                            pickle_safe=pickle_safe)
+                                            pickle_safe=pickle_safe,
+                                            verbose=verbose)
 
     def get_config(self):
         if isinstance(self.layers[0], legacy_layers.Merge):


Test patch:
diff --git a/tests/keras/test_sequential_model.py b/tests/keras/test_sequential_model.py
--- a/tests/keras/test_sequential_model.py
+++ b/tests/keras/test_sequential_model.py
@@ -122,7 +122,7 @@ def data_generator(x, y, batch_size=50):
 
     loss = model.evaluate(x_test, y_test)
 
-    prediction = model.predict_generator(data_generator(x_test, y_test), 1, max_q_size=2)
+    prediction = model.predict_generator(data_generator(x_test, y_test), 1, max_q_size=2, verbose=1)
     gen_loss = model.evaluate_generator(data_generator(x_test, y_test, 50), 1, max_q_size=2)
     pred_loss = K.eval(K.mean(losses.get(model.loss)(K.variable(y_test), K.variable(prediction))))