当前位置:网站首页>Handwriting recognition in MATLAB deep learning practice (including detailed notes)
Handwriting recognition in MATLAB deep learning practice (including detailed notes)
2022-07-18 07:54:00 【Xuan yanru Liu】
Matlab In recent years, we have done better and better in artificial intelligence , Recently, in order to get familiar with matlab How to build neural networks , I did a handwriting recognition experiment , Make a note of .
The experimental task is very simple , The network is also very casual , Unreasonable places are also lazy to change , Designed to get through matlab The process of building neural network .
First , The data set is MNIST Data sets 
I have sorted the data by category , It is divided into train and test, There are ten subfolders at the bottom to store handwritten images .
The network training code is as follows :
clear;close all;clc;
%% data fetch 、 enhance
% Read training set
path_train = 'D:\work\ Expired files \ Handwriting Recognition \MNIST\train'; % Training set path
folders_train = fullfile(path_train,{
'0' '1' '2' '3' '4' '5' '6' '7' '8' '9'}); % Read subdirectories
imds_train = imageDatastore(folders_train,'FileExtensions','.jpg',...
'LabelSource','foldernames'); % Read all image paths
[imdsTrain,imdsValidation] = splitEachLabel(imds_train,0.9,0.1); % Split the validation set
% Read test set
path_test = 'D:\work\ Expired files \ Handwriting Recognition \MNIST\test';
folders_test = fullfile(path_test,{
'0' '1' '2' '3' '4' '5' '6' '7' '8' '9'});
imds_test = imageDatastore(folders_test,'FileExtensions','.jpg',...
'LabelSource','foldernames');
% Image enhancement
pixelRange = [-2 2]; % Translation range
scaleRange = [0.9 1.1]; % Zoom range
imageAugmenter = imageDataAugmenter( ...
'RandXTranslation',pixelRange, ...
'RandYTranslation',pixelRange, ...
'RandXScale',scaleRange, ...
'RandYScale',scaleRange); % Define image intensifier
augimdsTrain = augmentedImageDatastore([28,28],imds_train, ...
'DataAugmentation',imageAugmenter); % Image enhancement
%% Design ( Or read ) The Internet
layers = [
imageInputLayer([28 28 1],"Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv_1","Padding","same","Stride",[2 2])
reluLayer("Name","relu_1")
batchNormalizationLayer("Name","batchnorm_1")
convolution2dLayer([3 3],32,"Name","conv_2","Padding","same")
reluLayer("Name","relu_2")
fullyConnectedLayer(512,"Name","fc_1")
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_3")
fullyConnectedLayer(10,"Name","fc_2")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
% analyzeNetwork(layers) % Analyze the Internet
%% Training network
options = trainingOptions('sgdm', ...
'MiniBatchSize',512, ...
'MaxEpochs',1, ...
'InitialLearnRate',1e-2, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',1, ...
'Plots','training-progress'); % Set up training strategies
trainedNet = trainNetwork(augimdsTrain,layers,options); % Training
%% test model
[YPred,probs] = classify(trainedNet,imds_test);
accuracy = mean(YPred == imds_test.Labels)
Inside this , Some functions are used , I have written some important usage in other blogs , Here is just a general introduction to what is the use
- fullfile: Read all subfolders under the folder
- imageDatastore: Reading data sets , This function is more important , Many later functions are calling it
- splitEachLabel: Split imageDatastore Read data
- imageDataAugmenter: Image intensifier , Define how to enhance images
- augmentedImageDatastore: Image enhancement
- About How to build a network , I wrote it here , After reading it, I found that there is no need to type a line of code for some simple tasks
- analyzeNetwork: Analyze the Internet
- trainingOptions: Define training strategies , For example, learning rate , Optimizer and so on
- trainNetwork: Training network
- classify: Use the network for classification
Training results :
If you need a processed data set , You can leave the mailbox ~
Listen to comments , Put it directly on the network disk , It should not be swallowed 2333
link :https://pan.baidu.com/s/1htpPayQ2m0B3C5xOk3Quqg
Extraction code :pdb6
Finally, let me explain , The network is built casually , Do not use !! Just learning MATLAB With
These hopes will help you
边栏推荐
- Meituan's one-sided experience and detailed answers
- Pytorch中torch.argmax()函数解析
- MySQL 为什么临时表可以重名 ?
- oracle跨网断转发如何解决?
- Pytorch中torch.unsqueeze()和torch.squeeze()函数解析
- Compétition · 6116 · calcul de la valeur de l'arbre binaire booléen · récursion
- Talk about how to write a programmer's resume (help modify your resume)
- 二路归并排序总结
- Redis 分布式锁:从小白到大神方案都经历了什么?
- Redis+caffeine two-level cache enables smooth access speed
猜你喜欢

概率密度函数中形状参数和尺度参数的区别

2. Trend technology 2017 school recruitment development post test questions

Unity IoTAR物联网增强现实教程

Qiu Zhao took 6 offers and summarized more than 20 categories of 1100 interview questions, including answer analysis

(高频面试题)计算机网络

My first anniversary of creation

Talk about how to write a programmer's resume (help modify your resume)

One question per day · 1252 Number of odd cells · simulation optimization

秋招拿了6offer,总结了20多类1100道面试题含答案解析

一家火锅店,凑了三个IPO
随机推荐
2、趋势科技2017校招开发岗试题
Pytorch中torch.max()函数解析
JVM tuning command encyclopedia and common command tools and practical steps
2022 China mobile maker marathon Internet of things special competition kicks off
蓝领困顿,直播带岗是真伪需求?
浅析与云基础架构相关的风险 及对应防御措施
(shangsilicon Valley) JDBC general review
676. Implement a magic dictionary prefix tree
Matlab:trainingOptions()详解 训练选项
【详细教程】一文参透MongoDB聚合查询
Can you use redis? Then come and learn about redis protocol
Several things I want to understand about being laid off at the age of 30
Pytorch中torch.repeat()函数解析
Qiu Zhao took 6 offers and summarized more than 20 categories of 1100 interview questions, including answer analysis
openpyxl绘制饼图
Matlab:搭建神经网络
Use SSH to pull code
307. Area and retrieval - array modifiable
软件架构与设计(二)-----架构模型
若依框架之定时任务