Split train data to train and validation by using tensorflow_datasets.load (TF 2.1)

三世轮回 提交于 2020-02-03 10:26:03

问题


I'm trying to run the following Colab project, but when I want to split the training data into validation and train parts I get this error:

KeyError: "Invalid split train[:70%]. Available splits are: ['train']"

I use the following code:

(training_set, validation_set), dataset_info = tfds.load(
'tf_flowers',
split=['train[:70%]', 'train[70%:]'],
with_info=True,
as_supervised=True,
)

How I can fix this error?


回答1:


According to the Tensorflow Dataset docs the percentage splitting is possible as e. g. first_10_percent = tfds.Split.TRAIN.subsplit(tfds.percent[:10])

Your code would work when changing the split list as in the example:

(training_set, validation_set), dataset_info = tfds.load(
'tf_flowers',
split=[
       tfds.Split.TRAIN.subsplit(tfds.percent[:70]),
       tfds.Split.TRAIN.subsplit(tfds.percent[70:])
],
with_info=True,
as_supervised=True,
)

With the above code the training_set has 2590 entries, while validation_set has 1080.



来源:https://stackoverflow.com/questions/59905761/split-train-data-to-train-and-validation-by-using-tensorflow-datasets-load-tf-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!