How can I select data from a Tensorflow Dataset data collection? Is there any way to select features or labels from a tensorflow Dataset without using numpy conversion methods or iterate through?

The simplest example I found is:

import tensorflow_datasets as tfds

ds = tfds.load('mnist', split='train', shuffle_files=True)
print(ds)
&gt;&gt; &lt;_OptionsDataset shapes: {image: (28, 28, 1), label: ()}, types: {image: tf.uint8, label: tf.int64}&gt;


In this case, _OptionsDataset holds data in a dict, but the collection can be a tuple, list or even a np.ndarray.



If there is not a way to select data directly from a tensorflow Dataset, what's the most commonly used alternative?
You can use the ds.map() function to create dataset conatains only images or labels:

ds_images = ds.map(lambda d:d['images')


the original purpose of the map function is manipulating the data without converting to numpy, for example:

ds_images = ds.map(lambda d:d['images']/255)


hope I helped you.