Number of observations in X and Y disagree for Regression Convolution network

조회 수: 2 (최근 30일)
Duong Pham
Duong Pham 2022년 1월 3일
댓글: Duong Pham 2022년 1월 11일
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
dpb
dpb 2022년 1월 3일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2022년 1월 11일
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.
If you are still facing the issue then contact support.
  댓글 수: 1
Duong Pham
Duong Pham 2022년 1월 11일
I am not sure what happen but the base on your code it is working now. Not sure what is the difference? Thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by