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.

detect.m
clear

ch = input('Input test image [1-40]:');

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;

load M outTrain;
outFTrain=outTrain';

load N outTest;
outFTest=outTest';

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(outFTrain,2)
    [maxoutput1 posout1]=max(outFTrain(:,i));
    [maxtarget1 postar1]=max(outFTest(:,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(outFTest,2)
    [maxoutput2 posout2]=min(outFTrain(:,i));
    [maxtarget2 postar2]=min(outFTest(:,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 max=',num2str(c1),'.Validation of min=',num2str(d1)));
disp(strcat('Validation of max=',num2str(c2),'.Validation of min=',num2str(d2)));
disp(strcat('Validation of max=',num2str(c3),'.Validation of min=',num2str(d3)));
disp(strcat('Validation of max=',num2str(c4),'.Validation of min=',num2str(d4)));
disp(strcat('Total validated max=',num2str(c1+c2+c3+c4),'.Total Validated min=',num2str(d1+d2+d3+d4)));
disp(strcat('Matched accuracymax =',num2str(((c1+c2+c3+c4)/10)*100),'%'));
disp(strcat('Matched accuracymin =',num2str(((d1+d2+d3+d4)/10)*100),'%'));

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

for b=1:10
    [maxOtr(b) posOtr(b)]=max(outFTrain(:,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(outFTest(:,b));    
end;
flag=ones(1,10);

for x=1:10
if maxO(x)>=thresholdmin1 & maxO(x)<thresholdmax1  
    disp('Fits threshold-F1');
    flag(x)=1;
elseif maxO(x)>=thresholdmin2 & maxO(x)<thresholdmax2
    disp('Fits threshold-F2');
    flag(x)=2;
elseif maxO(x)>=thresholdmin3 & maxO(x)<thresholdmax3
    disp('Fits threshold-F3');
    flag(x)=3;
elseif maxO(x)>=thresholdmin4 & maxO(x)<thresholdmax4
    disp('Fits threshold-F4');
    flag(x)=4;
elseif maxO(x)>=thresholdmin5 & maxO(x)<thresholdmax5
    disp('Fits threshold-F5');
    flag(x)=5;
elseif maxO(x)>=thresholdmin6 & maxO(x)<thresholdmax6
    disp('Fits threshold-F6');
    flag(x)=6;
elseif maxO(x)>=thresholdmin7 & maxO(x)<thresholdmax7
    disp('Fits threshold-F7');
    flag(x)=7;
elseif maxO(x)>=thresholdmin8 & maxO(x)<thresholdmax8
    disp('Fits threshold-F8');
    flag(x)=8;
elseif maxO(x)>=thresholdmin9 & maxO(x)<thresholdmax9
    disp('Fits threshold-F9');
    flag(x)=9;
elseif maxO(x)>=thresholdmin10 & maxO(x)<thresholdmax10
    disp('Fits 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 ch>=1 & ch<=4 
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 ch>=5 & ch<=8 
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 ch>=9 & ch<=12
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 ch>=13 & ch<=16 
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 ch>=17 & ch<=20 
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 ch>=21 & ch<=24 
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: F9- ',num2str(flag(6))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if ch>=25 & ch<=28 
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: F9- ',num2str(flag(7))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if ch>=29 & ch<=32 
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: F9- ',num2str(flag(8))));
else
strg = ['c:\images\id\err.tif'];
Dat1q=imread(strg);
subplot(122);imshow(Dat1q);
end;
end;

if ch>=33 & ch<=36 
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 ch>=37 & ch<=40 
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;

load B TestData;
    
%-----------------show test image---------------------
subplot(121);imshow(TestData{ch});
title(strcat('Test Image- ',num2str(ch)));

save MN;

Contact us