Matlab Face Recognition с использованием SVM выводит тот же класс
В следующем коде реализуется дискриминантный анализ и SVM Фишера с использованием LIBSVM. Я пытаюсь классифицировать тестовое изображение, используя бинарную древовидную структуру и SVM(libsvm), но каждый раз следующий код выводит один и тот же класс. Алгоритм LDA с классификатором EuclideanDistance хорошо 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)