⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runkfda.m

📁 It is for Face Recognition
💻 M
📖 第 1 页 / 共 3 页
字号:
  s1 = T1*vec'-mT1;     % a col vec
  if (norm(s1, 2) > maxFaceNorm)
     C(x,y) = -1;
     fprintf('.');
     cntThres=cntThres+1;
  else
      % build local model
      [X1, Y1, err1, d1, d2]=buildLocalModel(s1', R, fm1, nfm1, 'quadratic');      
      if err1 == -1         % no sample
           C(x,y) = -1; 
           fprintf('?'); 
           cntBadModel=cntBadModel+1;
      elseif err1 == -2     % covar singular,  NN classify
           mind1 = min(d1); 
           mind2 = min(d2);
           cntNN=cntNN+1;
           if mind1/(mind1+mind2) < 0.45
             C(x,y) = 1;
             fprintf('^');
           else
             C(x,y) = -1;
             fprintf('-');
           end
      else              % local SVM with monomial mapping
        c=classify(s1', X1, Y1, 'quadratic');
        cntKernel=cntKernel+1;
        C(x,y)=c;
        if c==1
           fprintf('+');
        else
           fprintf('x');
        end 
      end
  end %if norm(s1,2) > ...
end
end

% plot result
imshow(detImg, [0 255]); hold on;

for y=1:imgHt-modHt
for x=1:imgWd-modWd
  if C(x,y)==1
     plotBox(x, y, modWd, modHt, '-r');
  end
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Local Kernel Method for Face Recogntion
% Z. Li
% 6.12.2004
% performance:
% (1) n=20; recRate = 92.11 %
%     R = [400 600 800]; minFaceCnt=3; 
%     ids = 21:40; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
% (2.1) n=30: recRate=94.74 % 
%     R = [400 600 800]; minFaceCnt=2; 
%     ids = 11:40; poses = [1 2 3 6 7 9]; xPoses = [4 5 8 10];
% (2.2) n=30: recRate=93.1 %
%     R = [400 600 800]; minFaceCnt=2; 
%     ids = 11:40; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
% (3.1) n=40: recRate=85.53 %
%     R = [400 600 800]; minFaceCnt=2; 
%     ids = 1:40; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
% (3.2) n=40: recRate=92%
%     R = [1200 1200 1600]; minFaceCnt=2; options = 'linear';
%     ids = 1:40; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
% (3.3) n=40, 93%
%     R = [800 800 1200]; minFaceCnt=2; options = 'linear';
%     ids = [1:40]; poses = [1 2 3 4 6 7 9]; xPoses = [5 8 10];
% (4): n=30, R=R2, minFaceCnt=2;
% (4.1) ids = [11:40]; poses = [1 2 3 4 6 7 9]; xPoses = [5 8 10];
%       rec=0.9195    0.6207    0.6437    0.9080
% (4.2) ids = [11:40]; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
%       rec=0.9474    0.6491    0.5614    0.9298
% (4.3) ids = [11:40]; poses = [1 2 3 4 5 6 7 8 9]; xPoses = [10];
%       rec=0.9655    0.7586    0.7586    0.9310
% (4.4) ids = [1:20, 31:40]; poses = [1 2 3 4 6 7 8 9 10]; xPoses = [5];
%       rec=0.9643    0.5357    0.6071    0.8214
% (4.5) ids = [6:10, 16:40]; poses = [1 2 4 5 6 7 9 10]; xPoses = [3 8];
%       rec= 0.9138    0.4655    0.6552    0.8793
% (4.6) ids = [6:10, 16:40]; poses = [1 2 4 5 6 9 10]; xPoses = [3 7 8];
%       rec= 0.8506    0.4253    0.5402    0.7586
% (5):  n= 40, R=R6, minFaceCnt=2;
% (5.1) ids = [1:40]; poses = [1 2 4 6 9 10]; xPoses = [3 5 7 8];
%       rec=0.9474    0.9013    0.5066    0.9474
% (5.2) ids = [1:40]; poses = [1 2 3 4 5 6 7 8 9 10]; xPoses = [1 6 9 10];
%       rec=0.9868    0.9539    0.6776    0.9868


Face Det/Rec Performance:
3 face models:
   1) 18x16 upper face, 16-dim
   2) 14x18 lower face, 12-dim
   3) 21x28 full face,  20-dim
3 modes of classification:
   1) NN        - nearest neighbour
   2) Linear    - linear boundary
   3) Kernel    - non-linear mapping by kernel K(x,y) = <x,y>^2

 Detection:

 need more NonFace samples !

 Recog Performance stats on n=30 people recognition:

 n=30
 rec rate:  combined  upper     lower     full
%           0.9195    0.6207    0.6437    0.9080
%           0.9474    0.6491    0.5614    0.9298
%           0.9655    0.7586    0.7586    0.9310
%           0.8506    0.4253    0.5402    0.7586
%           0.9138    0.4655    0.6552    0.8793
%           0.9643    0.5357    0.6071    0.8214

--------------------------------------------
            FD      FR
--------------------------------------------
NN          154     20
Linear      0       151
Kernel      264     9(singular, bad) 
--------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
% load face recog models
% 18x16 upper face, 16-d
Fm1 = load('prjATTUpperFaceS04T08L08W18H16K16.dat');
% 14x18 lower face, 12-d
Fm2 = load('prjATTLowerFaceS01T-06L14W18H12K12.dat');
% 21x28 full face,  20-d
Fm3 = load('prjATTFullFaceModel4.dat');    



fm1 = Fm1; fm2=Fm2; fm3=Fm3;
R1=[inf inf inf]; R2=[400 600 800]; R3=[600 800 1000];R4=[600 400 800];
R5=[600 600 1000]; R6=[800 800 1200];
wt3=[ 0.8581    0.3472    0.2808    0.1498    0.1137    0.0875    0.0834    0.0530    0.0465    0.0446    0.0376    0.0350    0.0330    0.0308    0.0250    0.0224    0.0208    0.0195    0.0179    0.0170];
    

st = cputime;
R = R2; minFaceCnt=2; options = 'kernel';
ids = [11:40]; poses = [1 2 3  5  7 8 9]; xPoses = [4 6 10];
    recCnt=0; recCnt1=0; recCnt2=0; recCnt3=0; 
    cntNN=0; nnRec=0;
    nPerson = length(ids)*length(xPoses);
    for j=1:length(ids)
      qId = ids(j);      
      for k=1:length(xPoses)
         qPose = xPoses(k);     
         [nnId, fisherId3, fisherErr3, m3]=multiModeFaceRecognition(Fm3, ids, poses, qId, qPose, wt3, inf, 'NN');   
         if nnId == qId 
            nnRec=nnRec+1;
         end
         [results]=kfdFaceRecognition(fm1, fm2, fm3, qId, qPose, ids, poses, R, minFaceCnt, options);
         rId1 = results(1,1); err1=results(1,2); nModel1=results(1,3);
         rId2 = results(2,1); err2=results(2,2); nModel2=results(2,3);
         rId3 = results(3,1); err3=results(3,2); nModel3=results(3,3);
         if err1 == inf | err2 == inf | err3==inf
            cntNN = cntNN+1;
         end
         if rId1 == -2  % no model
           nPerson=nPerson-1;
         else
           [v, idx]=min([err1 err2 err3]);
           recIds=[rId1 rId2 rId3];
           if recIds(idx) == qId           
                fprintf('\n [%d +]', idx);
                recCnt=recCnt+1;
           else
                fprintf('\n [%d -]', idx);
           end
           if qId == rId1
              recCnt1=recCnt1+1;
           end
           if qId == rId2
              recCnt2=recCnt2+1;
           end
           if qId == rId3
              recCnt3=recCnt3+1;
           end
           fprintf(' q=%d:%d recIds: %d %d %d errRate: %1.2f %1.2f %1.3f nSample: %d %d %d', qId, qPose, rId1, rId2, rId3, err1, err2, err3, nModel1,nModel2,nModel3);
         end
         
      end
    end

    recRate=recCnt/nPerson;
    recRate1=recCnt1/nPerson;
    recRate2=recCnt2/nPerson;
    recRate3=recCnt3/nPerson;

    [recRate recRate1 recRate2 recRate3 nnRec/nPerson]

    ct=cputime-st




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Local Kernel Method for Face Recogntion
% Z. Li
% 7.12.2004
% performance:
% (4.1) ids = [11:40]; poses = [1 2 3 4 6 7 9]; xPoses = [5 8 10];
%       rec=0.9195    0.6207    0.6437    0.9080
% (4.2) ids = [11:40]; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
%       rec=0.9474    0.6491    0.5614    0.9298
% (4.3) ids = [11:40]; poses = [1 2 3 4 5 6 7 8 9]; xPoses = [10];
%       rec=0.9655    0.7586    0.7586    0.9310
% (4.4) ids = [1:20, 31:40]; poses = [1 2 3 4 6 7 8 9 10]; xPoses = [5];
%       rec=0.9643    0.5357    0.6071    0.8214
% (4.5) ids = [6:10, 16:40]; poses = [1 2 4 5 6 7 9 10]; xPoses = [3 8];
%       rec= 0.9138    0.4655    0.6552    0.8793
% (4.6) ids = [6:10, 16:40]; poses = [1 2 4 5 6 9 10]; xPoses = [3 7 8];
%       rec= 0.8506    0.4253    0.5402    0.7586
%       rec=0.9770    0.9080    0.5402    0.9770    0.8851    0.9080
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
% load face recog models
% 18x16 upper face, 16-d
Fm1 = load('prjATTUpperFaceS04T08L08W18H16K16.dat');
dim1 = 16;
% 14x18 lower face, 12-d
Fm2 = load('prjATTLowerFaceS01T-06L14W18H12K12.dat');
dim2 = 12;
% 21x28 full face,  20-d
Fm3 = load('prjATTFullFaceModel4.dat');    
dim3 = 20;

%%%%%%%%%%%%%%%%%%%%%%%%
% test case 1.1: n=30, minLocalSampleRatio     = 0.30;
%   recRate   recRt1    recRt2    recRt3    eig1      eig3
    0.9310    0.8621    0.5778    0.9540    0.8444    0.8778
    0.9298    0.8246    0.5167    0.9649    0.7833    0.8833
    0.9655    0.8966    0.6000    1.0000    0.8667    0.9333
    1.0000    0.8929    0.5667    1.0000    0.8000    0.9000
    0.9655    0.9500    0.6500    0.9828    0.9333    0.9000
    0.9425    0.8989    0.5341    0.9425    0.8667    0.8444
% test case 1.2: n=30, minLocalSampleRatio     = 0.20;
%   recRate   recRt1    recRt2    recRt3    eig1      eig3
    0.9425    0.8736    0.5556    0.9540    0.8444    0.8778
    0.9474    0.8421    0.5333    0.9649    0.7833    0.8833
    0.9655    0.8966    0.6667    1.0000    0.8667    0.9333
    1.0000    0.8929    0.5667    1.0000    0.8000    0.9000
    0.9655    0.9500    0.6333    1.0000    0.9333    0.9000
    0.9425    0.9101    0.5341    0.9540    0.8667    0.8444
% test case 1.2: n=30, minPoseCnt = 3;  minLocalSampleRatio = 0.20; defaultNNErr = 0.005;
%   recRate   recRt1    recRt2    recRt3    eig1      eig3
    0.9425    0.8444    0.5556    0.9222    0.8444    0.8778
    0.9474    0.8000    0.5333    0.9167    0.7833    0.8833
    0.9655    0.8667    0.6667    0.9667    0.8667    0.9333
    1.0000    0.8333    0.5667    0.9333    0.8000    0.9000
    0.9655    0.9500    0.6333    0.9667    0.9333    0.9000
    0.9425    0.9000    0.5222    0.9222    0.8667    0.8444

    0.9425    0.8444    0.5556    0.9222    0.8444    0.8778   11.9980
    0.9474    0.8000    0.5333    0.9167    0.7833    0.8833    9.0150
    0.9655    0.8667    0.6667    0.9667    0.8667    0.9333    4.9060
    1.0000    0.8333    0.5667    0.9333    0.8000    0.9000    4.7180
    0.9655    0.9500    0.6333    0.9667    0.9333    0.9000    7.0140
    0.9425    0.9000    0.5222    0.9222    0.8667    0.8444    8.1240
%%%%%%%%%%%%%%%%%%%%%%%%
% local model parameters
wt1=ones(16);R1=420; wt2=ones(12);R2=400; wt3=ones(20);R3=860;

recRate=[]; ct=[];
for t=1:6
    % old test set
    ids=[]; poses=[]; xPoses=[];
    if t==1
       ids = [11:40]; poses = [1 2 3 4 6 7 9]; xPoses = [5 8 10];
    elseif t == 2
       ids = [11:40]; poses = [1 2 3 4 6 7 8 9]; xPoses = [5 10];
    elseif t == 3
        ids = [11:40]; poses = [1 2 3 4 5 6 7 8 9]; xPoses = [10];
    elseif t == 4
        ids = [1:20, 31:40]; poses = [1 2 3 4 6 7 8 9 10]; xPoses = [5];
    elseif t == 5
        ids = [6:10, 16:40]; poses = [1 2 4 5 6 7 9 10]; xPoses = [3 8];
    else
        ids = [6:10, 16:40]; poses = [1 2 4 5 6 9 10]; xPoses = [3 7 8];
    end    
    [recRate(t,:), ct(t)]=testMultiModelFaceRecognition(Fm1, Fm2, Fm3, wt1, wt2, wt3, R1, R2, R3, ids, poses, xPoses, 'n');
end % for test
 
result=[recRate, ct']

 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% test case 2.1: n=40, minLocalSampleRatio     = 0.30;
    0.9145    0.8903    0.5897    0.9211    0.8375    0.7813
    0.9558    0.9402    0.5763    0.9558    0.8917    0.8500
    0.9333    0.8667    0.5125    0.9333    0.7875    0.8250
    0.9873    0.9125    0.6538    0.9873    0.9125    0.8875
    0.9200    0.9091    0.5395    0.9200    0.8625    0.8625
    0.9459    0.8831    0.5897    0.9730    0.8000    0.8375  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -