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

Saving after training an epoch #45

Open
25icecreamflavors opened this issue Aug 17, 2022 · 3 comments
Open

Saving after training an epoch #45

25icecreamflavors opened this issue Aug 17, 2022 · 3 comments

Comments

@25icecreamflavors
Copy link

How to save the model after each epoch training? I use fit method for 5 epochs and do not really understand hot to save after each one. not only after the last one.

@abhishekkrthakur
Copy link
Owner

you can use the EarlyStopping callback and save on each epoch where there is an improvement. here is an example: https://github.com/abhishekkrthakur/tez/blob/main/examples/image/digit_recognizer.py#L175

@25icecreamflavors
Copy link
Author

I'm not sure, will this stop training if there is no improvement for next epoch (I need to continue training anyway)? And do this function saves a model after the whole epoch, not somewhere in the middle right?

@gullayeshwantkumarruler
Copy link

gullayeshwantkumarruler commented Apr 14, 2023

You can create a custom callback and use model.save() to save the model at each epoch or if you want to save some specific epochs, that can also be done and that would help in saving model after each epoch, You can use something similar to below code, it maynot perfect but you can create a custom callback similarly

`
class CustomSaver(tez.callbacks.Callback):

    def on_epoch_end(self, epoch, logs={}):

        if epoch <=20:  # or save after some epoch, upto 20

            self.model.save("model_{}.hd5".format(epoch))

`

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

No branches or pull requests

3 participants