简体   繁体   English

验证数据可以是 tensorflow.keras 2.0 中的生成器(而训练数据是数组)吗?

[英]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.

相关问题 验证数据可以是 tensorflow.keras 2.0 中的生成器吗? - Could validation data be a generator in tensorflow.keras 2.0? 如何将自定义数据生成器输入到 model.fit 中,它会生成 X,y 和一个额外的数组,到 tensorflow.keras Z20F4ZF011622Z Z20F4ZF35E630DAF39466 - How to input custom data generator into model.fit, which generates X,y and one additional array, into tensorflow.keras model? TensorFlow / Keras 拆分训练和验证数据 - TensorFlow / Keras splitting training and validation data tensorflow.keras model 准确度、损失和验证指标在训练期间保持 ZA81259CEF8E959C2297DF1D456EZ5 - tensorflow.keras model accuracy, loss, and validation metrics remain static during 30 epochs of training Tensorflow 2.0-Keras培训 - Tensorflow 2.0 - keras training 输入训练数据时,Keras似乎比张量流慢 - Keras seems slower than tensorflow while feeding training data Tensorflow.keras 没有训练和停止错误“没有算法工作!” 在 Colab - Tensorflow.keras not training and stoping with error 'No algorithm worked!' in Colab 如何在训练期间替换损失函数 tensorflow.keras - How to replace loss function during training tensorflow.keras tensorflow 2 使用 keras.sequence 作为训练机器学习的数据生成器 model 具有多处理错误 - tensorflow 2 use keras.sequence as data generator for training machine learning model with multiprocessing error 在训练keras模型时如何使用数据生成器更快地生成数据? - How to use data generator to generate data faster while training keras model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM