title: How to modify flow_from_directory or preprocessing_function in ImageDataGenerator?
body: <p>According to the keras docs:</p>
  
  <p>preprocessing_function: function that will be implied on each input. The function will run after the image is resized and augmented. The function should take one argument: one image (Numpy tensor with rank 3), and should output a Numpy tensor with the same shape.</p>
  
  <p>My numpy tensor is of rank 5 because my input images have 3 dimensions (height, width, depth).</p>
  
  <pre><code>from keras.preprocessing.image import ImageDataGenerator
  label_datagen = ImageDataGenerator()
  
  train_label_generator = label_datagen.flow_from_directory(
      directory="some_directory",
      target_size=(32, 32, 32),
      color_mode='grayscale',
      class_mode=None,
      batch_size=4)
  </code></pre>
  
  <p>When I check the first batch, I get my 5D numpy tensor:</p>
  
  <pre><code>first_item = train_image_generator.__getitem__(0)
  
  &gt;&gt;&gt;print('first_item.shape')
  (4, 32, 32, 32, 1)
  </code></pre>
  
  <p>Now I first want to do a simple operation on every input image, I also check the input shape by printing it:</p>
  
  <pre><code>def some_function(arr):
      print(arr.shape)
      arr += 1
      return arr
  </code></pre>
  
  <p>Here I add this function to my ImageDataGenerator:</p>
  
  <pre><code>label_datagen = FixedImageDataGenerator(preprocessing_function=some_function)
  </code></pre>
  
  <p>This is what I get as input shape</p>
  
  <pre><code>(32, 32, 1)
  </code></pre>
  
  <p>which means that it really is limited to rank 3. Any idea how I can modify this so that the input shape is <code>(32, 32, 32)</code>?</p>
  
  <p>My goal is to use the <code>to_categorical</code> function on every input in the ImageDataGenerator. I cannot simply say <code>class_mode="categorical"</code> as I am doing semantic segmentation (not image classification). I know that I could write some custom code for generators for that purpose but I want to know if it would be difficult to modify the keras ImageDataGenerator.</p>