Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Face Recognition Project in MATLAB using Transfer learning (with complete code)

You need to create the database which contains 2 folders (total number of different classes you want to keep in your project , which is in this case 2 , one is my face , another is face of Shahrukh Khan) Code to create database (take image & extract the face part using viola-jones algorithm and resize to 227 *227 , to train alexnet is given in the comment section)


%Train Model:

clc

close all

g=alexnet;

layers=g.Layers;

layers(23)=fullyConnectedLayer(2);

layers(25)=classificationLayer;

allImages=imageDatastore('Dhamna','IncludeSubfolders',true, 'LabelSource','foldernames');

opts=trainingOptions('sgdm','InitialLearnRate',0.001,'MaxEpochs',20,'MiniBatchSize',64);

myNet=trainNetwork(allImages,layers,opts);

save myNet;

 

%Testing Model:

 

clc;close;clear

c=webcam;

load myNet;

faceDetector=vision.CascadeObjectDetector;

while true

    e=c.snapshot;

    bboxes =step(faceDetector,e);

    if(sum(sum(bboxes))~=0)

     es=imcrop(e,bboxes(1,:));

    es=imresize(es,[227 227]);

    label=classify(myNet,es);

    image(e);

    title(char(label));

    drawnow;

    else

        image(e);

        title('No Face Detected');

    end

end

 

 


Join us on Telegram: https://t.me/matlabcastor

No comments

Popular Posts