Why CNN Regression trainnetwork input output be the same 2-D metrics

2 ビュー (過去 30 日間)
Hao Mai
Hao Mai 2018 年 5 月 7 日
回答済み: Siraj 2022 年 6 月 27 日
I want to use same size 2D Input Output data to build a denoising CNN model just like Resnet
But net = trainNetwork(X,X,layers,options) always sending error:
Invalid training data. X and Y must have the same number of observations.
And I do not understand how to fix it . Here is a sample code below, Thanks for your help
layers = [...
imageInputLayer([25 25 1])
convolution2dLayer([4 3],12)
reluLayer
crossChannelNormalizationLayer(4)
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,16)
reluLayer
crossChannelNormalizationLayer(4)
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(256)
reluLayer
fullyConnectedLayer(25*25)%Change the dimensions to match the outputs.
regressionLayer;
];
%create training option
options = trainingOptions('sgdm','InitialLearnRate',0.001, ...
'MaxEpochs',15);
%create network
X(:,:,:,1) = rand(25);
Y=randn(1,25,25,1);
net = trainNetwork(X,Y,layers,options)

回答 (1 件)

Siraj
Siraj 2022 年 6 月 27 日
Hi,
It is my understanding that you want to train a model that gives the output of same dimension that of the input. For this you will have to tune your architecture, Currently the output dimensions of your network are 1X1X625 because the fully connected layer always gives a 1D output, also the error that you are getting is because the Y has incorrect dimensions. The responses, Y, can be a NxR matrix, where N = observations, R = number of responses (or output of the network).
Hope it helps

Community Treasure Hunt

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

Start Hunting!

Translated by