我正在尝试运行以下Colab项目,但是当我想将训练数据分为验证和训练部分时,出现此错误:
KeyError: "Invalid split train[:70%]. Available splits are: ['train']"
我使用以下代码:
(training_set, validation_set), dataset_info = tfds.load( 'tf_flowers', split=['train[:70%]', 'train[70%:]'], with_info=True, as_supervised=True, )
如何解决此错误?
根据Tensorflow Dataset docs,百分比拆分是可能的,例如first_10_percent = tfds.Split.TRAIN.subsplit(tfds.percent[:10])
first_10_percent = tfds.Split.TRAIN.subsplit(tfds.percent[:10])
split如示例所示,更改列表时,您的代码将起作用:
split
(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, )
使用上面的代码,training_set有2590个条目,而validation_set有1080个。
training_set
validation_set