Matlab simulation of face recognition algorithm based on Alexnet deep learning network

Table of contents

1. Overview of algorithm theory

I. Introduction

2. Alexnet deep learning network

3. Face recognition algorithm based on Alexnet

2. Some core programs

3. Algorithm running software version

4. Algorithm operation rendering preview

5. Algorithm complete program engineering


1. Overview of algorithm theory

I. Introduction

        Face recognition is an important task in the field of computer vision, which can automatically identify and verify human facial features. In recent years, with the rise of deep learning, face recognition algorithms based on deep learning have also been widely used. This article will introduce the face recognition algorithm based on the Alexnet deep learning network, including detailed implementation steps and mathematical formulas.

2. Alexnet deep learning network

        Alexnet is a deep neural network model proposed by Alex Krizhevsky et al. in 2012. It is the first deep learning network model successfully applied to large-scale image recognition tasks. Its main structure includes convolutional layers, pooling layers, fully connected layers, and softmax layers. In face recognition tasks, the Alexnet network model is usually used for feature extraction and classification.

Convolutional layer
The convolutional layer is one of the core layers in the Alexnet network model, which can perform convolution operations on the input image and extract the features of the image. The mathematical formula of the convolutional layer is:

$$h_{i,j}^{(l)}=\sigma(\sum\limits_{m=1}^{M}\sum\limits_{p=1}^{P}\sum\limits_{q=1}^{Q}w_{m,p,q}^{(l)}h_{(i+p-1)(j+q-1)}^{(l-1)}+b_m^{(l)})$$

Among them, $h_{i,j}^{(l)}$ represents the feature map of $l$th layer, $i$ row, $j$ column, $w_{m,p,q}^{(l) }$ represents the weight of the $p$th row $q$column of the $l$th $m$ convolution kernel, $h_{(i+p-1)(j+q-1)}^{ (l-1)}$ represents the feature map of the $(i+p-1)$ row $(j+q-1)$ column of the $l-1$ layer, and $b_m^{(l)}$ represents The bias item of the $m$th convolution kernel of the $l$th layer, $\sigma(\cdot)$ represents the activation function, $M$ represents the number of convolution kernels, $P$ and $Q$ represent convolution The size of the nucleus.

Pooling layer
The pooling layer is another core layer in the Alexnet network model, which can down-sample the feature map output by the convolutional layer, reducing the dimension and calculation of the feature map. Commonly used pooling methods include maximum pooling and average pooling. Their mathematical formulas are:

$$h_{i,j}^{(l)}=\max\limits_{p=1}^{P}\max\limits_{q=1}^{Q}h_{(i-1)P+p,(j-1)Q+q}^{(l-1)}$$

$$h_{i,j}^{(l)}=\frac{1}{PQ}\sum\limits_{p=1}^{P}\sum\limits_{q=1}^{Q}h_{(i-1)P+p,(j-1)Q+q}^{(l-1)}$$

Among them, $h_{i,j}^{(l)}$ represents the pooling result of the $l$th row $i$ column $j$, and $P$ and $Q$ represent the pooling window size .

Fully connected layer and softmax layer The
       fully connected layer is a connection method in the Alexnet network model, which can connect the output of the convolution and pooling layers into a vector for feature extraction of classification tasks. The softmax layer is the last layer of the fully connected layer, which is used to map feature vectors into category probability distributions. The mathematical formulas of the fully connected layer and the softmax layer are:

$$z_j^{(l)}=\sum\limits_{i=1}^{n}w_{i,j}^{(l)}h_i^{(l-1)}+b_j^{(l)}$$

$$h_j^{(l)}=\sigma(z_j^{(l)})$$

$$y_k=\frac{\exp(z_k^{(L)})}{\sum\limits_{j=1}^{K}\exp(z_j^{(L)})}$$

Among them, $z_j^{(l)}$ represents the weighted input of the $j$th neuron in the $l$th layer, and $w_{i,j}^{(l)}$ represents the $l$th layer $ The connection weight between the i$ neuron and the $j$ neuron, $h_i^{(l-1)}$ represents the output of the $l-1th layer $i$ neuron, $b_j ^{(l)}$ represents the bias item of the $j$th neuron in the $l$th layer, $y_k$ represents the probability of being predicted as the $k$th category, and $K$ represents the number of all categories.

3. Face recognition algorithm based on Alexnet

       The face recognition algorithm based on Alexnet mainly includes the following steps: data preprocessing, feature extraction, feature matching and classification.

Data preprocessing
Data preprocessing is a very important step in the face recognition algorithm. It can normalize, crop and enhance the input face image to improve the accuracy and robustness of recognition. Common data preprocessing methods include:

(1) Normalization: Normalize the pixel values ​​of the input face image so that each pixel value is between 0 and 1.

(2) Crop: Crop the face image from the original image to remove the background and other interference factors.

(3) Enhancement: Enhance the face image, such as brightness adjustment, contrast enhancement, image rotation, etc., to improve the quality and recognizability of the image.

Feature extraction
Feature extraction is the most critical step in the face recognition algorithm. It can convert the input face image into a high-dimensional feature vector for subsequent classification and matching. Face recognition algorithms based on Alexnet usually use convolutional layers and fully connected layers to extract features. The specific steps are as follows:

(1) Input a face image and process it through multiple convolutional and pooling layers to extract high-dimensional feature maps.

(2) Expand the feature map into a one-dimensional vector as the input of the fully connected layer.

(3) After multiple fully connected layers, a high-dimensional feature vector is obtained for face classification and matching.

Feature matching
Feature matching is another important step in the face recognition algorithm, which can compare and match the input face feature vectors to find the most similar faces. Commonly used feature matching methods include Euclidean distance, cosine similarity, etc., where the mathematical formula of Euclidean distance is:

$$d=\sqrt{\sum\limits_{i=1}^{n}(x_i-y_i)^2}$$

Among them, $d$ represents the Euclidean distance between the feature vectors, and $x_i$ and $y_i$ represent the $i$th elements of the two feature vectors, respectively.

Classification
Classification is the last step in the face recognition algorithm, which can classify the input face images into different categories, such as person's name, gender, age, etc.

       The face recognition algorithm based on Alexnet deep learning network is an efficient, accurate and robust face recognition method, which has been widely used in the fields of face recognition and face verification. The algorithm achieves efficient and accurate face recognition tasks by extracting and classifying the features of the input face images. In the future, with the continuous development and improvement of deep learning technology, the face recognition algorithm based on Alexnet will be more widely used and developed.

2. Some core programs

clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
rng('default')
%MATLAB/verilog/python/opencv/tensorflow/caffe/C/C++等算法仿真
%微信公众号:matlabworld
% 加载已经训练好的深度学习模型
load('mynet.mat');

 
% 处理匹配图像
file_path1 =  'Test\match\';% 图像文件夹路径  
img_path_list = dir(strcat(file_path1,'*.jpg'));
figure;
idx=0;
for i = 1:16
    idx  = idx+1;
    I    = imread([file_path1,img_path_list(i).name]);
    img  = (I);
    img1 = img(:,1:113,:);
    img1 = imresize(img1, [227 227]);
    img2 = img(:,115:end,:);
    img2 = imresize(img2, [227 227]);
 
    % 对左右两部分图像分别进行分类
    result1 = classify(classifier,img1);
    result2 = classify(classifier,img2);
     % 判断两部分图像是否属于同一个人
    if result1 == result2
        T = '同一个人';
    else
        T = '不同人员';
    end
    subplot(4,4,idx)
    imshow(img)
    title(T);
end


% 处理不匹配图像
file_path1 =  'Test\non-match\';% 图像文件夹路径  % 不匹配图像文件夹路径
img_path_list = dir(strcat(file_path1,'*.jpg'));
figure;
idx=0;
for i = 1:16
    idx  = idx+1;
    I    = imread([file_path1,img_path_list(i).name]);
    img  = (I);
    img1 = img(:,1:113,:);
    img1 = imresize(img1, [227 227]);
    img2 = img(:,115:end,:);
    img2 = imresize(img2, [227 227]);

    % 对左右两部分图像分别进行分类
    result1 = classify(classifier,img1);
    result2 = classify(classifier,img2);
    % 判断两部分图像是否属于同一个人
    if result1 == result2
        T = '同一个人';
    else
        T = '不同人员';
    end
    subplot(4,4,idx)
    imshow(img)
    title(T);
end
 0020

3. Algorithm running software version

matlab2022a

4. Algorithm operation rendering preview

 

5. Algorithm complete program engineering

OOOOO

OOO

O

Guess you like

Origin blog.csdn.net/aycd1234/article/details/131646290