当传递一个无限重复的数据集时,你必须指定`steps_per_epoch`参数。

问题描述 投票:1回答:1

我正在尝试使用这个Google的例子,但用我自己的数据集。

https:/github.comtensorflowexamplesblobmastertensorflow_exampleslitemodel_customizationdemotext_classification.ipynb。

我创建了一个类似于他们代码中下载的文件夹,里面有训练和测试文件夹以及txt文件。

在我的例子中,data_path如下。data_path = '/Users/developer/.keras/datasets/chat'

每当我尝试运行它时 model = text_classifier.create(train_data) 抛出一个错误 ValueError: When passing an infinitely repeating dataset, you must specify the `steps_per_epoch` argument.这到底是什么意思,我应该在哪里寻找问题?


import numpy as np
import os
import tensorflow as tf
assert tf.__version__.startswith('2')

from tensorflow_examples.lite.model_customization.core.data_util.text_dataloader import TextClassifierDataLoader
from tensorflow_examples.lite.model_customization.core.model_export_format import ModelExportFormat
import tensorflow_examples.lite.model_customization.core.task.text_classifier as text_classifier


# data_path = tf.keras.utils.get_file(
#       fname='aclImdb',
#       origin='http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz',
#       untar=True)

data_path = '/Users/developer/.keras/datasets/chat'

train_data = TextClassifierDataLoader.from_folder(os.path.join(data_path, 'train'), class_labels=['greeting', 'goodbye'])
test_data = TextClassifierDataLoader.from_folder(os.path.join(data_path, 'test'), shuffle=False)

model = text_classifier.create(train_data)
loss, acc = model.evaluate(test_data)
model.export('movie_review_classifier.tflite', 'text_label.txt', 'vocab.txt')
python tensorflow tensorflow-datasets tensorflow2.0 tensorflow-lite
1个回答
1
投票

我有一个类似的问题,然后在model.fit下我添加了 steps_per_epoch

history = single_step_model.fit(train_data_single,
                                epochs=100, 
                                callbacks=[lr_schedule], 
                                steps_per_epoch=EVALUATION_INTERVAL)

当然,我输入的值为 EVALUATION_INTERVAL之前,从而成功。 希望对大家有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.