How to fetch elements between x and y from tf.data.TFRecordDataset in Tensorflow

Issue

The test_dataset is defined as:

test_dataset = tf.data.TFRecordDataset([test_tfrecords])
test_dataset = test_dataset.map(map_f)
test_dataset = test_dataset.repeat(1)
test_dataset = test_dataset.batch(1)

For fetching the first 100 elements:

for test in test_dataset.take(100):
    pass

But how to fetch elements in index range between 50 and 150?

for test in test_dataset.take([50-150]):
    pass

Solution

Try tf.data.Dataset.skip:

for test in test_dataset.skip(50).take(100):
    pass

Answered By – AloneTogether

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published