mGesture recognition algorithm matlab simulation based on GA-CNN genetic optimization convolutional neural network

Table of contents

1. Algorithm simulation effect

2. Summary of theoretical knowledge involved in algorithms

2.1 Genetic algorithm optimization stage

2.2 Convolutional neural network classification stage

3.MATLAB core program

4. Obtain the complete algorithm code file


1. Algorithm simulation effect

The matlab2022a simulation results are as follows:

CNN training results

CNN training results after GA optimization

The mean convergence process obtained by the GA optimization process

Comparison of recognition rates between CNN and GA optimized CNN

The database used in this project is as follows:

2. Summary of theoretical knowledge involved in algorithms

         The gesture recognition algorithm based on GA-CNN genetically optimized convolutional neural network is a deep learning algorithm that combines genetic algorithm (GA) and convolutional neural network (CNN) for gesture recognition tasks. This algorithm uses a genetic algorithm to optimize the parameters of the convolutional neural network to improve the accuracy and robustness of gesture recognition.

       Gesture recognition refers to identifying human gestures by analyzing gesture images or videos. With the continuous development of deep learning technology, convolutional neural networks have become a mainstream method in the field of gesture recognition. However, traditional convolutional neural network methods usually require a large amount of annotated data for training, and are susceptible to interference from factors such as illumination, angle, and occlusion. In order to solve these problems, researchers have proposed a convolutional neural network optimization method based on genetic algorithms.

        The basic idea of ​​the GA-CNN algorithm is to combine the genetic algorithm with the convolutional neural network, and use the genetic algorithm to search for optimal network parameters to obtain better gesture recognition performance. Specifically, the GA-CNN algorithm includes two stages: genetic algorithm optimization stage and convolutional neural network classification stage.

2.1 Genetic algorithm optimization stage

       Genetic algorithm is an optimization algorithm based on the principle of biological evolution. It searches for the optimal solution by simulating operations such as selection, crossover, and mutation in the process of biological evolution. In the GA-CNN algorithm, the genetic algorithm is used to optimize the parameters of the convolutional neural network, including convolution kernel size, step size, pooling size, etc. The following is the basic formula for genetic algorithm optimization:

(1) Selection operation: Based on the fitness function, individuals with higher fitness are selected to form the next generation population. The fitness function is usually the inverse of the classification accuracy or loss function.

(2) Crossover operation: perform crossover operation on the selected individuals with a certain crossover probability to generate new individuals. Common crossover operations include point crossover, uniform crossover, etc.

(3) Mutation operation: Mutation operation is performed on individuals with a certain mutation probability to introduce new gene combinations. Common mutation operations include random insertion, random deletion, etc.

Through continuous iterative selection, crossover, and mutation operations, the genetic algorithm can gradually search for optimal network parameters.

2.2 Convolutional neural network classification stage

      Convolutional neural network is a deep learning algorithm used for tasks such as image classification and target detection. In the GA-CNN algorithm, a convolutional neural network is used to classify gesture images. The following is the basic formula of a convolutional neural network:

(1) Convolution operation: Convolve the local area of ​​the input image with the convolution kernel through the convolution kernel to obtain the output of the convolution layer. Common convolution operations include fully connected layers, convolutional layers, pooling layers, etc.

(2) ReLU activation function: Increase the nonlinear expression ability of the network through nonlinear activation functions. Commonly used activation functions include ReLU, sigmoid, tanh, etc.

(3) Pooling operation: downsample the output of the convolutional layer through the pooling function to reduce computational complexity. Commonly used pooling functions include maximum pooling, average pooling, etc.

Through multi-layer convolution, activation, and pooling operations, the convolutional neural network can classify gesture images. In the GA-CNN algorithm, we use optimized network parameters for gesture recognition tasks to obtain better classification performance.

       The gesture recognition algorithm based on GA-CNN genetically optimized convolutional neural network is a deep learning algorithm that combines genetic algorithms and convolutional neural networks and is used for gesture recognition tasks. This algorithm uses a genetic algorithm to search for optimal network parameters to obtain better gesture recognition performance. Through continuous iterative selection, crossover, and mutation operations, the genetic algorithm can gradually search for optimal network parameters. In the GA-CNN algorithm, we use optimized network parameters for gesture recognition tasks to obtain better classification performance.

3.MATLAB core program

...............................................................
while gen < MAXGEN
      gen
      Pe0 = 0.999;
      pe1 = 0.001; 

      FitnV=ranking(Objv);    
      Selch=select('sus',Chrom,FitnV);    
      Selch=recombin('xovsp', Selch,Pe0);   
      Selch=mut( Selch,pe1);   
      phen1=bs2rv(Selch,FieldD);   
 
      for a=1:1:NIND  
          X           = phen1(a,:);
          %计算对应的目标值
          [epls]      = func_obj(X);
          E           = epls;
          JJ(a,1)     = E;
      end 
      
      Objvsel=(JJ);    
      [Chrom,Objv]=reins(Chrom,Selch,1,1,Objv,Objvsel);   
      gen=gen+1; 


      Error2(gen) = 100-mean(JJ);
end 
tt=smooth(Error2,MAXGEN);
figure
plot(tt,'linewidth',2);
grid on
xlabel('迭代次数');
ylabel('遗传算法优化过程');
legend('Average fitness');

[V,I] = min(JJ);
X     = phen1(I,:);
Layers = round(X(1));
lr     = X(2);
 
digitDatasetPath = ['images\'];
imds = imageDatastore(digitDatasetPath,'IncludeSubfolders', true, 'LabelSource', 'foldernames');
%划分数据为训练集合验证集,训练集中每个类别包含1张图像,验证集包含其余图像的标签
[imdsTrain, imdsValidation] = splitEachLabel(imds,0.6,'randomized');%
  
if Layers == 2
%定义卷积神经网络的基础结构
layers = [
    imageInputLayer([160 120 1]);%注意,400,150为能量图的大小,不能改
    %第1个卷积层
    convolution2dLayer(4, 15, 'Padding', 'same');%第一个卷积层
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第2个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
 
    %全连接层
    fullyConnectedLayer(5);
    %softmax
    softmaxLayer;
    %输出分类结果
    classificationLayer;];
end

if Layers == 3
%定义卷积神经网络的基础结构
layers = [
    imageInputLayer([160 120 1]);%注意,400,150为能量图的大小,不能改
    %第1个卷积层
    convolution2dLayer(4, 15, 'Padding', 'same');%第一个卷积层
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第2个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第3个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);

    %全连接层
    fullyConnectedLayer(5);
    %softmax
    softmaxLayer;
    %输出分类结果
    classificationLayer;];
end

if Layers == 4
%定义卷积神经网络的基础结构
layers = [
    imageInputLayer([160 120 1]);%注意,400,150为能量图的大小,不能改
    %第1个卷积层
    convolution2dLayer(4, 15, 'Padding', 'same');%第一个卷积层
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第2个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第3个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第4个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);

    %全连接层
    fullyConnectedLayer(5);
    %softmax
    softmaxLayer;
    %输出分类结果
    classificationLayer;];
end


if Layers == 5
%定义卷积神经网络的基础结构
layers = [
    imageInputLayer([160 120 1]);%注意,400,150为能量图的大小,不能改
    %第1个卷积层
    convolution2dLayer(4, 15, 'Padding', 'same');%第一个卷积层
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第2个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第3个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第4个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %第5个卷积层
    convolution2dLayer(4, 15, 'padding', 'same');
    batchNormalizationLayer;
    reluLayer;
    maxPooling2dLayer(2, 'Stride', 2);
    
    %全连接层
    fullyConnectedLayer(5);
    %softmax
    softmaxLayer;
    %输出分类结果
    classificationLayer;];
end
%设置训练参数
options = trainingOptions('sgdm', ...
    'InitialLearnRate', lr, ...
    'MaxEpochs', 1000, ...
    'Shuffle', 'every-epoch', ...
    'ValidationData', imdsValidation, ...
    'ValidationFrequency', 10, ...
    'Verbose', false, ...
    'Plots', 'training-progress');
rng(1)
%使用训练集训练网络
net         = trainNetwork(imdsTrain, layers, options);

%对验证图像进行分类并计算精度
YPred       = classify(net, imdsValidation);
YValidation = imdsValidation.Labels;

accuracy    = 100*sum(YPred == YValidation) / numel(YValidation);
save R2.mat accuracy tt Layers lr
0X_032m

4. Obtain the complete algorithm code file

IN

Guess you like

Origin blog.csdn.net/hlayumi1234567/article/details/134238048
Recommended