keras icon indicating copy to clipboard operation
keras copied to clipboard

Add `on_epoch_begin` to `utils.Sequence`

Open Cerno-b opened this issue 9 months ago • 2 comments

Could we have an on_epoch_begin() function in utils.Sequence?

There is already a on_epoch_end(), but I can see a use case for the begin equivalent:

Let's say I have a data generator that has a fixed internal set of data and maybe does some augmentation. If I want to ensure that all patches have been used in an epoch (say, for debugging reasons), I would add a count variable to the generator, set it to 0 on on_epoch_begin(), increment it on __getitem__() and check against my internal data size on on_epoch_end().

I could achieve this currently by setting count to 0 on on_epoch_end(), but this won't work, because keras may call __getitem__() before the first epoch actually starts (e.g. for internal preprocessing).

So the workaround that I currently use is to create a callback object, whose on_epoch_begin() calls a reset() function I put in my generator object. It's ugly, but works.

It would be much nicer to have a proper on_epoch_begin()

Cerno-b avatar May 23 '24 12:05 Cerno-b