在 PyGad 中抑制打印纪元

Suppressing printing epoch in PyGad

我正在使用 Pygad 通过遗传算法训练 Keras NN,据我所知代码有效,但是,我不知道如何防止它在终端中打印纪元:

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)

正如你在这里看到的,我已经设置了suppress_warnings=True,然而,当我运行ga_instance.run()时,终端将继续打印这些文本:

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

我不确定这个问题是由 PyGad 还是 Tensorflow 引起的,但我想不出解决这个问题的方法。

感谢您的宝贵时间。

检查 fitnesson_generation 函数,如果您使用任何打印语句并删除它们。

否则,PyGad 不会自行打印输出,除非有警告或错误。

并且您已经阻止了抑制警告

suppress_warnings:bool参数,控制是否打印警告信息。它默认为假。查看文档以获取有关参数的更多信息:https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html