title: Keras: losing axis with brightness_range during image augmentation
body: <p>I'm training a U-net based segmentation network and using keras' <code>ImageDataGenerator</code> for inline augmentation of my grayscale images. Everything works as expected unless I include <code>brightness_range</code> in my arguments. When this happens my 512,512,1 image seems to turn into a 512,512 image and messes things up. How do I fix this?</p>
  
  <p>Here's my augmentation code:</p>
  
  <pre><code>data_gen_args = dict(
      rotation_range=15,
      shear_range=45,
      width_shift_range=0.1,
      height_shift_range=0.1,
      zoom_range=[0.5,1.5],
      #horizontal_flip=True,
      #vertical_flip=True,
      brightness_range=[0.5,1.5],
      fill_mode='nearest'
  )
  
  image_datagen_train = ImageDataGenerator(**data_gen_args)
  
  
  train_image_generator = image_datagen_train.flow_from_directory(
  train_ct,
  target_size = (512, 512),
  color_mode = ("grayscale"),
  classes=None,
  class_mode=None,
  seed = seed,
  batch_size = BS)
  
  train_mask_generator = mask_datagen_train.flow_from_directory(
  train_mask,
  target_size = (512, 512),
  color_mode = ("grayscale"),
  classes=None,
  class_mode=None,
  seed = seed,
  batch_size = BS)
  </code></pre>
  
  <p>And here's my error message:</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-33-8d701f27a3fa&gt; in &lt;module&gt;
        7                     verbose=1,
        8                     callbacks=cb_check,
  ----&gt; 9                     use_multiprocessing = False
       10                              )
  
  /usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
       89                 warnings.warn('Update your `' + object_name + '` call to the ' +
       90                               'Keras 2 API: ' + signature, stacklevel=2)
  ---&gt; 91             return func(*args, **kwargs)
       92         wrapper._original_function = func
       93         return wrapper
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
     1730             use_multiprocessing=use_multiprocessing,
     1731             shuffle=shuffle,
  -&gt; 1732             initial_epoch=initial_epoch)
     1733 
     1734     @interfaces.legacy_generator_methods_support
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
      183             batch_index = 0
      184             while steps_done &lt; steps_per_epoch:
  --&gt; 185                 generator_output = next(output_generator)
      186 
      187                 if not hasattr(generator_output, '__len__'):
  
  /usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py in get(self)
      740                     "`use_multiprocessing=False, workers &gt; 1`."
      741                     "For more information see issue #1638.")
  --&gt; 742             six.reraise(*sys.exc_info())
  
  /usr/local/lib/python3.6/dist-packages/six.py in reraise(tp, value, tb)
      691             if value.__traceback__ is not tb:
      692                 raise value.with_traceback(tb)
  --&gt; 693             raise value
      694         finally:
      695             value = None
  
  /usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py in get(self)
      709                 try:
      710                     future = self.queue.get(block=True)
  --&gt; 711                     inputs = future.get(timeout=30)
      712                     self.queue.task_done()
      713                 except mp.TimeoutError:
  
  /usr/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
      642             return self._value
      643         else:
  --&gt; 644             raise self._value
      645 
      646     def _set(self, i, obj):
  
  /usr/lib/python3.6/multiprocessing/pool.py in worker(inqueue, outqueue, initializer, initargs, maxtasks, wrap_exception)
      117         job, i, func, args, kwds = task
      118         try:
  --&gt; 119             result = (True, func(*args, **kwds))
      120         except Exception as e:
      121             if wrap_exception and func is not _helper_reraises_exception:
  
  /usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py in next_sample(uid)
      648         The next value of generator `uid`.
      649     """
  --&gt; 650     return six.next(_SHARED_SEQUENCES[uid])
      651 
      652 
  
  /usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/iterator.py in __next__(self, *args, **kwargs)
      102 
      103     def __next__(self, *args, **kwargs):
  --&gt; 104         return self.next(*args, **kwargs)
      105 
      106     def next(self):
  
  /usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/iterator.py in next(self)
      114         # The transformation of images is not under thread lock
      115         # so it can be done in parallel
  --&gt; 116         return self._get_batches_of_transformed_samples(index_array)
      117 
      118     def _get_batches_of_transformed_samples(self, index_array):
  
  /usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/iterator.py in _get_batches_of_transformed_samples(self, index_array)
      244                 x = self.image_data_generator.apply_transform(x, params)
      245                 x = self.image_data_generator.standardize(x)
  --&gt; 246             batch_x[i] = x
      247         # optionally save augmented images to disk for debugging purposes
      248         if self.save_to_dir:
  
  ValueError: could not broadcast input array from shape (512,512) into shape (512,512,1)
  </code></pre>