How can I load many image files with Tensorflow

I am currently in the Happy Whale competition. In it, there are 50,000 images of various whales and from which species they belong. I was trying to load these images with the tf dataset is there any efficient way to do load these many images with their labels?

Hi @Pritish_Mishra, You can load those images as tf dataset using tf.data.Dataset.list_files( file_pattern).

If the images are organized properly into directories and sub-directories like all the images to a specific label are stored in one sub-directory (name of sub directory must be the label name)

main_directory/
...class_a/
......a_image_1.jpg
......a_image_2.jpg
...class_b/
......b_image_1.jpg
......b_image_2.jpg

then you can load the images using tf.keras.utils.image_dataset_from_directory( ). Thank You.

1 Like