简体   繁体   English

Keras:如何为每个时代改变数据

[英]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. model.fit 有一个 shuffle 参数,默认值为 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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