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

查看:686
本文介绍了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设置为

To make sure that you have "at least steps_per_epoch * epochs batches", set the steps_per_epoch to

steps_per_epoch = len(X_train)//batch_size

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

然后,每个时期将有足够的数据.重要的是,请记住,默认情况下,在 model.fit()中,batch_size为32 > .

Then, there will be enough data for every epoch. 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天全站免登陆