我正在尝试同步转换图像和蒙版标签,但是随机增强被不同地应用于两个生成器(将两个图像都保存到目录时已得到证明)。
我尝试过
起作用的一件事是将批处理大小设置为1,但是随后我的训练表现受到了影响。
seed_val=0
data_gen_args = dict(
rescale=1./255,
horizontal_flip=True,
validation_split=validation_split)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)
image_generator = image_datagen.flow_from_directory(
'data/x/train_images/',
target_size=(224, 224),
color_mode='rgb',
class_mode=None,
batch_size=batch_size,
subset='training',
save_to_dir='tmp/img/',
seed=seed_val)
mask_generator = mask_datagen.flow_from_directory(
'data/x/train_annotations/',
target_size=(224, 224),
color_mode='grayscale',
class_mode=None,
batch_size=batch_size,
subset='training',
save_to_dir='tmp/mask/',
seed=seed_val)
train_generator = zip((image_generator), (mask_generator))
答案 0 :(得分:0)
尝试将shuffle
设置为False
来同时设置图像和遮罩
image_generator = image_datagen.flow_from_directory(
'data/x/train_images/',
target_size=(224, 224),
shuffle = False,
color_mode='rgb',
class_mode=None,
batch_size=batch_size,
subset='training',
save_to_dir='tmp/img/',
seed=seed_val)
mask_generator = mask_datagen.flow_from_directory(
'data/x/train_annotations/',
target_size=(224, 224),
shuffle = False,
color_mode='grayscale',
class_mode=None,
batch_size=batch_size,
subset='training',
save_to_dir='tmp/mask/',
seed=seed_val)