I am using the following code to read *.jpg files from the “labeled_data_dir”
Labels are age of person.
training_dataset= tf.keras.utils.image_dataset_from_directory(
labeled_data_dir,
image_size=image_size, # Resize images (adjust as needed)
batch_size=batch_size # Batch size for training (adjust as needed)
seed=9,
validation_split=0.2,
subset=”training”
labels=”inferred”,
label_mode=”int”
)
The files in directory are structured under each sub-directory, where sub-directory is name of labels.
Function also prints it as
“Found 10137 files belonging to 80 classes”
But when I try to see the images in loaded dataset, every image is the first subdirectory name, which is not the case.
If I remove that subdirectory then the label changes to next subdirectory name.
Code I am using to display Images and labels is:
for images, labels in training_dataset.take(1): # Take only one batch
for i in range(9): # Display the first 9 images from the batch
ax = plt.subplot(3, 3, i + 1) # Create subplots in a 3×3 grid
plt.imshow(images[i].numpy().astype(“uint8”)) # Show the image
plt.title(class_names[labels[i].numpy().argmax()]) #Show the class name
plt.axis(“off”) #Disable the axes
plt.show()
What am I doing wrong?