I am looking for some help on how to code a facial recognition program and make it highly accurate, I have been given a code from a lecture and have been asked to make it more accurate. I have never done any type of coding in python before and have no idea of where to begin. I understand that to make the program more accurate I will need to add hidden nodes within the program but not sure how ??
Below is the code I have been given and I also have 50 images for the program to run.
Any tips or help would be very much appreciated.
function main() % ver /02/19
global dname val_ratio nofpc nofhn nofpix
% Set the path to a folder (eg A1) which contains the face images on your PC
% Settings for experiments:
nofpc=100; % set a number of principal components
nofhn=20; % set a number of hidden neurons for ANN
% Advanced settings:
nofpix=32; % size of face images
val_ratio=0.3; % recommended part of the training set used for validation of ANN
% Steps 1 to 4:
% Step 1: Read image set
% Step 2: Split imsge data set into training and test subsets
% Step 3: Apply PCA to the training and test subsets
% Step 4: Train ANN
fprintf(‘Accuracy of recognition on validation subset %5.3f\n’,vacc)
% Scripts for Steps 1 to 4
function [X,T]=read_image_set() % Step 1
% Np=30 is the number of persons to be recognised by the given images
% Each person is taken 50 times, k=50.
% The images are reshaped to be 32 by 32 pixels.
% The number of images N=Npk=3050=1500.
% There are N jpg images representing the Np persons.
% Each image is vectorised to be a vector including
% L=3232=1024 elements.
% X is the (L by N) matrix of vectorised images of Np persons.
% T is the N-element target vector including the person indexes 1 to Np
% dname is the folder name including all the N images.
% nofpix=30 is the size of images in pixels, It can be reasonably
% changed for improving the recognition accuracy.
global dname nofpix
%imshow(Im) % uncomment if you want to see the image
function [X1,T1,X2,T2]=split_image_set(X,T) % Step 2
% X, T are the input data and labels calculated by the function read_image_set().
% The data X,T are split into training and validation subsets X1,T1 and X2,T2.
% Images in the subsets are randomly assigned accordingly
% to the given val_ratio.
% X1 is the (L by n1) matrix of training set.
% T1 is the n1-element target vector of images in the validation set.
% X2 is the (L by n2) matrix of validation set.
% T2 is the n2-element target vector of images in the validation set.
% val_ratio=0.3. This ratio can be reasonably changed to achieve
% the maximal accuracy of test (unseen) images .
nofim=size(X,2); % nof images
A2=randsample(nofim,nofvalimages); % validation images
I1(A2)=false; % flags for train images
I2=~I1; % flags for validation images
function [PS1,PS2,C,M]=apply_pca(X1,X2) % Step 3
% nofpc is the number of principal components extracted from the
% X1,X2 are the training and validation images prepared
% by the function split_image_set().
% PCA is applied to the set X1 to find the components P1 and matrix of
% coefficients C.
% PS1 is the (nofpc by n1) matrix of components for training set.
% PS2 is the (nofpc by n2) matrix of components for training set.
% nofpc=100 by default can be reasonably changed to improve
% the recognition accuracy
% train set:
% test set:
% get components:
function [Net,vacc]=train_net(X1,X2,T1,T2) % Step 4
% X1,X2 are the training and validation images prepared by the function
% Train an artificial neural network (Net) with the given number (nofhn)
% of hidden neurons and training method (trainscq).
% Validate the accuracy of the trained network (Net) on the validation data X2
% Net is the trained feedforward ANN
% nofhn=20 by default can be reasonably changed to improve
% the recognition accuracy
TV1=full(ind2vec(T1)); % read about the function ind2vec()
Net=train(Net,X1,TV1); % train ANN
vacc=mean(T2==Y2); % accuracy rate [0,1]