mchd
mchd

Reputation: 3163

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

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?

Upvotes: 1

Views: 415

Answers (1)

NHT_99
NHT_99

Reputation: 89

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.

Upvotes: 2

Related Questions