例如,在我的 2D 语义分割任务中,标签中的所有像素值都不是 0,1,2,而是 0,127,255。所以我想简单地向我的标签数据集的 ImageDataGenerator 添加一个预处理函数,
我的代码:
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
但似乎我的
预处理函数(图像)
对我的标签数据没有影响。
我是否以正确的方式使用预处理功能?我该如何修复这个?