Code covered by the BSD License  

Highlights from
Morphological Shared-Weight Neural Network for Face Recognition

image thumbnail

Morphological Shared-Weight Neural Network for Face Recognition

by

 

31 Dec 2004 (Updated )

MSNN has the ability to learn feature extraction and perform classification at the same time.

validation.m
% This function validates the training output
% of the training and the test set

clear

thresholdmin1=0.8; thresholdmax1=0.84;
thresholdmin2=0.86; thresholdmax2=0.877;
thresholdmin3=0.89; thresholdmax3=0.898;
thresholdmin4=0.9; thresholdmax4=0.912;
thresholdmin5=0.756; thresholdmax5=0.7590;
thresholdmin6=0.724; thresholdmax6=0.727;
thresholdmin7=0.741; thresholdmax7=0.742;
thresholdmin8=0.7372; thresholdmax8=0.7377;
thresholdmin9=0.8424; thresholdmax9=0.8427;
thresholdmin10=0.8807; thresholdmax10=0.8808;

%thresholdmin1=0.8; thresholdmax1=0.84;
%thresholdmin2=0.86; thresholdmax2=0.872;
%thresholdmin3=0.89; thresholdmax3=0.896;
%thresholdmin4=0.9; thresholdmax4=0.911;
%thresholdmin5=0.756; thresholdmax5=0.75690;
%thresholdmin6=0.724; thresholdmax6=0.727;
%thresholdmin7=0.741; thresholdmax7=0.742;
%thresholdmin8=0.7372; thresholdmax8=0.7377;
%thresholdmin9=0.8424; thresholdmax9=0.8427;
%thresholdmin10=0.8807; thresholdmax10=0.8808;


load AREA1 outeTrain;load AREA2 outeVal; load AREA3 outeTest;
load C selecte; load C dataP;
outTrain=outeTrain';
outVal=outeVal';
outTest=outeTest';
correct1=0; correct2=0;

c1=0;
c2=0;
c3=0;
c4=0;
flagG=0;flagB=0;

d1=0;
d2=0;
d3=0;
d4=0;




for i=1:size(outTrain,2)
    [maxoutput1 posout1]=max(outTrain(:,i));
    [maxtarget1 postar1]=max(outVal(:,i));
    if posout1==postar1
        correct1=correct1+1;
       
            switch posout1
                case 1
                    c1=c1+1;
                case 2
                    c2=c2+1;
                case 3
                    c3=c3+1;
                case 4
                    c4=c4+1;
                
            end;
        
end;end;


for i=1:size(outTest,2)
    [maxoutput2 posout2]=max(outTrain(:,i));
    [maxtarget2 postar2]=max(outTest(:,i));
    if posout2==postar2
        correct2=correct2+1;
       
            switch posout2
                case 1
                    d1=d1+1;
                case 2
                    d2=d2+1;
                case 3
                    d3=d3+1;
                case 4
                    d4=d4+1;
                
            end;
        
end;end;

disp(strcat('Validation of #F1=',num2str(c1),'.Correct=',num2str(d1)));
disp(strcat('Validation of #F2=',num2str(c2),'.Correct=',num2str(d2)));
disp(strcat('Validation of #F3=',num2str(c3),'.Correct=',num2str(d3)));
disp(strcat('Validation of #F4=',num2str(c4),'.Correct=',num2str(d4)));
disp(strcat('Total validated=',num2str(c1+c2+c3+c4),'.Correctly detected=',num2str(d1+d2+d3+d4)));
disp(strcat('Validation accuracy=',num2str(((c1+c2+c3+c4)/10)*100),'%'));
disp(strcat('Recognition accuracy=',num2str(((d1+d2+d3+d4)/10)*100),'%'));



% Set recognition threshold for training set-----------

for b=1:10
    [maxOtr(b) posOtr(b)]=max(outTrain(:,b));    
end;
flagup=zeros(1,10);
for x=1:10
if maxOtr(x)>=thresholdmin1 & maxOtr(x)<thresholdmax1    
    disp('Validate threshold-F1');
    flagup(x)=1;
elseif maxOtr(x)>=thresholdmin2 & maxOtr(x)<thresholdmax2 
    disp('Validate threshold-F2');
    flagup(x)=2;
elseif maxOtr(x)>=thresholdmin3 & maxOtr(x)<thresholdmax3
    disp('Validate threshold-F3');
    flagup(x)=3;
elseif maxOtr(x)>=thresholdmin4 & maxOtr(x)<thresholdmax4 
    disp('Validate threshold-F4');
    flagup(x)=4;
elseif maxOtr(x)>=thresholdmin5 & maxOtr(x)<thresholdmax5 
    disp('Validate threshold-F5');
    flagup(x)=5;
elseif maxOtr(x)>=thresholdmin6 & maxOtr(x)<thresholdmax6 
    disp('Validate threshold-F6');
    flagup(x)=6;
elseif maxOtr(x)>=thresholdmin7 & maxOtr(x)<thresholdmax7 
    disp('Validate threshold-F7');
    flagup(x)=7;
elseif maxOtr(x)>=thresholdmin8 & maxOtr(x)<thresholdmax8 
    disp('Validate threshold-F8');
    flagup(x)=8;
elseif maxOtr(x)>=thresholdmin9 & maxOtr(x)<thresholdmax9
    disp('Validate threshold-F9');
    flagup(x)=9;
elseif maxOtr(x)>=thresholdmin10 & maxOtr(x)<thresholdmax10
    disp('Validate threshold-F10');
    flagup(x)=10;    
else
    disp('Error: please retrain the network');
    flagup(x)=666;
end;
end;

for td=1:10
    if (flagup(td)==666)
        flagG=flagG+1;
    end;
end;

if flagG>0.5
disp(strcat('Validation accuracy=',num2str(100-(flagG/10)*100),'%'));
else
disp(strcat('Validation accuracy=',num2str(100),'%'));    
end;

% Set recognition threshold for test set---------------
for b=1:10
    [maxO(b) posO(b)]=max(outTest(:,b));    
end;
flag=zeros(1,10);
for x=1:10
if maxO(x)>=thresholdmin1 & maxO(x)<thresholdmax1   
    disp('Validate threshold-F1');
    flag(x)=1;
elseif maxO(x)>=thresholdmin2 & maxO(x)<thresholdmax2
    disp('Validate threshold-F2');
    flag(x)=2;
elseif maxO(x)>=thresholdmin3 & maxO(x)<thresholdmax3
    disp('Validate threshold-F3');
    flag(x)=3;
elseif maxO(x)>=thresholdmin4 & maxO(x)<thresholdmax4
    disp('Validate threshold-F4');
    flag(x)=4;
elseif maxO(x)>=thresholdmin5 & maxO(x)<thresholdmax5
    disp('Validate threshold-F5');
    flag(x)=5;
elseif maxO(x)>=thresholdmin6 & maxO(x)<thresholdmax6
    disp('Validate threshold-F6');
    flag(x)=6;
elseif maxO(x)>=thresholdmin7 & maxO(x)<thresholdmax7
    disp('Validate threshold-F7');
    flag(x)=7;
elseif maxO(x)>=thresholdmin8 & maxO(x)<thresholdmax8
    disp('Validate threshold-F8');
    flag(x)=8;
elseif maxO(x)>=thresholdmin9 & maxO(x)<thresholdmax9
    disp('Validate threshold-F9');
    flag(x)=9;
elseif maxO(x)>=thresholdmin10 & maxO(x)<thresholdmax10
    disp('Validate threshold-F10');
    flag(x)=10;    
else
    disp('Error: please retrain the network');
    flag(x)=666;
end;
end;

for td=1:10
    if (flag(td)==666)
        flagB=flagB+1;
    end;
end;

if flagB>0.5
disp(strcat('Recognition accuracy=',num2str(100-(flagB/10)*100),'%'));
else
disp(strcat('Recognition accuracy=',num2str(100),'%'));    
end;

if selecte>=1 & selecte<=2 
if flag(1)~=666
strg = ['c:\images\id\' num2str(flag(1)) '.tif'];
flagx=flag(1);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F1- ',num2str(flag(1))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;
    
if selecte>=3 & selecte<=4 
if flag(2)~=666
strg = ['c:\images\id\' num2str(flag(2)) '.tif'];
flagx=flag(2);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F7- ',num2str(flag(2))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=5 & selecte<=6
if flag(3)~=666    
strg = ['c:\images\id\' num2str(flag(3)) '.tif'];
flagx=flag(3);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F8- ',num2str(flag(3))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=7 & selecte<=8 
if flag(4)~=666    
strg = ['c:\images\id\' num2str(flag(4)) '.tif'];
flagx=flag(4);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F9- ',num2str(flag(4))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=9 & selecte<=10 
if flag(5)~=666  
strg = ['c:\images\id\' num2str(flag(5)) '.tif'];
flagx=flag(5);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F9- ',num2str(flag(5))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=11 & selecte<=12 
if flag(6)~=666
strg = ['c:\images\id\' num2str(flag(6)) '.tif'];
flagx=flag(6);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F1- ',num2str(flag(6))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;
    
if selecte>=13 & selecte<=14 
if flag(7)~=666
strg = ['c:\images\id\' num2str(flag(7)) '.tif'];
flagx=flag(7);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F7- ',num2str(flag(7))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=15 & selecte<=16
if flag(8)~=666    
strg = ['c:\images\id\' num2str(flag(8)) '.tif'];
flagx=flag(8);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F8- ',num2str(flag(8))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=17 & selecte<=18 
if flag(9)~=666
strg = ['c:\images\id\' num2str(flag(9)) '.tif'];
flagx=flag(9);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F9- ',num2str(flag(9))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if selecte>=19 & selecte<=20 
if flag(10)~=666    
strg = ['c:\images\id\' num2str(flag(10)) '.tif'];
flagx=flag(10);
Dat1=imread(strg);
subplot(122);imshow(Dat1);
title(strcat('Detected: F9- ',num2str(flag(10))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;



    
%-----------------show test image---------------------
subplot(121);imshow(dataP{selecte});
title(strcat('Test Image- ',num2str(selecte)));

save XX;

Contact us