首页 > 解决方案 > SMOTE 技术不会过采样图像数据集

问题描述

我是 imblearn 库的新手。我的图像数据集属于 5 个类别,数据集高度不平衡。类数高度不平衡 我使用 tensorflow flow.from 目录函数加载图像并使用 smote 函数进行重采样。

img_height, img_width = 224,224
# the no. imgaes to load at each iteration
batch_size = 32
# only rescaling
train_datagen =  ImageDataGenerator(
    rescale=1./255,
    zoom_range=0.2,
    horizontal_flip=True,
    vertical_flip=True
)
test_datagen =  ImageDataGenerator(
    rescale=1./255,
    vertical_flip=True, 
    zoom_range=0.2,
    horizontal_flip=True
)
# these are generators for train/test data that will read pictures #found in the defined subfolders of 'data/'
print('Total number of images for "training":')
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size = (img_height, img_width),
batch_size = batch_size, 
class_mode = "categorical",shuffle = True
    #,color_mode='grayscale'
)    
smote = SMOTE()
    X_sm, y_sm = smote.fit_resample(train_generator, category_names)

单元开始运行,30 到 40 分钟后,jupyter 内核死了,我没有得到任何结果。请帮忙解决这个问题,我有 16 GB GPU,但 smote 没有在图像数据集上运行

标签: pythonimageimblearnsmote

解决方案


  1. 您可以对不平衡类别执行数据扩充

  2. 将它们调整为 (28,28) 或 (32,32) 并使用flatten转换为 784 或 1024 特征现在您可以使用 SMOTE

希望它会工作


推荐阅读