Keras: A preprocessing_function with parameters for ImageDataGenerator

Created on 9 Oct 2018  路  2Comments  路  Source: keras-team/keras

Hi, I'm training a semantic segmentation keras model on the COCO data-set. I want to create a custom preprocessing function that resets irrelevant objects to zero in the mask image, e.g. I want to train segmentation training and I only care of correctly segmenting 'cars', so I want to set to zero all other labels:

The preprocessing function:

def preprocess_mask(x, label):
    x = x.astype('int16')
    x[x!=label] = 0
    return x

The desired generator:

datagen = ImageDataGenerator(
        preprocessing_function = preprocess_mask(label=4),
        rescale=1./255,
        horizontal_flip=True)

But it doesn't work

support

Most helpful comment

You need to implement a Functor in this case.

class MyFunctor():
    def __init__(self, label):
        self.label = label
    def __call__(self, x):
        ...

All 2 comments

You need to implement a Functor in this case.

class MyFunctor():
    def __init__(self, label):
        self.label = label
    def __call__(self, x):
        ...

Do you then pass an instance or the schema?

Edit:
Bad question, an instance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KeironO picture KeironO  路  3Comments

rantsandruse picture rantsandruse  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

fredtcaroli picture fredtcaroli  路  3Comments

zygmuntz picture zygmuntz  路  3Comments