0

We can generate image dataset using ImageDataGenerator with tf.data.Dataset.from_generator()method.

img_gen = tf.keras.preprocessing.image.ImageDataGenerator()
gen = img_gen.flow_from_directory(path)
train_set = tf.data.Dataset.from_generator(gen, ...)
train_set.shuffle(2)

Now, I would like to know number of images in train_set, I do this :

train_set.samples

Error was:

AttributeError: 'ShuffleDataset' object has no attribute 'samples'
Eliza
  • 584
  • 4
  • 14
  • Since it is a generator, you can not get the length of it's items. Because it does not contain any values. Unless you call it repeatedly to and count it yourself. – Kaveh Jun 29 '21 at 09:22
  • Here there is a solution: https://stackoverflow.com/a/7460986/2423278 – Kaveh Jun 29 '21 at 09:25

0 Answers0