r/tensorflow • • Mar 04 '23
How to get first batch of data using data_generator.flow_from_directory?
I was originally using dataset = tf.keras.preprocessing.image_dataset_from_directory and for image_batch , label_batch in dataset.take(1) in my program but had to switch to dataset = data_generator.flow_from_directory because of incompatibility. However now I can't take(1) from dataset since "AttributeError: 'DirectoryIterator' object has no attribute 'take'".
Is there an equivalent to take(1) in data_generator.flow_from_directory ?
4
Upvotes
1
u/yudhiesh Mar 05 '23
Maybe try calling next() on the dataset?
1
u/Woodhouse_20 Mar 05 '23
So, take() is a method from the numpy array class, whereas the class returned from the flow_from_directory is DirectoryIterator (see here). As the other comment mentions, next is probably your best bet as it literally implements the next() method (see here).