3

Iam using runtime data augmentation using generators in keras for segmentation problem..

Here is my data generator

    data_gen_args = dict(
                     width_shift_range=0.1,
                     height_shift_range=0.1,
                     zoom_range=0.2,
                     horizontal_flip=True,
                     validation_split=0.2
                    )

image_datagen = ImageDataGenerator(**data_gen_args)

def generate_data_generator(generator, Xi, Yi):
    genXi = generator.flow(Xi, seed=7, batch_size=32)
    genYi = generator.flow(Yi, seed=7,batch_size=32)


    while True:
            Xi = genXi.next()
            Yi = genYi.next()
            print(Yi.dtype)
            print(np.unique(Yi))
            yield (Xi, Yi)

train_generator = generate_data_generator(image_datagen,
                                    x_train,
                                    y_train)

My labels are in a numpy array with data type float 32 and value 0.0 and 1.0.

#Output of np.unique(y_train)
array([0., 1.], dtype=float32

However, the data generator seems to modifies pixel values as shown below:-

#Output of print(np.unique(Yi))
[0.00000000e+00 1.01742386e-04 1.74021334e-04 ... 9.99918878e-01
 9.99988437e-01 1.00000000e+00]

It is supposed to have same values(0.0 and 1.0) after data geneartion.. Also, the the official documentation shows an example using same augmentation arguments for generating mask and images together.

However when i remove shift and zoom iam getting (0.0 and 1.0) as output. Keras verion 2.2.4,Python 3.6.8

UPDATE:-

I saved those images as numpy array and plotted it using matplotlib.It looks like the edges are smoothly interpolated (0.0-1.0) somehow upon including shifts and zoom augmentation. I can round these values in my custom generator as a hack; but i still don't understand the root cause (in case of normal images this is quite unnoticeable and has no adverse effects; but in masks we don't want to change label values )!!!

Still wondering.. is this a bug (nobody has mentioned it so far)or problem with my custom code ??

anilsathyan7
  • 1,423
  • 17
  • 25

0 Answers0