Error using reshape

84 views
Skip to first unread message

snez...@gmail.com

unread,
Jun 18, 2018, 2:29:40 AM6/18/18
to mdCNN: Multidimensional CNN library in Matlab
Hi Hagay,,
Thanks for your code.
My input data is 2000 sample hyperspectral images  as matrix array 25*25*37 (25 is the size of images and 37 is the number of bands) and 1000 test data for tree type classification( output 3 class). I tried to run Mnist.m on my data but it took a long time (more than one day) and I didn't get result. Then I resized my images to 5*5*37 with this config setting :

 %%%%%%%%%%%%%%%%%%%%%  input settings  %%%%%%%%%%%%%%%%%%
 
  net.hyperParam.sizeFmInput = [5 5]; % size of input feature map
  net.hyperParam.numFmInput  = 925;        % number of feature map of the input
 
 %%%%%%%%%%%%%%%%%%%%%  Layers specification %%%%%%%%%%%%%%%%%%
 
  net.layers{end+1}.properties = struct('type',2,'numFm',12  ,'kernel',5,'pad',2);
  net.layers{end+1}.properties = struct('type',2,'numFm',24 ,'kernel',13);
  net.layers{end+1}.properties = struct('type',1,'numFm',128);
  net.layers{end+1}.properties = struct('type',1,'numFm',3);
 % net.layers{end+1}.properties = struct('type',0,'numFm',3); %softmax
 
 %%%%%%%%%%%%%%%%%%%%%  Hyper params - training %%%%%%%%%%%%%%%%%%
 
  net.hyperParam.trainLoopCount = 1000; %on how many images to train before evaluating the network
  net.hyperParam.testImageNum   = 2000;    % after each loop, on how many images to evaluate network performance
  net.hyperParam.ni_initial     = 0.05; % ni to start training process
  net.hyperParam.ni_final       = 0.025;         % final ni to stop the training process
  net.hyperParam.normalizeNetworkInput=0; % default is '1'
  
Now I is 2000*1 that each row in I cell array has 925 (5*5*37) values. 
  
Unfortunately, I've got these errors ;

Verifying backProp..Network is OK. Verification time=221.90
Error using reshape
To RESHAPE the number of elements must not
change.

Error in GetNetworkInputs (line 134)
    image = reshape(image , inputDim);

Error in Train (line 54)
 assert(ndims((zeros([net.hyperParam.sizeFmInput
 net.hyperParam.numFmInput])))==ndims(GetNetworkInputs(dataset.I{1},net,1)),
 'Error - input does not match network
 configuration (input size + num FM)');

Error in demoMnist (line 15)
net   =  Train(MNIST,net, 15000);

Could you please tell me what's the problem? and How much time is required to process this amount of data normally?
Thanks in advance!
Somayeh
 


Hagay Garty

unread,
Jun 18, 2018, 10:27:39 AM6/18/18
to mdCNN: Multidimensional CNN library in Matlab
You should set numFmInput as the number of bands, ie
net.hyperParam.numFmInput  = 37

I suggest starting without scaling first, keep your data as 25x25x37 and set
net.hyperParam.sizeFmInput = [5 5]; % size of input feature map
net.hyperParam.numFmInput  = 37;        % number of feature map of the input
 
Also to get quicker updates, reduce trainLoopCount to 100 and set testImageNum to 200

If you still have issues converging, you can try with/without the normalizeNetworkInput flag

snez...@gmail.com

unread,
Jun 19, 2018, 5:07:40 AM6/19/18
to mdCNN: Multidimensional CNN library in Matlab
Thanks so much for your reply!
I did what you suggested but the scesRate was completely constant=67.50% and all data were classified in first class. and I've got these errors :

Error using
images.internal.imageDisplayValidateParams>validateCData
(line 115)
Multi-plane image inputs must be RGB images of
size MxNx3.

Error in
images.internal.imageDisplayValidateParams (line
27)
common_args.CData =
validateCData(common_args.CData,image_type);

Error in images.internal.imageDisplayParseInputs
(line 78)
common_args =
images.internal.imageDisplayValidateParams(common_args);

Error in imshow (line 245)
    images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
    
Error in checkNetwork (line 168)
        imshow(im,'Border','loose');

Error in demoMnist (line 18)
checkNetwork(net,Inf,MNIST,1);

BR
Somayeh

Hagay Garty

unread,
Jun 19, 2018, 2:15:00 PM6/19/18
to mdCNN: Multidimensional CNN library in Matlab
The error is caused since imshow cannot show an image with more than 3 colors. so you can simply remark this call.
As for the single class classification, make sure the labels vector and training data are ordered randomly. If it's not then you should get some warning when training starts.

snez...@gmail.com

unread,
Jun 20, 2018, 4:58:32 AM6/20/18
to mdCNN: Multidimensional CNN library in Matlab
Hi again,

Thanks for your answers!
 I've checked the labels and training data. they've ordered randomly and I didn't get any warning when training started. This is first 100 values of my labels vector for instance:

labels =

     0     2     2     0     0     1     0     0     0     0     1     0     1     2     0     0     0     0      0     0     0     0     0     2     0     0     2      0     0     0     1     0     2     1     0     1
     0     2     0     0     2     1     0     1     0      0     2     0     0     2     0     0     0     0      0     1     0     0     0     2     0     0     0      0     0     0     1     0     0     0     0     0
     2     1     0     2     1     1     0     0     1      2     0     2     0     0     0     0     0     1      0     0     0     0     1     0     2     0     2      1
 
As you see they are in random order but the number of class 0 is more. Could you please tell me if you think there is another reason for this wrong classification? Should I modify some layers or kernels?

BR
Somayeh

snez...@gmail.com

unread,
Jun 25, 2018, 6:30:00 AM6/25/18
to mdCNN: Multidimensional CNN library in Matlab
Hi again,

I've tested some things to change the result but unfortunately, nothing happened. Do you think is it possible to change the result with some modification in optimization algorithm such as smaller steps? In case, how can I do that?

BR
Somayeh

Hagay Garty

unread,
Jun 28, 2018, 4:34:53 AM6/28/18
to mdCNN: Multidimensional CNN library in Matlab
Not sure what is your issue. You can try without normalization, did you try to set 'normalizeNetworkInput ' to 0?
You can control the learning rate in the config file. Set 'net.hyperParam.ni_initial' to any value you wish
Reply all
Reply to author
Forward
0 new messages