我有自定义回调,该回调将在某些情况下重置模型权重。但这会干扰EarlyStopping回调,从而保存最佳监视值,即“ val_loss”。如何从自定义回调到EarlyStopping回调中访问属性,以将其最佳“ val_loss”设置为我的值?
答案 0 :(得分:1)
设置您的早期塞子
early_stopping_callback.best = new_value
early_stopping_callback.wait = 0
基于source code, currently at line 816
将早期塞子放入其中:
class CustomCallback(...):
def __init__ (....., early_stopper, ...)
self.early_stopping_callback = early_stopper
.......
early_stopping = EarlyStopping(...)
custom = CustomCallback(...., early_stopping, ...)
您仍然需要将两个回调都传递给fit
:
model.fit(..., callbacks=[custom, early_stopping])