In my 2D semantic segmentation task, all pixel values in labels aren't are not 0,1,2, but 0,127,255 for example. So I want to simply add a preprocess function to my ImageDataGenerator of label dataset,
My code:
SEED = 111
batch_size = 2
image_datagen = ImageDataGenerator(
horizontal_flip=True,
zca_epsilon=9,
# fill_mode='nearest',
)
image_generator = image_datagen.flow_from_directory(
directory="/xxx/images",
class_mode=None,
batch_size=batch_size,
seed=SEED,
)
def preprocessing_function(image):
# if I have 3 categories, I need to convert 0,10,20 to 0,1,2 for example
return image
label_datagen = ImageDataGenerator(
horizontal_flip=True,
zca_epsilon=9,
rescale=1,
preprocessing_function=preprocessing_function,
# fill_mode='nearest',
)
label_generator = image_datagen.flow_from_directory(
directory="/xxx/labels",
class_mode=None,
batch_size=batch_size,
seed=SEED,
)
train_generator = zip(image_generator, label_generator)
print(len(image_generator))
i = 0
for image_batch, label_batch in iter(train_generator):
print(image_batch.shape, label_batch.shape) # (2, 256, 256, 3) (2, 256, 256, 3)
print(image_batch.dtype, label_batch.dtype) # float32 float32
i += 1
if i == 5:
break
But it seems that my
preprocessing_function(image)
has no effect on my label data.
Am I using the preprocess function in the right way? How can I repair this?