Split a dataset created by Tensorflow dataset API in to Train and Test?

Dani picture Dani · Jan 11, 2018 · Viewed 31.4k times · Source

Does anyone know how to split a dataset created by the dataset API (tf.data.Dataset) in Tensorflow into Test and Train?

Answer

apatsekin picture apatsekin · May 5, 2018

Assuming you have all_dataset variable of tf.data.Dataset type:

test_dataset = all_dataset.take(1000) 
train_dataset = all_dataset.skip(1000)

Test dataset now has first 1000 elements and the rest goes for training.