【人脸识别】基于GoogleNet深度学习网络的人脸识别matlab仿真

1.软件版本

matlab2021a

2.系统概述

GoogLeNet是2014年Christian Szegedy提出的一种全新的深度学习结构,在这之前的AlexNet、VGG等结构都是通过增大网络的深度(层数)来获得更好的训练效果,但层数的增加会带来很多负作用,比如overfit、梯度消失、梯度爆炸等。inception的提出则从另一种角度来提升训练结果:能更高效的利用计算资源,在相同的计算量下能提取到更多的特征,从而提升训练结果。

3.部分程序


clc;
clear;
close all;
warning off;
addpath(genpath(pwd));


% Create & label Dataset
Dataset = imageDatastore('Dataset', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');

% Define Training & Validation Dataset
Training_Dataset=Dataset;
Validation_Dataset=Dataset;


%#------2.  Load Network------#%

% Set Network
net = googlenet;
analyzeNetwork(net)

% Store Input size of layer 1
Input_Layer_Size = net.Layers(1).InputSize;

% Store whole architecture of network(Googlenet)
Layer_Graph = layerGraph(net);



%#------3.  Modify Required Layers ------#%

% Store layer 142 & 144
Feature_Learner = net.Layers(142);
Output_Classifier = net.Layers(144);

% Store number of classes in Dataset
Number_of_Classes = numel(categories(Training_Dataset.Labels));

% Create new fullyConnectedLayer(142) & classificationLayer(144)
New_Feature_Learner = fullyConnectedLayer(Number_of_Classes, ...
    'Name', 'Facial Feature Learner', ...
    'WeightLearnRateFactor', 10, ...
    'BiasLearnRateFactor', 10);
New_Classifier_Layer = classificationLayer('Name', 'Face Classifier');

% Replace layer 142 & 144
Layer_Graph = replaceLayer(Layer_Graph, Feature_Learner.Name, New_Feature_Learner);
Layer_Graph = replaceLayer(Layer_Graph, Output_Classifier.Name, New_Classifier_Layer);
analyzeNetwork(Layer_Graph)



%#------4.  Modify Images ------#%

% Define range of modification
Pixel_Range = [-30 30];
Scale_Range = [0.9 1.1];

% Now modify images
Image_Augmenter = imageDataAugmenter(...
    'RandXReflection', true, ...
    'RandXTranslation', Pixel_Range, ...
    'RandYTranslation', Pixel_Range,... 
     'RandXScale', Scale_Range, ...
     'RandYScale', Scale_Range);

 % Resize image for layer 1 of Googlenet
Augmented_Training_Image = augmentedImageDatastore(Input_Layer_Size(1:2), Training_Dataset, ...
    'DataAugmentation', Image_Augmenter);

Augmented_Validation_Image = augmentedImageDatastore(Input_Layer_Size(1:2),Validation_Dataset);



%#------5.  Train Network ------#%

% Specify training Option
Size_of_Minibatch = 5;
Validation_Frequency = floor(numel(Augmented_Training_Image.Files)/Size_of_Minibatch);
Training_Options = trainingOptions('sgdm',...
    'MiniBatchSize', Size_of_Minibatch, ...
    'MaxEpochs', 10,...
    'InitialLearnRate', 3e-4,...
    'Shuffle', 'every-epoch', ...
    'ValidationData', Augmented_Validation_Image, ...
    'ValidationFrequency', Validation_Frequency, ...
    'Verbose', false, ...
    'Plots', 'training-progress');

% Start training
net = trainNetwork(Augmented_Training_Image, Layer_Graph, Training_Options);


save nets.mat net

4.仿真结论

 

 

5.参考文献

[1]郑弘晖. 基于深度学习的图像分类和人脸识别算法研究[D]. 北京邮电大学, 2018.

猜你喜欢

转载自blog.csdn.net/ccsss22/article/details/125401897