I need to augment multichannel images and would like to use ImageDataGenerator Unfortunately, it supports 1,3 and 4 channel images only and I need much more. Would it be OK to directly edit site-packages/Keras/preprocessing/image.py adding necessary number of channels?
if x.shape[self.channel_axis] not in {1, 3, 4, XXX}:
raise ValueError(
'Expected input to be images (as Numpy array) '
'following the dimension ordering convention "' + self.dim_ordering + '" '
'(channels on axis ' + str(self.channel_axis) + '), i.e. expected '
'either 1, 3 or 4 channels on axis ' + str(self.channel_axis) + '. '
'However, it was passed an array with shape ' + str(x.shape) +
' (' + str(x.shape[self.channel_axis]) + ' channels).')
where XXX - is a number of channels that I need. Would this break anything? Thanks!
Introduction to Keras ImageDataGenerator. Keras ImageDataGenerator is used for getting the input of the original data and further, it makes the transformation of this data on a random basis and gives the output resultant containing only the data that is newly transformed. It does not add the data.
In datagen. flow() , It takes data in the form of datasets like np. arrays directly where in case of datage. flow_from_directory it takes data from folders containing labelled images. But both return batches of augmented images in batches.
I tried that anyway and it seems to work without too many side effects. I didn't explore every possible problem, though. So if you have multichannel data (like satellite imagery, etc) you can try this hack. There are couple of places where you need to augment the augmentation code :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With