Number of observations in X and Y disagree for Regression Convolution network
2 views (last 30 days)
Show older comments
Dear All,
I tried to used CNN network for regression.
My training input data is 16x16x1x9000 (9000 images of size 16)
The output is 9000x1 real number
I set the layer in matlab as :
layers = [
imageInputLayer([16 16 1]) %%
convolution2dLayer(3,8,'Padding','same') %% 16x16
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2) %%%%% 8x8
convolution2dLayer(3,16,'Padding','same') %%% 8x8
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2)%%%% 4x4
batchNormalizationLayer
reluLayer
dropoutLayer(0.2)
fullyConnectedLayer(1)
regressionLayer];
When I tried to train thenetwork this error appeared :"Number of observations in X and Y disagree".
Can any one help me and point out what is wrong with the layer setting above?
Thank you very much.
1 Comment
dpb
on 3 Jan 2022
I don't have the toolbox, but at least some of the regression functions are so braindead as to error like that if the x and y vectors are the same length but oriented differently.
Might check that all are either column or row vectors as starting point.
Also, why do you have a 16x16x1x9000 4D array when a 3D array would do and be simpler notationally and, no doubt, conceptually as well?
Answers (1)
Srivardhan Gadila
on 11 Jan 2022
Based on the above information, the following is a sample code which trains the network defined above, and I am not getting any such error you have mentioned:
layers = [
imageInputLayer([16 16 1]) %%
convolution2dLayer(3,8,'Padding','same') %% 16x16
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2) %%%%% 8x8
convolution2dLayer(3,16,'Padding','same') %%% 8x8
batchNormalizationLayer
reluLayer
averagePooling2dLayer(2,'Stride',2)%%%% 4x4
batchNormalizationLayer
reluLayer
dropoutLayer(0.2)
fullyConnectedLayer(1)
regressionLayer];
analyzeNetwork(layers)
numSamples = 9;
xtrain = randn(16,16,1,numSamples);
ytrain = randn(numSamples,1);
options = trainingOptions("sgdm");
net = trainNetwork(xtrain,ytrain,layers,options)
Check if you are passing the training data arguments in the correct order for the trainNetwork function. If you are not working on latest release of MATLAB then refer to the following page https://www.mathworks.com/help/doc-archives.html and check the documentation of appropriate release.
See Also
Categories
Find more on Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!