Nikhil
Nikhil

Reputation: 18

Keras ImageDataGenerator different images

I'm having trouble with Keras's ImageDataGenerator for image augmentation. Right now, I'm trying to vertically flip the images in my training dataset. X_batch is my flipped image dataset and X_train is my original training dataset.

Can someone explain why the images in X_batch are in a different order than the images in X_train? X_batch[0] should be a flipped version of X_train[0], but instead X_batch[0] is a flipped version of a different image in my dataset.

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)    

datagen = ImageDataGenerator(vertical_flip=True)
datagen.fit(X_train)

for X_batch, y_batch in datagen.flow(X_train, y_train):
    X_batch = X_batch.astype('uint8')

    plt.subplot(2, 1, 1)
    plt.imshow(X_batch[0]) // flipped image

    plt.subplot(2, 1, 2)
    plt.imshow(X_train[0]) // original image

    plt.show()
    break

Upvotes: 0

Views: 136

Answers (1)

today
today

Reputation: 33410

According to Keras documentation the flow method takes an argument called shuffle which if set to True (which is by default) shuffles the data and then apply the image transformations. You can set it to False if you don't like this behavior:

for X_batch, y_batch in datagen.flow(X_train, y_train, shuffle=False):
    ...

Upvotes: 1

Related Questions