1.介绍
? ? 数据集为EMNIST上的数据,将其导出后归成26个子文件夹,网络一共9层,利用trainNetwork进行训练,精度在90以上,话不多说,直接上代码。
clc
clear
imds = imageDatastore('D:\python\\matlab实践\\image_data\\Train_png', ... %数据集的路径
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
image_num=length(imds.Files); %获取数据个数
[imdsTrain,imdsTest] = splitEachLabel(imds,0.7,'randomize');
%网络层数
layers = [ ...
imageInputLayer([28 28 ])
convolution2dLayer(3,16)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(3,'Stride',1)
dropoutLayer(0.5)
fullyConnectedLayer(26)
softmaxLayer
classificationLayer];
%优化器设置
options = trainingOptions('sgdm', ...
'MaxEpochs',10,...
'InitialLearnRate',0.001, ...
'Verbose',false, ...
'Plots','training-progress',...
'MiniBatchSize',128, ...
'Shuffle','once');
net = trainNetwork(imdsTrain,layers,options);
%网络的保存
save('net_2.mat','net')
ps:相关数据集正在审核中
|