tensorflow:您的输入数据用完 [英] tensorflow:Your input ran out of data

查看:18
本文介绍了tensorflow:您的输入数据用完的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 seq2seq keras/tensorflow 2.0 模型.每次用户输入内容时,我的模型都会完美地打印响应.但是在每个回复的最后一行,我得到了这个:

I am working on a seq2seq keras/tensorflow 2.0 model. Every time the user inputs something, my model prints the response perfectly fine. However on the last line of each response I get this:

你:警告:tensorflow:你的输入数据用完了;中断训练.确保您的数据集或生成器至少可以生成 steps_per_epoch * epochs 个批次(在本例中为 2 个批次).在构建数据集时,您可能需要使用 repeat() 函数.

You: WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least steps_per_epoch * epochs batches (in this case, 2 batches). You may need to use the repeat() function when building your dataset.

你:"是我的最后一个输出,在用户应该输入新内容之前.模型工作得很好,但我想没有错误是好的,但我不太明白这个错误.它说中断训练",但是我没有在训练任何东西,这个程序加载了一个已经训练好的模型.我想这就是错误没有停止程序的原因?

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")

推荐答案

要确保您至少有 steps_per_epoch * epochs 个批次",请设置steps_per_epoch

steps_per_epoch = len(X_train)//batch_size

validation_steps = len(X_test)//batch_size # if you have validation data 

您可以在训练中断时通过进度条看到model.fit()可以接受的最大批次数:

You can see the maximum number of batches that model.fit() can take by the progress bar when the training interrupts:

5230/10000 [==============>...............] - ETA: 2:05:22 - loss: 0.0570

这里,最大值为 5230 - 1

Here, the maximum would be 5230 - 1

重要的是,请记住,默认情况下,batch_sizemodel.fit().

Importantly, keep in mind that by default, batch_size is 32 in model.fit().

如果您使用的是 tf.data.Dataset,您还可以添加 repeat() 方法,但要小心:它会无限循环(除非你指定一个数字).

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).

这篇关于tensorflow:您的输入数据用完的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆