Issue
When I try to import and batch the dataset using the method with tf.data.Dataset.batch()
and use the dataset.as_numpy_iterator(), the iterated objects are dicts, even though I should get multiple numpy arrays.
dataset = tfds.load('mnist', split='train')
dataset.batch(batch_size, drop_remainder=False)
for i in dataset.as_numpy_iterator():
print(type(i)) # prints <class 'dict'>
Why does it happen?
Solution
Use as_supervised = True
import tensorflow_datasets as tfds
dataset = tfds.load('mnist', split='train', as_supervised=True)
dataset.batch(10, drop_remainder=False)
for image, label in tfds.as_numpy(dataset):
print(type(image), type(label), label)
According to TensorFlow documentation if as_supervised is False you will get dictionary values. Check Docs Here
Answered By - Aniket Bote
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.