简体   繁体   English

Keras Batch Training回调串联

[英]Keras Batch Training Callback concatenation

I have a model in Keras, and due to a large dataset, I load it in batches using a generator. 我在Keras中有一个模型,由于数据集很大,我使用生成器批量加载它。 So the training routine is encapsulated in a for loop: 因此,训练例程封装在for循环中:

from keras.callbacks import History 

history = History()

for epoch in xrange(100):
  x_train,y_train=load_data_generator()
  model.fit(x_train, y_train, nb_epoch=1, batch_size=1000, verbose=2, validation_data=(x_test, y_test), callbacks=[history])

I would ideally like to have history for the entire training loop. 理想情况下,我希望拥有整个培训循环的历史记录。 However, keras seems to overwrite the history during each loop with the current batch. 但是,keras似乎会用当前批处理在每个循环期间覆盖历史记录。

Question 1) How can I easily concatenate history over all epochs? 问题1)我如何轻松地将所有时期的历史串联起来? In other words trick it into resuming where it left off in the prior history. 换句话说,欺骗它恢复在先前历史记录中遗留的位置。

Question 2) Each time keras completes an epoch, it prints the number of the epoch. 问题2)每次keras完成一个纪元时,它都会打印该纪元的编号。 Since I do training in batches, is there an easy way of updating the epoch? 由于我分批进行培训,是否有一种简便的方法来更新纪元? I've seen a 'initial_epoch' parameter for the fitting routine, but it sounds like that would revert to a prior epoch. 我已经看到了拟合例程的“ initial_epoch”参数,但听起来好像会还原为先前的纪元。

Can you try to set the initial_epoch = epoch inside the fit call? 您可以尝试在fit调用中设置initial_epoch = epoch吗?

I would assume that it will then append the information to your History callback since it's a new epoch every time. 我认为它会将信息附加到您的History回调中,因为每次都是新纪元。 The number of the epoch will also be incremented at each step of the loop. 在循环的每个步骤中,纪元的数量也将增加。

I hope this helps. 我希望这有帮助。

You may find the documentation on image preprocessing in Keras helpful in understanding the use of data generators. 您可能会发现Keras中有关图像预处理的文档有助于理解数据生成器的使用。 I believe that both of your issues will be solved by using the fit_generator() function instead of fit() . 我相信,通过使用fit_generator()函数而不是fit()可以解决您的两个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM