[英]Could validation data be a generator (while training data is Array) in tensorflow.keras 2.0?
I want to train a model with tensorflow.keras
.我想用tensorflow.keras
训练一个模型。 And I hope to do some other things between every training step, that's why I can not use fit_generator
to train my model.我希望在每个训练步骤之间做一些其他的事情,这就是为什么我不能使用fit_generator
来训练我的模型。 In the other words, I hope to train model by looping fit
function like follows:换句话说,我希望通过循环fit
函数来训练模型,如下所示:
training_data_generator = ...
validation_data_generator = ...
for i in range(steps_number):
x, y = next(training_data_generator )
net.fit(x, y)
do_other_things_function()
if steps_number%100==0:
net.fit(x, y, validation_data = validation_data_generator)
But it failed.但它失败了。 The reason may be that my training data is a numpy array in net.fit(x, y, validation_data = validation_data_generator)
, but my validation data is a generator.原因可能是我的训练数据是net.fit(x, y, validation_data = validation_data_generator)
一个 numpy 数组,但我的验证数据是一个生成器。
So my question is: how to use a numpy array as training data and generaor as validation data at the same time??所以我的问题是:如何同时使用 numpy 数组作为训练数据和生成器作为验证数据?
I recommend you turn your train data into a generator and use fit_generator()
instead of fit()
我建议您将您的火车数据转换为生成器并使用fit_generator()
而不是fit()
There are more ways to tackle this, first, look at this question about how to change NumPy array to a generator, and if you need a more robust and detailed explanation look at this post.有更多方法可以解决这个问题,首先,看看这个关于如何将 NumPy 数组更改为生成器的问题,如果您需要更强大和详细的解释,请查看这篇文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.