text_plain_output_1.png
from imblearn.under_sampling import RandomUnderSampler

from tensorflow.keras.preprocessing.image import ImageDataGenerator

import numpy as np

seed = 42
np.random.seed = seed

x_train = np.asarray(x_train, np.float32) / 255
x_test = np.asarray(x_test, np.float32) / 255
y_train = np.asarray(y_train)
y_test = np.asarray(y_test)

shape = 50 * 50 * 3
x_train = x_train.reshape(x_train.shape[0], shape)
x_test = x_test.reshape(x_test.shape[0], shape)

from imblearn.under_sampling import RandomUnderSampler
underampler = RandomUnderSampler(sampling_strategy='auto')
x_train_fit, y_train_fit = underampler.fit_resample(x_train, y_train)
X_test_fit, Y_test_fit = underampler.fit_resample(x_test, y_test)
x_train_ = x_train_fit.reshape(x_train_fit.shape[0], 50, 50, 3)
x_test_ = X_test_fit.reshape(X_test_fit.shape[0], 50, 50, 3)

batch_size = 32
image_gen = ImageDataGenerator(shear_range=0.2, zoom_range=0.3, height_shift_range=0.2, width_shift_range=0.2, fill_mode='nearest', horizontal_flip=True, rotation_range=20)
test_data_gen = ImageDataGenerator(shear_range=0.2, zoom_range=0.3, height_shift_range=0.2, width_shift_range=0.2, fill_mode='nearest', horizontal_flip=True, rotation_range=20)
train = image_gen.flow(x_train_, y_train_fit, shuffle=True, batch_size=batch_size)
test = test_data_gen.flow(x_test_, Y_test_fit, shuffle=True, batch_size=batch_size)

for t_img, t_label in test:
    print('image shape ', t_img.shape)
    print('label  shape ', t_label.shape)
    break