這是MATLAB關(guān)于Deep Learning 的一個(gè)入門的簡(jiǎn)單的例程
Step1
加載并查看數(shù)據(jù)
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
digitData = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
然后隨機(jī)顯示其中的一部分如下
figure;
perm = randperm(10000,20);
for i = 1:20
subplot(4,5,i);
imshow(digitData.Files{perm(i)});
end

Step2.
查看每個(gè)標(biāo)簽的數(shù)量
CountLabel = digitData.countEachLabel;
查看每個(gè)圖片的尺寸大小
img = readimage(digitData,1);
size(img)
ans =
28 28
把數(shù)據(jù)集分為 訓(xùn)練數(shù)據(jù)集 和 測(cè)試數(shù)據(jù)集
trainingNumFiles = 750;
rng(1) % For reproducibility
[trainDigitData,testDigitData] = splitEachLabel(digitData, ...
trainingNumFiles,'randomize');
Step3.
定義神經(jīng)層,定義卷積網(wǎng)絡(luò)的結(jié)構(gòu)
layers = [imageInputLayer([28 28 1])
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer()];
Image Input Layer :圖像輸入層,就是圖像的尺寸,長(zhǎng)寬通道數(shù),因?yàn)槭呛诎讏D像,通道數(shù)為1,如果為彩色的話,就是3
Convolutional Layer :卷積層,第一個(gè)參數(shù)是濾波器的尺寸,代表5*5,第二個(gè)參數(shù)是濾波器的個(gè)數(shù)
ReLU Layer:激活函數(shù)的個(gè)數(shù)
Max-Pooling Layer:最大池化層
Fully Connected Layer :全連接層,和待輸出的標(biāo)簽個(gè)數(shù)一致
Softmax Layer:激活函數(shù)或者分類函數(shù)
Classification Layer:分類函數(shù)
Step4.
指定訓(xùn)練參數(shù)
options = trainingOptions('sgdm','MaxEpochs',15, ...
'InitialLearnRate',0.0001);
訓(xùn)練數(shù)據(jù)
convnet = trainNetwork(trainDigitData,layers,options);
訓(xùn)練結(jié)果如下

Step5.
分類測(cè)試數(shù)據(jù)集
YTest = classify(convnet,testDigitData);
TTest = testDigitData.Labels;
計(jì)算準(zhǔn)確率
accuracy = sum(YTest == TTest)/numel(TTest);

總結(jié):
學(xué)習(xí)了幾個(gè)通用函數(shù)的使用方式
fullfile,用來(lái)構(gòu)造文件路徑
randperm,取隨機(jī)整數(shù)
rng,初始化隨機(jī)數(shù)種子關(guān)于深度學(xué)習(xí)用到的幾個(gè)函數(shù)
imageDatastore,組建圖像處理數(shù)據(jù)集
splitEachLabel,標(biāo)簽分類
CNN卷積的一些設(shè)置函數(shù):
imageInputLayer
convolution2dLayer
reluLayer
maxPooling2dLayer
fullyConnectedLayer
softmaxLayer
classificationLayer
trainingOptions
trainNetwork,訓(xùn)練神經(jīng)網(wǎng)絡(luò)
classify,對(duì)訓(xùn)練好的神經(jīng)網(wǎng)絡(luò)應(yīng)用用于分類