简体   繁体   中英

Keras: how to mutate data for each epoch

I am trying to reduce overfitting by adding noise and random mutations to my original data.

I have a function that mutates training data

x, y = generate_data()

I would like the each epoch to call it and train my model on the new data. The hope is to reduce overfitting.

history = model.fit(x, y, epochs=100, batch_size=64)

What is the best way to change the data for each new epoch?

Just a guess. Try:

for _ in range(num_epochs):
    x, y = generate_data()
    history = model.fit(x, y, epochs=1, batch_size=64)

model.fit has a shuffle argument and the default value is True. So it shuffles the samples at each epoch.

def fit(self, x, y, batch_size=32, epochs=10, verbose=1, callbacks=None,
            validation_split=0., validation_data=None, shuffle=True,
            class_weight=None, sample_weight=None, initial_epoch=0, **kwargs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM