資源簡介
MATLAB代碼,里面包括代碼運行的相關變量以及提供了下載數據的鏈接,可以通過代碼直接下載數據,方便閱讀。

代碼片段和文件信息
%%?Deep?learning?for?classification?on?the?MNIST?dataset
%?Copyright?2018?The?MathWorks?Inc.
%%?Prepare?the?dataset
%準備數據集
%?The?MNIST?dataset?is?a?set?of?handwritten?digits?categorized?0-9?and?is
%?available?at?http://yann.lecun.com/exdb/mnist/.
%MNIST數據集是一組手寫數字,分類為0-9,可以在http://yann.lecun.com/exdb/mnist/上找到。
%?The?following?line?will?download?(if?necessary)?and?prepare?the?dataset
%?to?use?in?MATLAB.
%如有必要,下面的代碼行將下載并準備好在MATLAB中使用的數據集。
[imgDataTrain?labelsTrain?imgDataTest?labelsTest]?=?prepareData;
%%?Let‘s?look?at?a?few?of?the?images
%讓我們看一些圖片
%?Randomize?the?images?for?display
%隨機顯示圖像
warning?off?images:imshow:magnificationMustBeFitForDockedFigure
perm?=?randperm(numel(labelsTrain)?25);
subset?=?imgDataTrain(::1perm);
montage(subset)
%%?How?do?we?classify?a?digit?
%我們如何對數字進行分類?
%?First?we?need?a?model?-?let‘s?load?one
load?MNISTModel
%?Predict?the?class?of?an?image
%預測圖像的類別
randIndx?=?randi(numel(labelsTest));
img?=?imgDataTest(::1randIndx);
actualLabel?=?labelsTest(randIndx);
predictedLabel?=?net.classify(img);
imshow(img);
title([‘Predicted:?‘?char(predictedLabel)?‘?Actual:?‘?char(actualLabel)])
%%?Need?a?starting?point??Check?the?documentation!
%需要一個起點?檢查文檔!
%?search?“deep?learning“
%搜索“深度學習”
web(fullfile(docroot?‘nnet/deep-learning-training-from-scratch.html‘))
%%?Prepare?the?CNN
%?One?of?the?simplest?possible?convnets?it?contains?one?convolutional
%?layer?one?ReLU?one?pooling?layer?and?one?fully?connected?layer
%一個最簡單的卷積網絡,它包含一個卷積層,一個ReLU,一個池化層,和一個完全連接的層
layers?=?[??imageInputlayer([28?28?1])
????????????convolution2dlayer(520)
????????????relulayer
????????????maxPooling2dlayer(2?‘Stride‘?2)
????????????fullyConnectedlayer(10)
????????????softmaxlayer
????????????classificationlayer()???]
????????
%%?Attempt?1:?Set?training?options?and?train?the?network
%%嘗試1:設置訓練選項并訓練網絡
????
????miniBatchSize?=?8192;
????options?=?trainingOptions(?‘sgdm‘...
????????‘MiniBatchSize‘?miniBatchSize...
????????‘Plots‘?‘training-progress‘);
????net?=?trainNetwork(imgDataTrain?labelsTrain?layers?options);
????
%%?Attempt?2:?Change?the?learning?rate
%嘗試2:改變學習速度
????options?=?trainingOptions(?‘sgdm‘...
????????‘MiniBatchSize‘?miniBatchSize...
????????‘Plots‘?‘training-progress‘...
????????‘InitialLearnRate‘?0.0001);
????net?=?trainNetwork(imgDataTrain?labelsTrain?layers?options);
%%?Attempt?3:?Change?the?network?architecture
%嘗試3:更改網絡架構
layers?=?[
????imageInputlayer([28?28?1])
????convolution2dlayer(316‘Padding‘1)
????batchNormalizationlayer
????relulayer
????maxPooling2dlayer(2‘Stride‘2)
????convolution2dlayer(332‘Padding‘1)
????batchNormalizationlayer
????relulayer
????maxPooling2dlayer(2‘Stride‘2)
????convolution2dlayer(364‘Padding‘1)
????batchNormalizationlayer
????relulayer
????fullyConnectedlayer(10)
????softmaxlayer
????classificationlayer];
????options?=?trainingOptions(?‘sgdm‘
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????505??2018-05-02?10:43??Demo1_MNIST\letterW.png
?????文件?????211842??2018-05-02?10:43??Demo1_MNIST\MNISTModel.mat
?????文件???????3727??2019-04-24?11:25??Demo1_MNIST\MNIST_Classification_Demo.m
?????文件?????828512??2018-05-02?10:43??Demo1_MNIST\MNIST_Classification_Demo_Live.html
?????文件?????503833??2018-05-02?10:43??Demo1_MNIST\MNIST_Classification_Demo_Live.mlx
?????文件???????3508??2019-04-24?10:20??Demo1_MNIST\prepareData.m
?????目錄??????????0??2019-04-25?11:14??Demo1_MNIST
-----------?---------??----------?-----??----
??????????????1551927????????????????????7
- 上一篇:心電信號處理方法
- 下一篇:hsv空間雙邊濾波去霧MATLAB代碼
評論
共有 條評論