Help ME ! Error in feature input layer in CNN, Number of observations in X and Y disagree

조회 수: 9 (최근 30일)
I am trying to use a deep neural network in Matlab. However, I get the error:
Number of observations in X and Y disagree.
Below is my current implementation:
[inputs, targets] = load_data();
inputs = inputs'; % size : 18000*10
targets = targets'; % size : 18000*5
randDataNum = 0.15*18000;
%% Validation Data
idx_val = randperm(size(inputs,1),randDataNum);
xVal = inputs(idx_val,:);
inputs(idx_val,:) = [];
yVal = targets(idx_val,:);
targets(idx_val,:) = [];
%% Test Data
idx_test = randperm(size(inputs,1),randDataNum);
xTest = inputs(idx_test,:);
inputs(idx_test,:) = [];
yTest = targets(idx_test,:);
targets(idx_test,:) = [];
%% Define Network Architecture
% Define the convolutional neural network architecture.
layers = [
featureInputLayer(10,'Name','inputs')
fullyConnectedLayer(30) % 384 refers to number of neurons in next FC hidden layer
batchNormalizationLayer
reluLayer
fullyConnectedLayer(30) % 384 refers to number of neurons in next FC hidden layer
reluLayer
fullyConnectedLayer(5) % 2 refers to number of neurons in next output layer (number of output classes)
regressionLayer];
options = trainingOptions('adam',...
'InitialLearnRate', 0.0001, ...
'MiniBatchSize',16, ...
'Shuffle','every-epoch', ...
'MaxEpochs',500, ...
'Verbose',false,...
'Plots','training-progress',...
'ValidationData',{xVal,yVal'});
net = trainNetwork(inputs,targets,layers,options);
how can i fix this error ?
I am using MATLAB 2021b
  댓글 수: 1
Fahad Abdul Wahid
Fahad Abdul Wahid 2022년 8월 5일
I've some doubts regarding your function. I'm learning deep learning and wanted to know in the below function
featureInputLayer(10,'Name','inputs') - what does 10 signify?
fullyConnectedLayer(30) what does 30 signify?
fullyConnectedLayer(5) what does 5 signify?
why is there two fully connected layer? What happens when you have only 1 fully connected layer?

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

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 6월 25일
편집: Cris LaPierre 2022년 6월 29일
I see the error in this line:
'ValidationData',{xVal,yVal'});
% ^
You are transposing yVal. Assuming your input and target variables are the size you say, this is unnecessary, and causing your number of observations to disagree. Remove the apostraphe, and it should run.
  댓글 수: 3
nagihan yagmur
nagihan yagmur 2023년 3월 17일
What is the content of the target data? I am also facing a problem. the target of my dataset consists of 5 different classes. Is yours like this too? can you help me
Cris LaPierre
Cris LaPierre 2023년 3월 17일
@nagihan yagmur please share the same information as the OP so we can help you. Also, if you create a new question, it will get more eyes on it, as this one has an accepted answer.

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

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 6월 25일
As I see in your code the X and Y have mismacthed sizes:
inputs = inputs'; % size : 18000*10
targets = targets'; % size : 18000*5
Make sure that they have the same size when you feed them in trainNetwork().
  댓글 수: 1
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 6월 25일
Another point is a proper use of size() command, while selecting some data for validation and testing using random number generator, i.e., randperm().

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


Arman Ali
Arman Ali 2023년 4월 17일
@Amir Hossein Asadian can you contact me at arman.ncepu@gmail.com , need your help. Thank you

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by