Skip to content
Advertisement

extracting images and their label one by one from ImageDataGenerator().flow_from_directory

so I imported my dataset(38 classes) for validation using ImageDataGenerator().flow_from_directory

JavaScript

and i wanted to pick each image and its label one by one. For example i want to pick the first image and it’s label

i tried this

JavaScript

i get the image but for the label i just get an array of shape (32,38) with 0 and 1s

JavaScript

Is there a way to get the label of this picture?

Advertisement

Answer

The documentation might help you with this question. More specifically, the default arguments from tf.keras.ImageDataGenerator.flow_from_directory:

JavaScript

The class mode is categorical, so your labels will come as one-hot encoded matrices. The default batch size is 32, so when you iterate, 32 one-hot encoded rows will be fetched every time. This is what you’re getting.

To access the labels, you can index the list of all labels of your dataset:

JavaScript
Advertisement