如何在Keras的每个时代保存培训历史? [英] How to save training history on every epoch in Keras?
问题描述
我无法整天保持PC的运行状态,为此,我需要在每个时期之后保存培训历史记录.例如,我一天训练了我的模型100个纪元,第二天,我想再训练50个纪元.我需要为整个150个历元生成损耗与历元以及准确性与历元图.我正在使用 fit_generator
方法.有没有什么方法可以在每个时期后保存培训历史记录(最有可能使用 Callback
)?培训结束后,我知道如何保存培训历史记录.我正在使用Tensorflow后端.
I can't keep my PC running all day long, and for this I need to save training history after every epoch. For example, I have trained my model for 100 epochs in one day, and on the next day, I want to train it for another 50 epochs. I need to generate the loss vs epoch and accuracy vs epoch graphs for the whole 150 epochs. I am using fit_generator
method. Is there any way to save the training history after every epoch (most probably using Callback
)? I know how to save the training history after the training has ended. I am using Tensorflow backend.
推荐答案
Keras具有CSVLogger回调,该回调似乎完全可以满足您的需要;从文档:
Keras has the CSVLogger callback which appears to do exactly what you need; from the documentation:
将纪元结果流式传输到CSV文件的回调.
Callback that streams epoch results to a CSV file.
它具有用于添加到文件的附加参数.再次,从文档中:
It has an append parameter for adding to the file. Again, from the documentation:
追加:布尔值.True:如果文件存在,则追加(用于继续培训).False:覆盖现有文件
append: Boolean. True: append if file exists (useful for continuing training). False: overwrite existing file
来自keras.callbacks的
from keras.callbacks import CSVLogger
csv_logger = CSVLogger("model_history_log.csv", append=True)
model.fit_generator(...,callbacks=[csv_logger])
这篇关于如何在Keras的每个时代保存培训历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!