I'm having trouble with Keras imagedatagenerator
class. I want to pass it an image with 6 channels to train background subtraction - I have the image stacked depthwise with its background, which is calculated using SubSense algorithm. This gives an image of shape (X,X,6)
instead of two images with (X,X,3)
But opencv
doesn't really let you save this so I had to save it as a numpy
file. Now I want to get that numpy
file into Keras as an image for training a CNN that will eventually return just the foreground masks but obviously trying to run it through ImageDataGenerator returns 0 images because it has too many channels.
My code is:
all_files = os.listdir("null/train")
arr=[]
for i in all_files:
file_path= "null/train/" + i
X = np.load(file_path)
arr.append (X)
datagen = ImageDataGenerator(
featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True)
datagen.fit(arr)
The resulting Error was:
null/anaconda3\envs\tensorflow\lib\site-packages\keras_preprocessing\image\image_data_generator.py:940: UserWarning: Expected input to be images (as Numpy array) following the data format convention "channels_last" (channels on axis 3), i.e. expected either 1, 3 or 4 channels on axis 3. However, it was passed an array with shape (451, 321, 321, 6) (6 channels). ' channels).')
Is there a way to force it to take numpy
files with 6 channels?