goldjunge
goldjunge

Reputation: 341

Is it possible to set value in different Keras callback?

I have custom callback that will reset model weights on some conditions. But this will interfere with EarlyStopping callback saves best monitored value i.e. 'val_loss'. How can I access properties from my custom callback to EarlyStopping callback to set its best 'val_loss' to my value ?

Upvotes: 1

Views: 92

Answers (1)

Daniel Möller
Daniel Möller

Reputation: 86620

Set in your early stopper:

early_stopping_callback.best = new_value
early_stopping_callback.wait = 0

Based on the source code, currently at line 816


Putting the early stopper inside:

class CustomCallback(...):
    def __init__ (....., early_stopper, ...)
        self.early_stopping_callback = early_stopper

    .......

early_stopping = EarlyStopping(...)
custom = CustomCallback(...., early_stopping, ...)

You still need to pass both callbacks to fit:

model.fit(..., callbacks=[custom, early_stopping])    

Upvotes: 1

Related Questions