Muhammad Ibtihaj Tahir
Muhammad Ibtihaj Tahir

Reputation: 636

Image Data Generator for images in Numpy array

So I have my images in a numpy array but not in a directory. I have a final numpy array which is a 4d tensor of shape (sample, 48, 48, 1). My goal is to use keras's image data generator to convert them to (sample, 224, 224, 1). Please guide me on how to do it as so far I have seen examples of people using image data generators from the directory where they load actuall images.

I have 4 numpy arrays stored localy train_images.npy, train_labels.npy, test_images.npy and test_labels.npy.

The shape for images in these numpy is (sample, 48, 48, 1) The shape for labels in these numpy is (sample, number of classes) as i have already converted them to keras.utils.np_utils.to_categorical method.

Upvotes: 5

Views: 6673

Answers (1)

Dr. Snoopy
Dr. Snoopy

Reputation: 56357

For this you should use ImageDataGenerator.flow, which takes numpy arrays directly. This replaces the flow_from_directory call, all other code using the generator should be the same.

Upvotes: 11

Related Questions