Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback for earlystopping #20

Open
piyushmadan opened this issue Jan 16, 2019 · 1 comment
Open

Add callback for earlystopping #20

piyushmadan opened this issue Jan 16, 2019 · 1 comment
Assignees

Comments

@piyushmadan
Copy link

It will be good to have an option to early stop or easily add other callbacks from keras.

@maet3608 maet3608 self-assigned this Jan 31, 2019
@maet3608
Copy link
Owner

maet3608 commented Jan 31, 2019

The KerasNetwork wrapper does not support callbacks because the underlying Keras API (train_on_batch()) does not support it. However, you can use model.fit_generator
(and not use the KerasNetwork wrapper):

model = Sequential()
...

batches = train_samples >> Cycle() >> read_big_data >> ... >> build_batch
model.fit_generator(batches, callbacks=...)

More info can be found here: https://maet3608.github.io/nuts-ml/tutorial/network.html

You have to make sure that train_samples can be loaded into memory,
and all big data, e.g. images are loaded after Cycle() !

Alternatively, you can run the epoch loop explicitly and do early stopping there, e.g.

network = KerasNetwork(model)
for epoch in range(EPOCHS):
    t_loss, t_acc = (train_samples >> read_image >> transform >> augment >>
                     Shuffle(100) >> build_batch >> network.train() >> Unzip())

    v_loss, v_acc = (val_samples >> read_image >> transform >>
                     build_batch >> network.validate() >> Unzip())

    network.save_best(v_loss >> Mean(), isloss=True)  # early stopping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants