Home > database >  Suppressing printing epoch in PyGad
Suppressing printing epoch in PyGad

Time:06-02

I'm using Pygad to train a Keras NN through genetic algorithm, and as far as I can tell the code works, however, I do not know how to prevent it from printing the epoch in the terminal:

ga_instance = pygad.GA(num_generations=15, num_parents_mating=5, fitness_func=fitness_func, 
initial_population=keras_ga.population_weights, on_generation=on_generation, suppress_warnings=True)

As you can see here, I've already set suppress_warnings=True, however, when I run ga_instance.run(), the terminal will continue to print these texts:

1/1 [==============================] - 0s 34ms/step
1/1 [==============================] - 0s 36ms/step
1/1 [==============================] - 0s 34ms/step
1/1 [==============================] - 0s 36ms/step
1/1 [==============================] - 0s 31ms/step
1/1 [==============================] - 0s 29ms/step
1/1 [==============================] - 0s 29ms/step
1/1 [==============================] - 0s 29ms/step
1/1 [==============================] - 0s 29ms/step
1/1 [==============================] - 0s 37ms/step
1/1 [==============================] - 0s 38ms/step
1/1 [==============================] - 0s 33ms/step
1/1 [==============================] - 0s 34ms/step
1/1 [==============================] - 0s 32ms/step
1/1 [==============================] - 0s 31ms/step
1/1 [==============================] - 0s 29ms/step

I'm not sure if this issue is being caused by PyGad or Tensorflow, but I couldn't figured out a way to solve this.

Thank you for your time.

CodePudding user response:

Check the fitness and on_generation functions, if you use any print statements and remove them.

Otherwise, the PyGad doesn't print output with itself unless there are warnings or errors.

And you already prevented the suppress warnings

suppress_warnings: A bool parameter to control whether the warning messages are printed or not. It defaults to False. check the documentation for more information about the parameters: https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html

  • Related