Python Keras:ImageDataGenerator的性能较差
我尝试使用KerasPython Keras:ImageDataGenerator的性能较差,python,image,keras,computer-vision,data-augmentation,Python,Image,Keras,Computer Vision,Data Augmentation,我尝试使用KerasImageDataGenerator来扩充图像数据。我的任务是一个回归任务,其中一个输入图像产生另一个转换图像。到目前为止,效果不错 在这里,我想使用ImageDataGenerator应用数据扩充。为了以相同的方式变换两幅图像,我使用了中描述的方法,其中描述了使用相应遮罩的图像变换。我的情况有点不同,因为我的图像已经加载,不需要从目录中获取。此过程已在中描述 为了验证我的实现,我首先使用了它,没有进行任何扩充,并且使用了ImageDataGenerator,没有指定任何参数
ImageDataGenerator
来扩充图像数据。我的任务是一个回归任务,其中一个输入图像产生另一个转换图像。到目前为止,效果不错
在这里,我想使用ImageDataGenerator
应用数据扩充。为了以相同的方式变换两幅图像,我使用了中描述的方法,其中描述了使用相应遮罩的图像变换。我的情况有点不同,因为我的图像已经加载,不需要从目录中获取。此过程已在中描述
为了验证我的实现,我首先使用了它,没有进行任何扩充,并且使用了ImageDataGenerator
,没有指定任何参数。根据中的类引用,这不应改变图像。请参阅此代码段:
img_val = img[0:split_seperator]
img_train = img[split_seperator:]
target_val = target[0:split_seperator]
target_train = target[split_seperator:]
data_gen_args = dict()
# define data preparation
src_datagen = ImageDataGenerator(**data_gen_args)
target_datagen = ImageDataGenerator(**data_gen_args)
# fit parameters from data
seed = 1
src_datagen.fit(img_train, augment=False, seed=seed)
target_datagen.fit(target_train, augment=False, seed=seed)
training_generator = zip(
src_datagen.flow(img_train, batch_size=batch_size_training, seed=seed),
target_datagen.flow(target_train, batch_size=batch_size_training, seed=seed))
_ = model.fit_generator(
generator=training_generator,
steps_per_epoch=image_train.shape[0] // batch_size_training,
epochs=num_epochs, verbose=1,
validation_data=(img_val, target_val), callbacks=callbacks)
不幸的是,我的实现似乎有一些问题。我没有得到预期的表演。验证损失在某种程度上稳定在某个值附近,只是略有下降(见下图)。在这里,我期望,因为我没有使用任何增强,与非增强基线相同的损失
相比之下,我在没有ImageDataGenerator
的情况下进行的培训
_ = model.fit(img, target,
batch_size=batch_size_training,
epochs=num_epochs, verbose=1,
validation_split=0.2, callbacks=cb)
我想我不知怎么搞混了ImageDataGenerator
、flow
和fit
函数的用法。因此,我的问题是:
- 应用的功能之一
或fit
是否冗余并导致此行为flow
- 我是否有实现问题
- 这种实现一般来说有意义吗
- 设置验证集修复程序有意义吗?还是应该对其进行扩展
- 同时为验证数据创建生成器
- 删除应用的拟合功能
- 在流函数中设置
(数据已被洗牌)shuffle=True
这两种方法都无助于改善结果。最后,我明白了您要做什么,这应该可以完成工作
aug = ImageDataGenerator(**data_gen_args)
# train the network
H = model.fit_generator(aug.flow(img_train, target_train, batch_size=image_train.shape[0]),
validation_data=(img_val, target_val), steps_per_epoch=image_train.shape[0] // BS,
epochs=EPOCHS)
让我知道这是否有效。您是否尝试过手动查看错误标记的内容以及错误标记后的结果,您是否看到了一种模式,还是所有模式都是随机的,只需查看一些错误标记的数据。我有一项回归任务,将一幅图像转换为另一幅图像。在这里很难看出它是否贴错了标签。我唯一能说的是,正确的目标图像与输入图像一起使用。结果看起来就像我预料的那样。你是在尝试使用神经式转移吗?不是。这是图像处理中的监督应用。@anand_v.singh当像素已经出现在数据帧中(如中)时,如何加载和增强图像?你能在那里回答吗?