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

时间:2021-03-12 01:31:39

标签: image-processing

有人知道如何将两个训练数据集应用到 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=['Normal','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)'' '

此致, 穆斯塔法。

1 个答案:

答案 0 :(得分:0)

您想要重新缩放所有图像(重复数据集两次)并翻转其中的一半 仅对您的数据使用一种增强过程。您可以使用 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 并重复您的数据集。

相关问题