数据增强:ImageDataGenerator vs openCV

数据挖掘 深度学习 喀拉斯 张量流 计算机视觉 卷积神经网络
2022-02-23 18:23:26

我想增加我的数据集中的数据来创建一个 CNN 深度学习分类模型。

哪个更适合模型,使用数据增强ImageDataGenerator或使用 openCV 来增加数据?

顺便说一句,我正在使用 Keras 和 floydhub。

2个回答

库 imgaug、Keras、ImageDataGenerator 和 flow_from_dataframe 的示例:

import imgaug as ia
import imgaug.augmenters as iaa

seq = iaa.Sequential([
        iaa.Crop(px=(0, 16)), 
        # crop images from each side by 0 to 16px (randomly chosen)
        iaa.Fliplr(0.5), 
        # horizontally flip 50% of the images
        iaa.GaussianBlur(sigma=(0, 3.0)) 
        # blur images with a sigma of 0 to 3.0
    ])

def augment(img):
        seq_det = seq.to_deterministic()
        aug_image = seq_det.augment_image(img)

        return applications.inception_resnet_v2.preprocess_input(aug_image)

train_generator = image.ImageDataGenerator(preprocessing_function=augment)

train_flow = train_generator.flow_from_dataframe(
        dataframe=train_df,
        directory=train_data_dir,
        x_col="path",
        y_col=columns,
        batch_size=batch_size,
        class_mode="other",
        target_size=(img_height ,img_width),
        shuffle=True
    )


KerasImageDataGenerator本身并没有为数据增强提供太多支持。但是,它有一个名为的参数preprocessing_function,允许您使用自定义增强器。

我个人使用imgaug,它提供了几乎所有你能想到的增强功能,并且可以很好地使用,ImageDataGenerator就像我说的那样。