当前位置:网站首页>Analysis of 43 cases of MATLAB neural network: Chapter 27 prediction of LVQ Neural Network - face orientation recognition
Analysis of 43 cases of MATLAB neural network: Chapter 27 prediction of LVQ Neural Network - face orientation recognition
2022-06-21 17:37:00 【mozun2020】
《MATLAB neural network 43 A case study 》: The first 27 Chapter LVQ Neural network prediction —— Face orientation recognition
1. Preface
《MATLAB neural network 43 A case study 》 yes MATLAB Technology Forum (www.matlabsky.com) planning , Led by teacher wangxiaochuan ,2013 Beijing University of Aeronautics and Astronautics Press MATLAB A book for tools MATLAB Example teaching books , Is in 《MATLAB neural network 30 A case study 》 On the basis of modification 、 Complementary , Adhering to “ Theoretical explanation — case analysis — Application extension ” This feature , Help readers to be more intuitive 、 Learn neural networks vividly .
《MATLAB neural network 43 A case study 》 share 43 Chapter , The content covers common neural networks (BP、RBF、SOM、Hopfield、Elman、LVQ、Kohonen、GRNN、NARX etc. ) And related intelligent algorithms (SVM、 Decision tree 、 Random forests 、 Extreme learning machine, etc ). meanwhile , Some chapters also cover common optimization algorithms ( Genetic algorithm (ga) 、 Ant colony algorithm, etc ) And neural network . Besides ,《MATLAB neural network 43 A case study 》 It also introduces MATLAB R2012b New functions and features of neural network toolbox in , Such as neural network parallel computing 、 Custom neural networks 、 Efficient programming of neural network, etc .
In recent years, with the rise of artificial intelligence research , The related direction of neural network has also ushered in another upsurge of research , Because of its outstanding performance in the field of signal processing , The neural network method is also being applied to various applications in the direction of speech and image , This paper combines the cases in the book , It is simulated and realized , It's a relearning , I hope I can review the old and know the new , Strengthen and improve my understanding and practice of the application of neural network in various fields . I just started this book on catching more fish , Let's start the simulation example , Mainly to introduce the source code application examples in each chapter , This paper is mainly based on MATLAB2015b(32 position ) Platform simulation implementation , This is Chapter 27 of the book LVQ An example of neural network prediction , Don't talk much , Start !
2. MATLAB Simulation example 1
open MATLAB, Click on “ Home page ”, Click on “ open ”, Find the sample file 
Choose chapter27_lvq.m, Click on “ open ”
chapter27_lvq.m Source code is as follows :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : LVQ Neural network prediction —— Face recognition
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LVQ Neural network prediction —— Face recognition
%% Clear environment variables
clear all
clc
tic
%% Face feature vector extraction
% The number of
M = 10;
% Number of face orientation categories
N = 5;
% Feature vector extraction
pixel_value = feature_extraction(M,N);
%% Training set / Test set generation
% Generate a random sequence of image sequence numbers
rand_label = randperm(M*N);
% The face faces toward the label
direction_label = repmat(1:N,1,M);
% Training set
train_label = rand_label(1:30);
P_train = pixel_value(train_label,:)';
Tc_train = direction_label(train_label);
T_train = ind2vec(Tc_train);
% Test set
test_label = rand_label(31:end);
P_test = pixel_value(test_label,:)';
Tc_test = direction_label(test_label);
%% establish LVQ The Internet
for i = 1:5
rate{
i} = length(find(Tc_train == i))/30;
end
net = newlvq(minmax(P_train),20,cell2mat(rate),0.01,'learnlv1');
% Set training parameters
net.trainParam.epochs = 100;
net.trainParam.goal = 0.001;
net.trainParam.lr = 0.1;
%% Training network
net = train(net,P_train,T_train);
%% Face recognition test
T_sim = sim(net,P_test);
Tc_sim = vec2ind(T_sim);
result = [Tc_test;Tc_sim]
%% Results show
% Training set face label
strain_label = sort(train_label);
htrain_label = ceil(strain_label/N);
% Training set face orientation label
dtrain_label = strain_label - floor(strain_label/N)*N;
dtrain_label(dtrain_label == 0) = N;
% Displays the training set image sequence number
disp(' The training set image is :' );
for i = 1:30
str_train = [num2str(htrain_label(i)) '_'...
num2str(dtrain_label(i)) ' '];
fprintf('%s',str_train)
if mod(i,5) == 0
fprintf('\n');
end
end
% Test set face label
stest_label = sort(test_label);
htest_label = ceil(stest_label/N);
% Test set face orientation label
dtest_label = stest_label - floor(stest_label/N)*N;
dtest_label(dtest_label == 0) = N;
% Displays the test set image sequence number
disp(' The test set image is :');
for i = 1:20
str_test = [num2str(htest_label(i)) '_'...
num2str(dtest_label(i)) ' '];
fprintf('%s',str_test)
if mod(i,5) == 0
fprintf('\n');
end
end
% Display recognition error image
error = Tc_sim - Tc_test;
location = {
' left side ' ' Left front ' ' In front of the ' ' Right front ' ' right '};
for i = 1:length(error)
if error(i) ~= 0
% Recognize the face label of the wrong image
herror_label = ceil(test_label(i)/N);
% Identify the face orientation label of the wrong image
derror_label = test_label(i) - floor(test_label(i)/N)*N;
derror_label(derror_label == 0) = N;
% The original orientation of the image
standard = location{
Tc_test(i)};
% The result of image recognition is towards
identify = location{
Tc_sim(i)};
str_err = strcat([' Images ' num2str(herror_label) '_'...
num2str(derror_label) ' Recognition error .']);
disp([str_err '( Correct result : toward ' standard...
'; Recognition result : toward ' identify ')']);
end
end
% Display the recognition rate
disp([' The recognition rate is :' num2str(length(find(error == 0))/20*100) '%']);
toc
Add completed , Click on “ function ”, Start emulating , The output simulation results are as follows :
result =
1 to 19 Column
2 4 3 3 1 1 1 5 2 2 4 2 5 4 1 1 5 3 2
2 4 3 3 4 1 4 5 2 2 4 2 5 4 1 1 5 3 2
20 Column
1
1
The training set image is :
1_5 2_1 2_3 2_5 3_1
3_2 3_3 3_4 3_5 4_1
4_3 4_4 5_2 5_3 5_4
5_5 6_1 6_3 6_5 7_2
7_3 7_4 8_2 8_4 9_2
9_4 9_5 10_3 10_4 10_5
The test set image is :
1_1 1_2 1_3 1_4 2_2
2_4 4_2 4_5 5_1 6_2
6_4 7_1 7_5 8_1 8_3
8_5 9_1 9_3 10_1 10_2
Images 5_1 Recognition error .( Correct result : Towards the left ; Recognition result : Towards the front right )
Images 9_1 Recognition error .( Correct result : Towards the left ; Recognition result : Towards the front right )
The recognition rate is :90%
Time has passed 4.401417 second .

In turn, click Plots Medium Performance,Training State,Confusion,Receiver Operating Characteristic The following graphical results are obtained :



3. MATLAB Simulation example 2
Click... In the current folder view box chapter27_bp.m
open chapter27_bp.m Source code is as follows :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : BP Neural network prediction —— Face recognition
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% BP Neural network prediction —— Face recognition
%% Clear environment variables
clear all
clc
tic
%% Face feature vector extraction
% The number of
M = 10;
% Number of face orientation categories
N = 5;
% Feature vector extraction
pixel_value = feature_extraction(M,N);
%% Training set / Test set generation
% Generate a random sequence of image sequence numbers
rand_label = randperm(M*N);
% The face faces toward the label
direction_label = [1 0 0;1 1 0;0 1 0;0 1 1;0 0 1];
% Training set
train_label = rand_label(1:30);
P_train = pixel_value(train_label,:)';
dtrain_label = train_label - floor(train_label/N)*N;
dtrain_label(dtrain_label == 0) = N;
T_train = direction_label(dtrain_label,:)';
% Test set
test_label = rand_label(31:end);
P_test = pixel_value(test_label,:)';
dtest_label = test_label - floor(test_label/N)*N;
dtest_label(dtest_label == 0) = N;
T_test = direction_label(dtest_label,:)';
%% establish BP The Internet
net = newff(minmax(P_train),[10,3],{
'tansig','purelin'},'trainlm');
% Set training parameters
net.trainParam.epochs = 1000;
net.trainParam.show = 10;
net.trainParam.goal = 1e-3;
net.trainParam.lr = 0.1;
%% Network training
net = train(net,P_train,T_train);
%% The simulation test
T_sim = sim(net,P_test);
for i = 1:3
for j = 1:20
if T_sim(i,j) < 0.5
T_sim(i,j) = 0;
else
T_sim(i,j) = 1;
end
end
end
T_sim
T_test
toc
Click on “ function ”, Start emulating , The output simulation results are as follows :
T_sim =
1 to 19 Column
0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0
1 0 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 0
1 0 0 1 1 0 0 0 0 1 1 0 1 1 0 1 0 1 0
20 Column
1
1
0
T_test =
1 to 19 Column
0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 1
1 0 0 1 0 1 0 1 1 1 0 0 0 1 1 1 1 0 0
1 1 0 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 0
20 Column
1
1
0
Time has passed 3.215773 second .

In turn, click Plots Medium Performance,Training State,Regression The following figure is available :


4. MATLAB Simulation example 3
Click... In the current folder view box chapter_svm.m
open chapter_svm.m Source code is as follows :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : SVM The forecast —— Face recognition
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SVM The forecast —— Face recognition
%% Clear environment variables
clear all
clc
warning off
tic
%% Face feature vector extraction
% The number of
M = 10;
% Number of face orientation categories
N = 5;
% Feature vector extraction
pixel_value = feature_extraction(M,N);
% normalization
pixel_value = premnmx(pixel_value);
%% Training set / Test set generation
% Generate a random sequence of image sequence numbers
rand_label = randperm(M*N);
% The face faces toward the label
direction_label = repmat(1:N,1,M);
% Training set
rand_train = rand_label(1:30);
Train = pixel_value(rand_train,:);
Train_label = direction_label(rand_train)';
% Test set
rand_test = rand_label(31:end);
Test = pixel_value(rand_test,:);
Test_label = direction_label(rand_test)';
% SVM Model
model = svmtrain(Train_label,Train,'-c 2 -g 0.05');
% The simulation test
[predict_label,accuracy] = svmpredict(Test_label,Test,model);
result_svm = [Test_label';predict_label']
toc
Click on “ function ”, Start emulating , The output simulation results are as follows :
Accuracy = 100% (20/20) (classification)
result_svm =
1 to 19 Column
5 2 4 3 5 3 4 4 3 2 4 4 3 5 3 5 1 5 2
5 2 4 3 5 3 4 4 3 2 4 4 3 5 3 5 1 5 2
20 Column
4
4
Time has passed 0.832052 second .
The sample image folder is as follows :
5. Summary
This chapter continues with LVQ Neural network for prediction , Simultaneous adoption BP Neural networks and SVM Contrast , The result is shown in the figure above , You can see the prediction effect LVQ neural network <BP neural network <SVM, Thought of other LVQ Examples of neural networks , You can go back to the previous chapter of this column to learn about . Interested in the content of this chapter or want to fully learn and understand , It is suggested to study the contents of chapter 27 in the book . Some of these knowledge points will be supplemented on the basis of their own understanding in the later stage , Welcome to study and exchange together .
The article in the previous chapter :《MATLAB neural network 43 A case study 》: The first 26 Chapter LVQ Classification of neural networks —— Breast tumor diagnosis
边栏推荐
- 3DE 运动轮廓数据修改
- [MySQL learning notes 15] user management
- Android kotlin class delegation by, by lazy key
- BM22 比较版本号
- Variables and pointers
- Accélérer le déploiement de l'application Native Cloud et compléter l'authentification de compatibilité entre Yanrong yrcloudfile et Tianyi Cloud
- 叩富网开期货账户安全可信吗?
- PTA l3-031 thousand hand Guanyin (30 points)
- fs. Readfile() and fs writeFile()
- Mqtt of NLog custom target
猜你喜欢
随机推荐
JetPack compose 状态提升(二)
室内膨胀型防火涂料根据BS 476-21 耐火标准测定需要符合几项?
Google play 应用签名密钥证书,上传签名证书区别
fs.readFile() 和 fs.writeFile()
一些细节
path.join() 、path.basename() 和 path.extname()
iframe跨域传值
全国行政区划
用Node创建一个服务器
Lagrange interpolation
常见设置模式
node服务器 res.end()中写中文,客户端中乱码问题的解决方法
火山引擎+焱融 YRCloudFile,驱动数据存储新增长
Jetpack Compose 管理状态(一)
[MySQL learning notes 14] DQL statement execution sequence
Volcano engine + Yanrong yrcloudfile, driving new growth of data storage
Kotlin DSL build
泊松抽样与伯努利抽样主要联系与区别
线段树&树状数组模板
Readjustment of move protocol beta to expand the total prize pool






![[MySQL learning notes 17] sorting out common functions](/img/11/cb4ea6750cc6dca5a39a65de443074.png)


