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.

traindata_newfinal.m
clear

from=1;
length=4;
rez=100;

% gray-level shift
u=0; % add noise
lowin=0.1; highin=0.9;
lowout=0.1; highout=0.9;

% create target vectors
T1=[0 1 1 0;0 1 1 0;0 1 1 0;0 1 1 0];
T2=[1 1 0 0;1 1 0 0;1 1 0 0;1 1 0 0];
T3=[1 1 1 0;1 1 1 0;1 1 1 0;1 1 1 0];
T4=[0 1 1 1;0 1 1 1;0 1 1 1;0 1 1 1];
T5=[1 0 0 0;1 0 0 0;1 0 0 0;1 0 0 0];
T6=[0 0 0 1;0 0 0 1;0 0 0 1;0 0 0 1];
T7=[1 0 1 0;1 0 1 0;1 0 1 0;1 0 1 0];
T8=[0 1 0 1;0 1 0 1;0 1 0 1;0 1 0 1];
T9=[1 0 0 1;1 0 0 1;1 0 0 1;1 0 0 1];
T10=[0 0 1 1;0 0 1 1;0 0 1 1;0 0 1 1];


% read images
for i = from:length
    data1{i} = imread(['C:\images\f1\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data1(i,:) = temp(:); 
end;

for i = from:length
    data2{i} = imread(['C:\images\f2\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data2(i,:) = temp(:); 
end;

for i = from:length
    data3{i} = imread(['C:\images\f3\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data3(i,:) = temp(:); 
end;

for i = from:length
    data4{i} = imread(['C:\images\f4\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data4(i,:) = temp(:); 
end;

for i = from:length
    data5{i} = imread(['C:\images\f5\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data5(i,:) = temp(:); 
end;

for i = from:length
    data6{i} = imread(['C:\images\f6\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data6(i,:) = temp(:); 
end;

for i = from:length
    data7{i} = imread(['C:\images\f7\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data7(i,:) = temp(:); 
end;

for i = from:length
    data8{i} = imread(['C:\images\f8\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data8(i,:) = temp(:); 
end;

for i = from:length
    data9{i} = imread(['C:\images\f9\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data9(i,:) = temp(:); 
end;

for i = from:length
    data10{i} = imread(['C:\images\f10\' num2str(i) '.tif']);
    %temp = imnoise(temp,'salt & pepper',u);
    %temp = imadjust(temp,[lowin highin],[lowout highout]);
    %temp = imresize(temp, [rez rez]);
    %data10(i,:) = temp(:); 
end;


%-------------------\\\Train training set///----------------
hd=10;
lr=.25;
ep=20;




%load wintface;load zintface;
%W=winit;Z=zinit;

W=zeros(900+1,10);
Z=rand(10+1,4);
winit=W;
zinit=Z;
save wintface winit;
save zintface zinit;
save wq W;
save zq Z;


tic
[W,Z,O1,E1]=msnn1(T1,data1,hd,lr,ep);
[W,Z,O2,E2]=msnn1(T2,data2,hd,lr,ep);
[W,Z,O3,E3]=msnn1(T3,data3,hd,lr,ep);
[W,Z,O4,E4]=msnn1(T4,data4,hd,lr,ep);
[W,Z,O5,E5]=msnn1(T5,data5,hd,lr,ep);
[W,Z,O6,E6]=msnn1(T6,data6,hd,lr,ep);
[W,Z,O7,E7]=msnn1(T7,data7,hd,lr,ep);
[W,Z,O8,E8]=msnn1(T8,data8,hd,lr,ep);
[W,Z,O9,E9]=msnn1(T9,data9,hd,lr,ep);
[W,Z,O10,E10]=msnn1(T10,data10,hd,lr,ep);
toc
timerTrainSet=toc;



out_train1 = O1(1,:);
out_train2 = O2(1,:);
out_train3 = O3(1,:);
out_train4 = O4(1,:);
out_train5 = O5(1,:);
out_train6 = O6(1,:);
out_train7 = O7(1,:);
out_train8 = O8(1,:);
out_train9 = O9(1,:);
out_train10 = O10(1,:);



outTrain = [out_train1;out_train2;out_train3;out_train4;...
            out_train5;out_train6;out_train7;out_train8;...
            out_train9;out_train10];

save M;

% Plot Error Descent
%EgraphTrain = [E1,E2,E3,E4];
%plot(EgraphTrain);
%xlabel('Epochs');
%ylabel('Training Error of Training Set');

Contact us