简体   繁体   English

tensorflow:您的输入数据用完

[英]tensorflow:Your input ran out of data

I am working on a seq2seq keras/tensorflow 2.0 model.我正在研究 seq2seq keras/tensorflow 2.0 模型。 Every time the user inputs something, my model prints the response perfectly fine.每次用户输入内容时,我的模型都会完美地打印响应。 However on the last line of each response I get this:但是在每个回复的最后一行我得到这个:

You: WARNING:tensorflow:Your input ran out of data;你:警告:tensorflow:你的输入数据用完了; interrupting training.中断训练。 Make sure that your dataset or generator can generate at least steps_per_epoch * epochs batches (in this case, 2 batches).确保您的数据集或生成器至少可以生成steps_per_epoch * epochs批次(在本例中为 2 个批次)。 You may need to use the repeat() function when building your dataset.在构建数据集时,您可能需要使用 repeat() 函数。

The "You:" is my last output, before the user is supposed to type something new in. The model works totally fine, but I guess no error is ever good, but I don't quite get this error. “你:”是我的最后一个输出,在用户应该输入新的东西之前。模型工作得很好,但我想没有错误是好的,但我不太明白这个错误。 It says "interrupting training", however I am not training anything, this program loads an already trained model.它说“中断训练”,但是我没有在训练任何东西,这个程序加载了一个已经训练好的模型。 I guess this is why the error is not stopping the program?我想这就是错误没有停止程序的原因?

In case it helps, my model looks like this:如果有帮助,我的模型如下所示:

intent_model = keras.Sequential([
    keras.layers.Dense(8, input_shape=[len(train_x[0])]),  # input layer
    keras.layers.Dense(8),  # hidden layer
    keras.layers.Dense(len(train_y[0]), activation="softmax"),  # output layer
])

intent_model.compile(optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"])
intent_model.fit(train_x, train_y, epochs=epochs)

test_loss, test_acc = intent_model.evaluate(train_x, train_y)
print("Tested Acc:", test_acc)

intent_model.save("models/intent_model.h5")

To make sure that you have " at least steps_per_epoch * epochs batches ", set the steps_per_epoch to为了确保你有“至少steps_per_epoch * epochs batches ”,将steps_per_epoch设置为

steps_per_epoch = len(X_train)//batch_size
validation_steps = len(X_test)//batch_size # if you have test data

Then, there will be enough data for every epoch.然后,每个时期都会有足够的数据。 Importantly, keep in mind that by default, batch_size is 32 in model.fit() .重要的是,请记住,默认情况下, model.fit() batch_size为 32。

If you're using a tf.data.Dataset , you can also add the repeat() method, but be careful: it will loop indefinitely (unless you specify a number).如果您使用的是tf.data.Dataset ,您还可以添加repeat()方法,但要小心:它会无限循环(除非您指定一个数字)。

I have also had a number of models crash with the same warnings while trying to train them.我也有许多模型在尝试训练时崩溃并发出相同的警告。 The training dataset if created using the tf.keras.preprocessing.image_dataset_from_directory() and split 80/20.训练数据集如果使用 tf.keras.preprocessing.image_dataset_from_directory() 创建并分割 80/20。 I have created a variable to try and not run out of image.我创建了一个变量来尝试不要用完图像。 Using ResNet50 with my own images.....将 ResNet50 与我自己的图像一起使用.....

TRAIN_STEPS_PER_EPOCH = np.ceil((image_count*0.8/BATCH_SIZE)-1)
# to ensure that there are enough images for training bahch
VAL_STEPS_PER_EPOCH = np.ceil((image_count*0.2/BATCH_SIZE)-1)

but it still does.但它仍然如此。 BATCH_SIZE is set to 32 so i am taking 80% of the number of images and dividing by 32 then taking away 1 to have surplus.....or so i thought. BATCH_SIZE 设置为 32,所以我取图像数量的 80%,然后除以 32,然后拿走 1 以获得剩余......或者我想。

history = model.fit(
        train_ds,
        steps_per_epoch=TRAIN_STEPS_PER_EPOCH,
        epochs=EPOCHS,
        verbose = 1,
        validation_data=val_ds,
        validation_steps=VAL_STEPS_PER_EPOCH,
        callbacks=tensorboard_callback)

Error after 3 hours processing aa single successful Epoch is:处理一个成功的 Epoch 3 小时后的错误是:

Epoch 1/25 374/374 [==============================] - 8133s 22s/step - loss: 7.0126 - accuracy: 0.0028 - val_loss: 6.8585 - val_accuracy: 0.0000e+00 Epoch 2/25 1/374 [..............................] - ETA: 0s - loss: 6.0445 - accuracy: 0.0000e+00WARNING:tensorflow:Your input ran out of data;纪元 1/25 374/374 [==============================] - 8133s 22s/步 - 损失:7.0126 - 准确度: 0.0028 - val_loss: 6.8585 - val_accuracy: 0.0000e+00 Epoch 2/25 1/374 [........................ .] - ETA:0s - 损失:6.0445 - 准确度:0.0000e+00WARNING:tensorflow:您的输入数据用完了; interrupting training.中断训练。 Make sure that your dataset or generator can generate at least steps_per_epoch * epochs batches (in this case, 9350.0 batches).确保您的数据集或生成器至少可以生成steps_per_epoch * epochs批次(在本例中为 9350.0 个批次)。 You may need to use the repeat() function when building your dataset.在构建数据集时,您可能需要使用 repeat() 函数。

this might help....这可能会有所帮助....

> > print(train_ds) <BatchDataset shapes: ((None, 224, 224, 3), (None,)), types: (tf.float32, tf.int32)>
> 
> print(val_ds) BatchDataset shapes: ((None, 224, 224, 3), (None,)),types: (tf.float32, tf.int32)>
> 
> print(TRAIN_STEPS_PER_EPOCH)
> 374.0
> 
> print(VAL_STEPS_PER_EPOCH)
> 93.0

Solution which worked for me was to set drop_remainder=True while generating the dataset.对我drop_remainder=True解决方案是在生成数据集时设置drop_remainder=True This automatically handles any extra data that is left over.这会自动处理剩余的任何额外数据。

For example:例如:

dataset = tf.data.Dataset.from_tensor_slices((images, targets)) \
        .batch(12, drop_remainder=True)

I had the same problem in TF 2.1.我在 TF 2.1 中遇到了同样的问题。 It has something to do with the shape/ type of the input, namely the query.它与输入的形状/类型有关,即查询。 In my case, I solved the problem as follows: (My model takes 3 inputs)就我而言,我解决了以下问题:(我的模型需要 3 个输入)

x = [[test_X[0][0]], [test_X[1][0]], [test_X[2][0]]]
MODEL.predict(x)

Output:输出:

WARNING:tensorflow:Your input ran out of data;警告:tensorflow:您的输入数据不足; interrupting training.中断训练。 Make sure that your dataset or generator can generate at least steps_per_epoch * epochs batches (in this case, 7 batches).确保您的数据集或生成器至少可以生成steps_per_epoch * epochs批次(在本例中为 7 个批次)。 You may need to use the repeat() function when building your dataset.在构建数据集时,您可能需要使用 repeat() 函数。

array([[2.053718]], dtype=float32)数组([[2.053718]],dtype=float32)

Solution:解决方案:

x = [np.array([test_X[0][0]]), np.array([test_X[1][0]]), np.array([test_X[2][0]])]
MODEL.predict(x)

Output:输出:

array([[2.053718]], dtype=float32)数组([[2.053718]],dtype=float32)

我遇到了同样的问题,将validation_steps 从 50 减少到 10 解决了这个问题。

I understand that it is completely fine.我明白这完全没问题。 Firstly.首先。 it is a warning not an error.这是警告而不是错误。 Secondly, the situation is similar to one data is trained during one epoch, next epoch trains next data and you have set epochs value too high eg500 (assuming your data size is not fixed but will approximately be <=500).其次,情况类似于在一个时期训练一个数据,下一个时期训练下一个数据并且您将时期值设置得太高,例如500(假设您的数据大小不固定,但大约 <=500)。 Suppose data size is 480. Now, the remaining epoch don't have any data left to process, hence the warning.假设数据大小为 480。现在,剩余的 epoch 没有任何要处理的数据,因此出现警告。 As a result, it returns to the recent state when the last data was trained.结果,当最后一个数据被训练时,它返回到最近的状态。 I hope this helps.我希望这有帮助。 Do let me know if the concept is misunderstood.如果这个概念被误解了,请告诉我。 Thanks!谢谢!

Try reducing the steps_per_epoch value below the value you have currently set.尝试将 steps_per_epoch 值降低到您当前设置的值以下。 This helped me solve the problem这帮助我解决了问题

Remove steps_per_epoch and validation_steps parameters in model.fit , if you create a dataset with image_dataset_from_directory .删除steps_per_epochvalidation_steps在参数model.fit ,如果你创建一个数据集image_dataset_from_directory

because the steps was initiated when batch_size passed into image_dataset_from_directory因为这些步骤是在batch_size传入image_dataset_from_directory时启动的

You can trying get the length of dataset created with image_dataset_from_directory , it is steps number.您可以尝试获取使用image_dataset_from_directory创建的数据集的长度,它是步数。

我在 google colab 中训练模型时也得到了这个,原因是没有足够的内存/RAM 来存储每批的数据量(如果你使用的是批),所以在我降低 batch_size 之后,它都运行得很好

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

相关问题 tensorflow:使用自定义生成器时您的输入用完了数据 - tensorflow:Your input ran out of data when using custom generator 警告:tensorflow:您的输入数据不足; 中断训练 - WARNING:tensorflow:Your input ran out of data; interrupting training tensorflow 2.0, model.fit() :您的输入数据不足 - tensorflow 2.0, model.fit() : Your input ran out of data “WARNING:tensorflow:Your input run out of data”训练时出现错误 Keras Model - “WARNING:tensorflow:Your input ran out of data” Error appearing when training Keras Model 训练时出错:tensorflow:你的输入数据用完了; 中断训练 - Error while training: tensorflow:Your input ran out of data; interrupting training Tensorflow 输入生成器用完了数据 - Tensorflow input generator ran out of data &#39;tf.data()&#39; throwing 你的输入数据用完了; 中断训练 - 'tf.data()' throwing Your input ran out of data; interrupting training 您输入的数据不足; 中断训练。 确保您的数据集或生成器至少可以生成`steps_per_epoch - Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch 输入用完数据错误但数据在那里 - Input ran out of Data error but the data is there 输入的数据用完了; 中断训练 - input ran out of data; interrupting training
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM