简体   繁体   中英

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

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):
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM