Early Stop Callback does not work with Keras LSTM policy


I have defined an Early Stop callback for the Keras LSTM policy and I pass it to the Agent as follows:

kwargs["callbacks"] = [
        EarlyStopping(monitor="val_acc", mode="max", min_delta=0.2, patience=2)

agent.train(training_data, **kwargs)

However, it does not work. Any idea on what I am doing wrong?

L-P from Dialogue

Hi, we don’t support passing policy parameters through agent. You should initialize KerasPolicy with it

Thanks, this works :slight_smile:


I have also been trying to get EarlyStopping to work.

I tried subclassing KerasPolicy and passing the callback as kwargs.

class OurKerasPolicy(KerasPolicy):
def __init__(self, **kwargs: Any):
    kwargs["callbacks"] = [
        EarlyStopping(monitor="val_loss", mode="min", min_delta=0.5, patience=2),
    print(f"KerasPolicy kwargs = {kwargs}")

But the callback is never triggered.

could you please check that callbacks are actually passed to self.model.fit?