title: Tensorflow 2 ImageDataGenerator preprocessing_function for semantic segmentation masks
body: <p>I'm trying to use ImageDataGenerator flow_from_directory to load images and masks for semantic segmentation. Images and masks are png files. Masks 3 classes represented by 3 colors: [255,0,0], [0,0,255] and [255,255,255]. 
  An example of a mask:</p>
  
  <p><a href="https://i.stack.imgur.com/AbBSF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AbBSF.png" alt="enter image description here"></a></p>
  
  <p>I want to load a mask from directory and apply one hot encoding on fly:</p>
  
  <pre><code>def one_hot_preprocessing(img):
    # the RGB values printed here have float values 
    #print(img)
    print("shape: ", img.shape)
    print("type: ", type(img))
    return one_hot(img, num_classes)
  
  seed = 1
  data_gen_args = dict(
      rotation_range=180,
      width_shift_range=0.1,
      height_shift_range=0.1,
      zoom_range=0.2)
  
  image_datagen = ImageDataGenerator(**data_gen_args, rescale=1./255)
  mask_datagen = ImageDataGenerator(**data_gen_args, preprocessing_function=one_hot_preprocessing)
  
  image_generator = image_datagen.flow_from_directory(
      'train/input',
      class_mode=None,
      target_size=(IMG_WIDTH, IMG_HEIGHT),
      seed=seed)
  mask_generator = mask_datagen.flow_from_directory(
      'train/output',
      class_mode=None,
      target_size=(IMG_WIDTH, IMG_HEIGHT),
      seed=seed)
  
  # combine generators into one which yields image and masks
  train_generator = zip(image_generator, mask_generator)
  </code></pre>
  
  <p>When I check the img values in <code>one_hot_preprocessing</code> function, I see such values as <code>0.0000000e+00</code>, <code>2.5500000e+02</code> or even <code>5.3197867e-04</code>. I don't understand why the RGB values are read such way. My only assumption is that mask generator already applied some augmentation transformations and changed the colors. But how in this case can I get one hot encoded set? </p>
  
  <p>Maybe you can advice some more sophisticated solution how to load a data set for semantic segmentation?</p>
  
  <p>Thanks in advance!</p>