Home > Back-end >  ValueError: not enough values to unpack (expected 2, got 1) when trying to access dataset
ValueError: not enough values to unpack (expected 2, got 1) when trying to access dataset

Time:10-10

test_ds is a dataset of shape

<PrefetchDataset shapes: ((None, 256, 256, 3), (None,)), types: (tf.float32, tf.int32)>.

When i try to fetch data using for loop it worked.

for image_batch,label_batch in test_ds.take(1):

but when i try to fetch using following line of code it is throwing error

image_batch,label_batch=test_ds.take(1)
ValueError: not enough values to unpack (expected 2, got 1)

Could someone let me know the issue here.

CodePudding user response:

A tf.data.Dataset is an iterator. You need to iterate over it in order to access its elements. Try:

image_batch, label_batch = next(iter(test_ds.take(1)))
  • Related