How to apply Matlab CNN code on an input image with 6 channels

I have currently applied the Matbal CNN function to train my research data. Unlike, the Matlab 'lettersTrainSet'with a size of 28x28x1x1500 (4-D array), the input train data of my experiment have a size of 7x7x6x30,000. The problem I have encountered is that while running the 'trainNetwork' function, Matlab shows me an error: *Error using trainNetwork>iAssertValidImageArray (line 575) X must be a 4-D array of images.
Error in trainNetwork>iParseInput (line 329) iAssertValidImageArray( X );
Error in trainNetwork (line 68) [layers, opts, X, Y] = iParseInput(varargin{:});*
However, the same training data with 3 channels or 1 channels I can run the CNN code without any error message. It will be a great help if anyone can suggest how to use image data with more than 3 channels in Matlab for CNN classification.

 Accepted Answer

Currently, CNN exclusively supports single and RGB channel imagery. Due to this limitation, the ability to use CNNs with image data with more than 3 channels is not available at this time.
I work at MathWorks, so I have forwarded this feedback to the relevant development team.

7 Comments

Hi Kristen, thank you very much for the information and to let the relevant Matlab team know about this limitation. As my entire research work is with satellite multichannel images, I have to switch to another program to get my images work. Thank you for your kind help.
Kind Regards
Hello Chandrama.
This is not a solution, but maybe a workaround... When dealing with multiple channels, as you do, one option would be to apply PCA to the whole image (with all channels) and then just take the first three components. That way you would be compressing the information of all 6 channels into 3. The whole information wouldn't be compressed on those three channels, but, as I said, that might be a workaround for now.
Att,
Manuel Blanco Valentín
I am not sure what you are doing with the images. However, when dealing with classification PLS is superior to PCA.
I'm pretty sure I have one or two posts dealing with PLS. I don't recall the exact MATLAB function. However, it should not be hard to find.
Hope this helps.
Greg
Thanks very much Greg and Mbvalentin for your important suggestions. But my project is related with Generating a CNN network model for flood detection, and as I am doing everything from scratch (generating the training data), therefore I need information from all the channels at this stage and I believe that PCA or any equivalent to it may cause dimensionality reduction and loss of information. That is why I am not able to proceed further with MATLAB.
The purposes of PCA and PLS are to reduce dimensionality subject to the constraints of minimizing the loss of regression information (PCA) or classification information(PLS).
It may definitely be worth doing before trying to preserve the dimensionality.
Hope this helps
Greg
I have currently applied the Matbal CNN function to train my research data. Unlike, the Matlab 'lettersTrainSet'with a size of 28x28x1x1500 (4-D array), the input train data of my experiment have a size of 7x7x2500. The problem I have encountered is that while running the 'trainNetwork' function, Matlab shows me an error: *Error using trainNetwork>iAssertValidImageArray (line 575) X must be a 4-D array of images.
Error in trainNetwork>iParseInput (line 329) iAssertValidImageArray( X );
Error in trainNetwork (line 68) [layers, opts, X, Y] = iParseInput(varargin{:});*
please help me in this regard
reshape your data to 7 by 7 by 1 by 2500

Sign in to comment.

More Answers (4)

If the development team is prioritizing by market need, this is a deal-breaker for a few of our applications too:
Using XYZRGB (6ch), or XYZ+Gray(4ch), or XYZ+normals+gray(7ch), or two stereo channels with multiple exposures/textures each (up to 24ch)...

1 Comment

Yes, I agree with you, Jim, that is why I have to shift from Matlab to Python in order to utilize the information from all the 6 channels of the image. In some cases specifically in the field of remote sensing, the number of channels would never be limited to 3 channel data and it may be higher than 6 channels too. Regards

Sign in to comment.

1 Comment

Hi Zhiyi,
Thanks very much for the link. I will try that with my 6 channel data and will update the outcome.

Sign in to comment.

This is the same for me. I wanted to implement a deconvolutional neural network and thus meed to have an input layer with more than 3 channels (to input the feature map and also to modify them as all needed layers for this are not yet implemented). Is there any workaround, or will this fixed in the next release? I will have to switch to Python otherwise. Is it in the plans of the development team? Cheers.
I want to apply CNN in 3D images (MRI data). I am planning to use 3D images as 2D x z stacks thus need to work in 2D CNN with multi channels. Please let me know what should i do.. Thank you.

9 Comments

Hello, I am trying to do a similar thing, did you find any solution?
No Aron, I couldn't find any solution. Hope this is solved in a new version matlab code.
Is it possible to seperate the channels inside the network, and process them by parallel convolutional layers? I'm trying to process a sequence of images, I've created a new question about this: https://www.mathworks.com/matlabcentral/answers/395474-how-can-i-create-a-neural-network-with-an-input-of-image-sequences?s_tid=prof_contriblnk
Sorry that is outside of my experience.
Dear Walter, thank you so much for your help. But i have one question regarding that, is this ok to use multiple 2D image in 2D CNN with multispectral channel??, because my 2D images are not images with different colors but images with grey scaled color at different z axis.
Sorry, I do not know. Probably, but I am not certain at all.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!