Effects of channel_shift_range in ImageDataGenerator (Keras image augmentation)

Viewed 5274

Maybe I'm misunderstanding. If I implement channel_shift_range in my ImageDataGenerator, the output should have "scrambled" color values, right? I would like to use it to make my model more robust to variance in color.

However, when I test it, I'm not seeing any effect. Am I using it wrong? Here's my code:

from keras.preprocessing.image import ImageDataGenerator

import cv2
import matplotlib.pyplot as plt
%matplotlib inline

path = '/mnt/Project/Imaging/samples'

datagen = ImageDataGenerator(channel_shift_range=0.9)

genObject = datagen.flow_from_directory(path,
                                        batch_size=1)

augs = []
i = 0

for batch in genObject:
    augs.append(batch)
    i += 1
    if i > 10:
        break

for item in augs:
    plt.imshow(item[0][0].astype('uint8'))
    plt.show()

Environment:
Jupyter Lab
Python 3.6.6
Keras==2.2.4
Keras-Applications==1.0.7
Keras-Preprocessing==1.0.9
tensorboard==1.9.0
tensorflow-gpu==1.9.0

Thanks in advance for the help!

1 Answers

The values of the image data are in the range [0..255], so a shift of 0.. 0.9 is hardly visible. Try a much large shift to see any effect.

Note that using rescale=1./255. does not help as the rescaling is applied after the transformation.

Related