필터 지우기
필터 지우기

I have a problem in the trainNetwork for Xtrain and Ytrain it gives me X and Y must have the same number of observations.

조회 수: 2 (최근 30일)
XTrain = importdata('C:\Users\m7mod\Documents\MATLAB\TrainM.mat'); % size of XTrain = 9 * 44 YTrain = categorical([1 1 1 1 0 0 0 0 0]'); % size of YTrain = 9 * 1 layers = [ ... imageInputLayer([44 1]) convolution2dLayer(5,20) reluLayer fullyConnectedLayer(10) softmaxLayer classificationLayer()] options = trainingOptions('sgdm'); XNew = zeros(size(XTrain,1),1,1,size(XTrain,2)); XNew(:,1,1,:) = XTrain(:,:); net = trainNetwork(XNew,YTrain',layers,options);

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 24일
편집: Ameer Hamza 2018년 4월 24일
You are facing the problem because you are trying to use imageInputLayer and convolution2dLayer which will only work if your input sample have at least 2 non-singleton dimensions (i.e. m*n and m*n*k will work but 1*m or m*1 will not work). For a single dimension data (as in your case 1*44), you can use sequenceInputLayers. For your case, if you can change the layers combination as shown in following script snippet the code will work
XTrain = importdata('C:\Users\m7mod\Documents\MATLAB\TrainM.mat'); % size of XTrain = 9 * 44
YTrain = categorical([1 1 1 1 0 0 0 0 0]'); % size of YTrain = 9 * 1
layers = [ ...
sequenceInputLayer(44)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm');
net = trainNetwork(XTrain',YTrain',layers,options);
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2018년 4월 24일

The documentation page state that it was introduced in 2017b.

If you are using earlier version then you can use fitnet and train as

XTrain = importdata('C:\Users\m7mod\Documents\MATLAB\TrainM.mat'); % size of XTrain = 9 * 44 
YTrain = [1 1 1 1 0 0 0 0 0]'; % size of YTrain = 9 * 1 
net = fitnet([10 10]);
net = train(net, XTrain',YTrain');
mahmoud Bassiouni
mahmoud Bassiouni 2019년 3월 26일
XTrain = AllTrainCel(1:200000,:)'; 4 * 200000
YTrain = categorical([1 0 -1 -2]'); % 4 * 1;
layers = [ ...
sequenceInputLayer(200000)
%reluLayer
LSTMLayer
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm');
net = trainNetwork(XTrain',YTrain',layers,options);
net = fitnet([10 10]);
XTest = AllTestCel(1:200000,:)';
YTest = categorical([1 0 -1 -2]');
[YPred] = classify(net,XTest);
The problem is in the classification stage the classify doesnt work it. It needs more parameters although it work in the examples with two parameters only

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

추가 답변 (1개)

mahmoud Bassiouni
mahmoud Bassiouni 2019년 3월 27일
The problem is in the classification stage the classify doesnt work it. It needs more parameters although it work in the examples of deep learning with two parameters only
XTrain = AllTrainCel(1:200000,:)'; 4 * 200000
YTrain = categorical([1 0 -1 -2]'); % 4 * 1;
layers = [ ...
sequenceInputLayer(200000)
%reluLayer
LSTMLayer
fullyConnectedLayer(4)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm');
net = trainNetwork(XTrain',YTrain',layers,options);
net = fitnet([10 10]);
XTest = AllTestCel(1:200000,:)';
YTest = categorical([1 0 -1 -2]');
[YPred] = classify(net,XTest);

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by