Python Keras中的预处理函数不';行不通
在我的2D语义分割任务中,标签中的所有像素值不是0,1,2,而是0127255。 所以我想简单地向标签数据集的ImageDataGenerator添加一个预处理函数 我的代码:Python Keras中的预处理函数不';行不通,python,keras,image-preprocessing,Python,Keras,Image Preprocessing,在我的2D语义分割任务中,标签中的所有像素值不是0,1,2,而是0127255。 所以我想简单地向标签数据集的ImageDataGenerator添加一个预处理函数 我的代码: SEED = 111 batch_size = 2 image_datagen = ImageDataGenerator( horizontal_flip=True, zca_epsilon=9, # fill_mode='nearest', ) image_generator = image_d
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
但是我的
预处理函数(图像)
对我的标签数据没有影响
我是否以正确的方式使用预处理函数?如何修复此问题?我找到了解决方案:
如果将预处理函数传递给label data的ImageDataGenerator(),则需要使用:
label_batch = label_datagen.standardize(label_batch)
在每个标签批次上激活预处理功能