首页 > 解决方案 > 将两个训练数据集应用于 model.fit 或将两个图像生成器函数的结果组合到我们的 CNN 模型中

问题描述

有谁知道我们如何将两个训练数据集应用到我们的 CNN 模型的 Model.fit 部分?

我可以用另一种方式问我的问题,我正在使用 Kers 中的 Imagedata 生成器函数对我的图像应用一些增强策略,以增加我的训练数据的数量。我想知道是否有一种直接的方法可以组合两个图像生成器函数的结果而不保存到目录中,然后在我们的模型中使用它们?

'''train_batches1 = ImageDataGenerator(rescale=1./255).flow_from_directory(directory="/content/gdrive/Shareddrives/Yihai, Brandon and Mostafa (1)/Images/Cross validation/Fold1/Train",target_size=(64 ,64),classes=['正常','OR21_6','OR7_6','OR14_6','OR7_12','OR7_3','OR21_3','OR21_12'],batch_size=10)

train_batches2 = ImageDataGenerator(rescale=1./255,horizo​​ntal_flip=True).flow_from_directory(directory="/content/gdrive/Shareddrives/Yihai, Brandon and Mostafa (1)/Images/Cross validation/Fold1/Train",target_size=( 64,64),classes=['Normal','OR21_6','OR7_6','OR14_6','OR7_12','OR7_3','OR21_3','OR21_12'],batch_size=10)'''

最好的问候,穆斯塔法。

标签: image-processing

解决方案


您想要重新缩放所有图像(重复数据集两次)并翻转其中的一半 对您的数据仅使用一个增强过程。你可以使用imgaug图书馆。就像图像在其中流动的 Keras 序列模型一样。

import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa


# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.

seq = iaa.Sequential(
    [
        # apply the following augmenters to most images

        iaa.Fliplr(0.5), # horizontally flip 50% of all images
      
        
]

您可以在此顺序中添加所需的任何类型的增强。并将您的增强函数设置为等于seq并重复您的数据集。


推荐阅读