How to load a custom image dataset as numpy.ndarray?

Issue

Here, I am loading the MNIST dataset from keras and printing out the datatypes:

(train_images, _), (test_images, _) = tf.keras.datasets.mnist.load_data()
print(type(train_images))
print(type(test_images))

Instead of this, I want to load a custom dataset in a way to make it compatible with the rest of my code. How can I go about doing this?

Solution

You can use tf.keras.utils.image_dataset_from_directory() for loading your custom image dataset, split train/test set, resize image,… if your dataset contains n sub-directories, one per class (for classification). You should read this example.
Another way, you can set data flow with tf.keras.preprocessing.image.ImageDataGenerator() and flow_from_directory() to load your custom image dataset or use Djinn’s answer.

Answered By – NHT_99

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published