AttributeError: 'ProgbarLogger' object has no attribute 'log_values'

错误表现

运行以下代码以训练模型:

train_model.fit_generator(
    train_generator.fit_iter(),
    steps_per_epoch=len(train_generator),
    epochs=20,
    callbacks=[evaluator]
)

遇到错误:

Epoch 1/25
Traceback (most recent call last):
  File "binary_classification.py", line 59, in <module>
    history=model.fit(X, y,batch_size=10, epochs=25,validation_split=0.7)
  File "/home/isabella/.local/lib/python3.6/site-packages/keras/engine/training.py",
line 1039, in fit
    validation_steps=validation_steps)
  File "/home/isabella/.local/lib/python3.6/site-packages/keras/engine/training_arrays.py",
line 217, in fit_loop
    callbacks.on_epoch_end(epoch, epoch_logs)
  File "/home/isabella/.local/lib/python3.6/site-packages/keras/callbacks.py",
line 79, in on_epoch_end
    callback.on_epoch_end(epoch, logs)
  File "/home/isabella/.local/lib/python3.6/site-packages/keras/callbacks.py",
line 338, in on_epoch_end
    self.progbar.update(self.seen, self.log_values)
AttributeError: 'ProgbarLogger' object has no attribute 'log_values'

错误原因

一般出现AttributeError: 'ProgbarLogger' object has no attribute 'log_values'这种错误, 是由于代码错误, 导致训练集为空, 或者训练集的大小不到一个batch size. 因此在keras更新训练的进度条时, 发生错误.

具体来说, 可能是喂给模型的训练集是空的; 或者在使用fit_generator方法时, 指定steps_per_epoch参数为0也会导致该错误.

解决方法

  • 检查代码中训练集生成部分, 以及steps_per_epoch参数是否为0.

  • 如果训练集生成没有错误, 且steps_per_epoch参数没有问题, 可以设置verbose=0, 不使用进度条, 解决此问题

参考资料

最后更新于