【发布时间】:2020-05-24 14:54:50
【问题描述】:
我在这里有点困惑...我刚刚花了一个小时阅读有关如何在 TensorFlow 中将我的数据集拆分为测试/训练的信息。我正在按照本教程导入我的图像:https://www.tensorflow.org/tutorials/load_data/images。显然,可以使用 sklearn:model_selection.train_test_split 拆分为训练/测试。
但我的问题是:我何时将数据集拆分为训练/测试。我已经用我的数据集完成了这个(见下文),现在怎么办?我该如何拆分它?在将文件加载为tf.data.Dataset 之前我必须这样做吗?
# determine names of classes
CLASS_NAMES = np.array([item.name for item in data_dir.glob('*') if item.name != "LICENSE.txt"])
print(CLASS_NAMES)
# count images
image_count = len(list(data_dir.glob('*/*.png')))
print(image_count)
# load the files as a tf.data.Dataset
list_ds = tf.data.Dataset.list_files(str(cwd + '/train/' + '*/*'))
另外,我的数据结构如下所示。没有 test 文件夹,没有 val 文件夹。我需要从那组火车中抽取 20% 的时间进行测试。
train
|__ class 1
|__ class 2
|__ class 3
【问题讨论】:
标签: python scikit-learn tensorflow2.0 train-test-split