Face Recignition using SVM outputs the same Class
Show older comments
The following code implements Fisher's Discriminant Analysis and SVMs using LIBSVM.I am trying to classify the Test Image using a binary tree structure and SVM(libsvm),but the following code outputs the same class every time.The LDA algorithm with EuclideanDistance classifier has good acuraccy.
TrainDatabasePath = uigetdir(strcat(matlabroot,'\work'), 'Select training database path' );
TestDatabasePath = uigetdir(strcat(matlabroot,'\work'), 'Select test database path');
%Each column of T contain an training image vector
[T,irow,icol] = CreateDatabase(TrainDatabasePath);
Class_population = 13;
Class_number = ( size(T,2) )/Class_population;
Train_number=size(T,2);
%LDA IN TRAINING DATABASE
[m,V_PCA,V_Fisher,ProjectedImages_Fisher] =FisherfaceCore(T,Class_population);
prompt = {'Enter test image name (a number between 1 to 50):'};
dlg_title = 'Input of FLD-Based Face Recognition System';
num_lines= 1;
def = {'1'};
TestImage = inputdlg(prompt,dlg_title,num_lines,def);
TestImage = strcat(TestDatabasePath,'\',char(TestImage),'.jpg');
InputImage = imread(TestImage);
%Project Test Image in Subspace
temp = rgb2gray(InputImage);
temp=double(temp);
[irow icol] = size(temp);
InImage = reshape(temp',irow*icol,1);
Difference = double(InImage)-m;
ProjectedTestImage = V_Fisher' * V_PCA' * Difference;
%SVM parameters. The kernel is a polynomial
c=1e9;
params=[' -t ' int2str(1) ' -c ' int2str(c)];
% prevArray starts with an array containing each class. Winner array is the
%classes that are selected in the binary tree
prevArr = [1:Class_number];
winnerArr = [];
feature=[];
% This section of the code computes a binary SVM tree, by solving a 2 class
% problem with SVM for every 2 classes (1 and 2, 3 and 4, 5 and 6 etc). The
% that you selected is classified according to each 2-class problem and the
% class selected goes on to compete with the other classes selected.
for max = 1:1000
winnerArr = [];
for winRep = 1:2:length(prevArr)
% Selects the two classes to train the SVM
if winRep >= length(prevArr)
i = prevArr(winRep) ;
j = prevArr(winRep-1) ;
else
i = prevArr(winRep) ;
j = prevArr(winRep+1) ;
end
% Selects the features of the 2 classes
feature = [ProjectedImages_Fisher(1:2,Class_population*i-(Class_population-1):Class_population*i),ProjectedImages_Fisher(1:2,Class_population*j-(Class_population-1):Class_population*j)]';
% Assigns the labels for each class
for m1 = 1:Class_population
label(m1) = 1;
end
for n1 = Class_population+1:2*Class_population
label(n1) = -1;
end
% The SVM is trained
model=svmtrain(label',feature, params);
% The face that the user selected is classified to any of the two
% classes
guessLab(1) = 1;
predLabel=svmpredict(guessLab',[ProjectedTestImage(1) ProjectedTestImage(2)],model);
predLabel;
% A winner class is selected
if predLabel == 1
winnerArr = [winnerArr i];
elseif predLabel == -1
winnerArr = [winnerArr j];
end
if winnerArr > 1
for c1 = 2:length(winnerArr)
if winnerArr(c1) == winnerArr(c1-1)
winnerArr(c1) = [];
end
end
end
end
prevArr = winnerArr;
if length(winnerArr) < 2
winnerArr;
break
end
end
% This is the class that was selected
CLASS = winnerArr;
display('The class that matches your face is:')
display(CLASS)
1 Comment
Image Analyst
on 10 Dec 2017
I'm not seeing a question there. Just a statement/announcement plus some code. And some code like FisherfaceCore() is missing and the images are also missing, so no one can do anything.
Answers (0)
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!