# Size of Matrix Training Data for CNN for Regression

조회 수: 37(최근 30일)
MathWorks Support Team 2017년 10월 5일
댓글: TIRUPATHI RAO ALTHI 2019년 10월 6일
I am trying to use a CNN to solve a regression problem. I have a 64 by 2048 vector as input training data. I am trying to make an auto-encoder, so this is also the size of my output training data.
The command below gives me the error shown
net = trainNetwork(X,X,lgraph,options);
Error using trainNetwork (line 140)
Invalid training data. X and Y must have the same number of observations.
What does this error mean? 'X' and 'Y' are the same matrix, so I do not understand how they have a different number of observations.

### 채택된 답변

MathWorks Support Team 2018년 4월 18일
If you look closely at the documentation for "trainNetwork", you can see that the input data can be a 4D Numeric Matrix, and the output can be a 2D Numeric matrix for regression. This documentation is linked below:
This input format is required because the input layer more or less expects to treat each as an h by w by c image, where h is height, w is width, and c is the number of channels in the image. This requires you to initialize extra dimensions as a placeholder in the input. Note that you must do this for your training and validation data. To do this, you can transform 'X' as below:
Xnew = reshape(x, [size(x,1),1,1,size(x,2)]);
Similarly, you must transform the output training data to be a Number of Observations by Number of Response Variables matrix. This can be done by simply setting this to the transpose of 'X'. Again, this must be done for both training and validation data.
##### 댓글 수: 1표시숨기기 없음
Ben Hur 2017년 11월 20일
@ MathWorks Support Team , Can you please explain more as I have the same problem. I did what you doing but still the same problem. Is the 64 the observation? also what did you mean by the three line in the end.
My training data is 18000x24000 , the 18000 is the observation (each is a single image) and the 24000 is the feature.

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

### 추가 답변(2개)

Ling Zhang 2018년 3월 28일
I encountered the same problem by using trainedNet = trainNetwork(X_train,Y_train,layers,options); My X_train is a 4D matrix, and Y_train is a 2D matrix.
But then I changed it Y_train to Y_train', and it works!
trainedNet = trainNetwork(X_train,Y_train',layers,options)
##### 댓글 수: 1표시숨기기 없음
TIRUPATHI RAO ALTHI 2019년 10월 6일
I encountered the same problem by using trainedNet = trainNetwork(X_train,Y_train,layers,options); My X_train is a 4D matrix, and Y_train is a 2D matrix.
But then I changed it Y_train to Y_train', and it works!
trainedNet = trainNetwork(X_train,Y_train',layers,options)
thank you Ling Zhang

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

Bhartendu 2018년 4월 8일

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

R2017b

### Community Treasure Hunt

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

Start Hunting!

Translated by