'_VariantDataset' element access

Hi,

Getting the following error

TypeError: ‘_VariantDataset’ object is not subscriptable

when trying to access the first element like img[‘image’] from the dataset. How can I access first element of the dataset?

Thanks

Have you tried with:

https://www.tensorflow.org/api_docs/python/tf/data/experimental/get_single_element

Or you can use an iterator:
https://www.tensorflow.org/api_docs/python/tf/data/Iterator

1 Like

Usually:

for x in dataset:
  ....

for x in dataset.take(1)
  ....

Or

x = next(iter(dataset))

Or is this one of those cases where you have a dataset of datasets?

1 Like

Yes. It is the case of dataset of datasets

Then you need to either use a double loop:

for sub in dataset:
  for x in sub:
     ...

Or use tf.data.Dataset.flat_map to flatten the nested datasets.

2 Likes

Thanks. I will try that.

Have a case of nested datasets. I will try the flat_map solution as suggested by Mark. Thanks

thank’s mark, this was usefull to take a loot and learn how window works.

1 Like