why i'm getting the following error using fitcecoc

13 次查看(过去 30 天)
Following is the code:
%%dataset= datastore('D:\mat_project');
imgfolder=fullfile('D:\','mat_project');
dataset = imageSet(imgfolder);
trainingLabel = zeros(1, 11);
personIndex = zeros(1, 11);
[training,test] = partition(dataset,[0.8 0.2]);
%%hog features for training set
trainingFeatures=zeros(size(training,2)*training(1).Count,531036);
featureCount=1;
for i= 1:size(training,2)
for j= 1:training(i).Count
trainingFeatures(featureCount,:)=extractHOGFeatures(read(training(i),j));
trainingLabel(featureCount,:)=training(i).Description;
featureCount=featureCount+1;
end
personIndex(i,:)=training(i).Description;
end
Classifier = fitcecoc(trainingFeatures,trainingLabel);
%%test imaage from test set
person=1;
querImage=read(test(person),1);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel, personIndex);
integerIndex = find(booleanIndex);
subplot(1,2,1);imshow(queryImage);title('Query Face');
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched Class');
Error using classreg.learning.internal.ClassLabel (line 29)
You must pass class labels as a vector.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 480)
allClassNames = levels(classreg.learning.internal.ClassLabel(Y));
Error in classreg.learning.FitTemplate/fit (line 213)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationECOC.fit (line 116)
this = fit(temp,X,Y);
Error in fitcecoc (line 329)
obj = ClassificationECOC.fit(X,Y,ecocArgs{:});
Error in example (line 18)
Classifier = fitcecoc(trainingFeatures,trainingLabel);

回答(2 个)

Rohan Amarapurkar
Rohan Amarapurkar 2019-3-28
As the error message suggeests, check your trainingLabel variable. Its dimensions must match with the dimensions (number of rows) of the trainingFeatures variable. You also might want to check the for loops again, there could be an error in the way you are allocating values to trainingLabel.

zinou sell
zinou sell 2019-6-17
i use Deep learning for face recignition and svm as a cllasifier. when i run the program i got this :
Error using classreg.learning.classif.FullClassificationModel.processClassNames (line 176)
Requested class names are not found among passed class labels.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 492)
classreg.learning.classif.FullClassificationModel.processClassNames(...
Error in classreg.learning.FitTemplate/fit (line 213)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationECOC.fit (line 116)
this = fit(temp,X,Y);
Error in fitcecoc (line 329)
obj = ClassificationECOC.fit(X,Y,ecocArgs{:});
Error in CNNFaceRec (line 95)
clf = fitcecoc(descriptors,lab,'Learners',t,'FitPosterior',1,...
what should i do ?
thank you
  1 个评论
Saira
Saira 2020-3-11
How can I solve this error?
Error:
Subscripted assignment dimension mismatch.
trainingLabel(featureCount,:) = TrainingimgSets(i).Description;

请先登录,再进行评论。

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by