Cast ImageDataGenerator数据输出

问题描述 投票:0回答:1

我正在编写一个用于图像分割的网络。我有我的ImageDataGenerator用于遮罩(它们是只有0和255作为值的黑白图像的RGB图像,黑白):

train_mask_data_gen = ImageDataGenerator(rotation_range=10,
                                         width_shift_range=10,
                                         height_shift_range=10,
                                         zoom_range=0.3,
                                         horizontal_flip=True,
                                         vertical_flip=True,
                                         fill_mode='nearest',#interpolation used for augmenting the image
                                         cval=0,
                                         rescale=1./255)

和flow_from_directory:

train_mask_gen = train_mask_data_gen.flow_from_directory(os.path.join(training_dir, 'masks'),
                                                     target_size=(img_h, img_w),
                                                     batch_size=bs,
                                                     class_mode=None, # Because we have no class subfolders in this case
                                                     shuffle=True,
                                                     interpolation='nearest',#interpolation used for resizing
                                                     #color_mode='grayscale',
                                                     seed=SEED)

代码运行良好,唯一的问题是,当我将数据增强应用到蒙版时,我将不再具有二进制图像,但是我得到的值介于0和1之间(归一化)。例如,如果我打印输出矩阵(图像),则会得到类似以下内容:

 [[0.         0.         0.        ]


[0.         0.         0.        ]
   [0.         0.         0.        ]
   ...
   [1.         1.         1.        ]
   [1.         1.         1.        ]
   [1.         1.         1.        ]]

  ...

  [[0.         0.         0.        ]
   [0.3457849  0.3457849  0.3457849 ]
   [1.         1.         1.        ]
   ...
   [0.         0.         0.        ]
   [0.         0.         0.        ]
   [0.         0.         0.        ]]

其中还包含那些由于扩充而产生的“额外”值。如果我不应用任何增强,我将获得所需的二进制图像。

我如何将演员表嵌入整数? (为了获得只有0或1的值)我试图在dtype=int中使用字段ImageDataGenerator,但是它什么也没做,我一直得到相同的结果。

我正在编写一个用于图像分割的网络。我有我的ImageDataGenerator用于遮罩(它们是仅包含0和255作为值的黑白图像的RGB图像),它是:train_mask_data_gen = ...

python keras casting image-segmentation data-augmentation
1个回答
0
投票

Keras文档确实建议设置Dtype是正确的做法,因此可能是一个错误...您可以做的一件事就是自己包装Keras生成器并正确地进行转换:

© www.soinside.com 2019 - 2024. All rights reserved.