将Tensorflow数据集API创建的数据集拆分为训练和测试?
问题描述:
有人知道如何在Tensorflow中将数据集API(tf.data.Dataset)创建的数据集拆分为Test and Train吗?
Does anyone know how to split a dataset created by the dataset API (tf.data.Dataset) in Tensorflow into Test and Train?
答
假定您具有 all_dataset
变量为 tf.data.Dataset
类型:
Assuming you have all_dataset
variable of tf.data.Dataset
type:
test_dataset = all_dataset.take(1000)
train_dataset = all_dataset.skip(1000)
测试数据集现在具有前1000个元素,其余用于训练。
Test dataset now has first 1000 elements and the rest goes for training.