image-processing - 将两个训练数据集应用于 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,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)'''
最好的问候,穆斯塔法。
解决方案
您想要重新缩放所有图像(重复数据集两次)并翻转其中的一半 对您的数据仅使用一个增强过程。你可以使用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
并重复您的数据集。
推荐阅读
- python - 在 Tkinter python 中自动检查复选框的功能
- javascript - 使用 JavaScript 在 Bootstrap 4 无序列表中获取活动列表项
- node.js - 为什么 testDouble 不能模拟 3rd 方函数?
- .htaccess - 使用 .htaccess 将用户从我们的 amp 页面重定向
- javascript - 数据未填充在 MongoDB 中
- cassandra - 配置 cassandra-rackdc 和 cassandra-topology
- go - 如何在验收测试中测试 terraform 导入?
- python - 分布总和中的石榴参数
- javascript - 如何检查柏树中的随机数?
- r - 如果彼此在一定距离内,则根据最近的日期合并两个数据框