我早早在keras停留了 early_stopping = kr.callbacks.EarlyStopping(monitor ='val_loss', 耐心= 10,详细= 1,模式='自动') 但是,我得到的结果如下:
epoch = 2时的val_loss是0.6683,epoch = 3的val> 0.6683,但是训练开始起作用,val开始从纪元3开始减少。当我设定耐心= 10时,我希望训练将在10个连续的时期停止,没有任何改进,不仅比较纪元2和纪元12那样。有人知道如何解决这个问题吗?谢谢。
答案 0 :(得分:0)
我修复了,刚刚修改了keras.callbacks.EarlyStopping:
代替
if self.monitor_op(current - self.min_delta, self.best):
self.best = current
self.wait = 0
else:
self.wait += 1
if self.wait >= self.patience:
self.stopped_epoch = epoch
self.model.stop_training = True
通过
if epoch==1:
self.previous=logs.get(self.monitor)
#if val_loss of current < previous, set wait=0
#if self.monitor_op(current - self.min_delta, self.best):
if self.monitor_op(current - self.min_delta, self.previous):
# if current < self.previous:
self.wait = 0
else: #if val_loss of current > previous, that means performance pause improving, then set wait+=1
self.wait += 1
print 'now: ' +str(current) + ', pre: ' +str(self.previous) + 'not improved! wait:' + str(self.wait)
if self.wait >= self.patience: #if wait reach limitation, then stopping training
self.stopped_epoch = epoch
self.model.stop_training = True
if epoch>1:
self.previous=logs.get(self.monitor)
答案 1 :(得分:0)
您可以根据Keras Documentation编写自己的回调。在这种情况下,您想要做的是从Keras版本的EarlyStopping中编辑on_epoch_end()
方法。与其跟踪最佳值,不如跟踪先前的值,看看它是否连续10次没有改善。