Without arguing the pros and cons of whether to actually do this, I'm curious if anyone has created or knows of a simple way to mutate the training data between epochs during the fitting of a model using keras.
Example: I have 100 vectors and output features that I'm using to train a model. I randomly pick 80 of them for the training set, setting the other 20 aside for validation, and then run:
model.fit(train_vectors,train_features,validation_data=(test_vectors,test_features))
Keras fitting allows one to shuffle the order of the training data with shuffle=True
but this just randomly changes the order of the training data. It might be fun to randomly pick just 40 vectors from the training set, run an epoch, then randomly pick another 40 vectors, run another epoch, etc.
https://keras.io/models/model/#fit
model.fit()
has an argument steps_per_epoch
. If you set shuffle=True
and choose steps_per_epoch
small enough you will get the behaviour that you describe.
In your example with 80 training examples: you could for instance set batch_size
to 20 and steps_per_epoch
to 4, or batch_size
to 10 and steps_per_epoch
to 8 etc.
I found that specifying both steps_per_epoch
and batch_size
raises error. You can find correspondent code lines in the code linked below (seek if steps is not None and batch_size is not None:
). Thus, we need to implement a data generator in order to realize such a behavior.
https://github.com/keras-team/keras/blob/1cf5218edb23e575a827ca4d849f1d52d21b4bb0/keras/engine/training_utils.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With