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

2 次查看(过去 30 天)
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.

类别

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