簡體   English   中英

為什么准確度為0%? MATLAB LIBSVM

[英]Why is the accuracy coming as 0% ? MATLAB LIBSVM

我使用以下方法提取PCA功能:

function [mn,A1,A2,Eigenfaces] = pca(T,f1,nf1) 
m=mean(T,2),   %T is the whole training set
train=size(T,2);
A=[];
for i=1:train
    temp=double(T(:,i))-m;
    A=[A temp];
end

train=size(f1,2);    %f1 - Face 1 images from training set 'T'
A=[];
for i=1:train
    temp=double(f1(:,i))-m;
    A1=[A1 temp];
end


train=size(nf1,2);    %nf1 - Images other than face 1 from training set 'T'
A=[];
for i=1:train
    temp=double(nf1(:,i))-m;
    A2=[A2 temp];
end

L=A'*A;
[V D]=eig(L);
for i=1:size(V,2)
    if(D(i,i)>1)
       L_eig=[L_eig V(:,1)];
    end
end 
Eigenfaces=A*L_eig;
end  

然后我只從訓練數據中投射出面部1(+1級):

功能1

for i=1:15                       %number of images of face 1 in training set
    temp=Eigenfaces'*A1(:,i);
    proj_img1=[proj_img1 temp];
end

然后我從訓練數據中投射出其余的面(-1級):

功能2

 for i=1:221              %number of images of faces other than face 1 in training set
      temp=Eigenfaces'*A2(:,i);
      proj_img2=[proj_img2 temp];
 end

功能3然后使用以下方法獲得輸入圖像矢量:

diff=double(inputimg)-mn;   %mn is the mean of training data
testfeaturevector=Eigenfaces'*diff;

我將功能1和2的結果寫在CSV文件中,標簽分別為+1和-1。 然后我使用LIBSVM來獲得真實標簽時的准確度,它返回0%,當我試圖預測標簽時它是-1而不是+1。

准確度為0%?

基本上我的模型沒有正確訓練,我沒有看到錯誤。

任何建議將不勝感激。

使用Eigenfaces作為訓練集,用1或-1組成label向量(如果Eigenfaces的第i列引用1,則label的第i個元素為1,否則為-1)。 並在svmtrain函數中使用Eigenfaceslabel

@ lennon310:

for i=1:length(Eigenfaces)                   
    temp=Eigenfaces'*A(:,i);
    proj_imgs=[proj_imgs temp];
end

@ lennon310:

   diff=double(inputimg)-mn;   %mn is the mean of training data

   testfeaturevector=Eigenfaces'*diff;

坦白說,你的代碼很亂。

一個值得懷疑的部分:

data = reshape(data, M*N,1);

這不會使data成為只有1列的矩陣嗎? 這根本不符合邏輯。

關於特征臉的本教程。 其中有代碼和示例向您展示如何操作。 有關詳細信息,請參閱此處的相關網頁。 Matlab / Octave代碼可以在這里找到。

@lennon310: 

    temp=double(testimg)-m;  %where 'm' is the mean of the training images
    L=temp'*temp;
    [V D]=eig(L);
    for i=1:size(V,2)
        if(D(i,i)>1)
           L_eig=[L_eig V(:,1)];
        end
    end 
    Eigenfaces=temp*L_eig;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM