有人知道我们如何将两个训练数据集应用到模型中吗?我们CNN模型的拟合部分?
我可以用另一种方式问我的问题,我正在使用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,horizontal_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) " '
致以最诚挚的问候。Mostafa .
您希望重新缩放所有图像(重复数据集两次)并翻转其中的一半仅对数据使用一个增强过程。您可以使用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
,并重复您的数据集。