machine learning(1) Matlab

0.Review On convelutional Neural Network

Convolutional layer(卷积层)
POOLING layer
Input layers of CNNS:RGB bands
Fully connected layer

1.begin with accessing the data

Create Simple Deep Learning Network for Classification
Load and Explore Image Data
to read original binary file,insert code listed:

digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
    'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
    'IncludeSubfolders',true,'LabelSource','foldernames');

Display some of the images in the datastore.
insert code listed:

figure;
perm = randperm(10000,20);
for i = 1:20
    subplot(4,5,i);
    imshow(imds.Files{perm(i)});
end

then,the figure pop out automatically:

在这里插入图片描述
fx of matlab:count each label

labelCount = countEachLabel(imds)

``

/*the comeout: labelCount =

 10×2 table

Label    Count
_____    _____

  0      1000 
  1      1000 
  2      1000 
  3      1000 
  4      1000 
  5      1000 
  6      1000 
  7      1000 
  8      1000 
  9      1000 

*/
``

fx of matlab:readimage//Read specified image from datastore

insert:

img = readimage(imds,1);
size(img)

2.Specify Training and Validation Sets

matlab function:split each label

(some notes:when I first insert this command,I try again and again and found that I used the word “spilt"but not"split”)

numTrainFiles = 750;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');

3.Define Network Architecture

fx of matlab:batchNormalizationLayer//归一化,正则化
Normalize the activations of the previous layer at each batch

fx of matlab:reluLayer

//A ReLU layer performs a threshold operation to each element of the input, where any value less than zero is set to zero.

//This operation is equivalent to

//f(x)={x(x>0);0(x<0)}
//syntax:
layer = reluLayer
layer = reluLayer('Name',Name)

so this part of code define the who architecture of a CNN from every aspect
the code is below. As far as I’m concerned,It’s really like the structure of C. And think from logically, it defined every Layer one by one. and then Normalization ,then rectified it.

 layers=[
imageInputLayer([28,28,1])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer

maxPooling2dLayer(2,'Stride',2)

convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer

fullyConnectedLayer(10)
softmaxLayer
classificationLayer];

4. Specify Training Options

some clarifications from my own words:
Train the network using stochastic gradient descent with momentum (SGDM) with an initial learning rate of 0.01. Set the maximum number of epochs to 4.

Talk about Gradent descent:

Gradient Descent For Machine Learning by Jason
Optimization is a big part of machine learning. Almost every machine
learning algorithm has an optimization algorithm at it’s core.

What is gradient descent? How can gradient descent be used in
algorithms like linear regression? How can gradient descent scale to
very large datasets? What are some tips for getting the most from
gradient descent? Discover how machine learning algorithms work
including kNN, decision trees, naive bayes, SVM, ensembles and much
more in my new book, with 22 tutorials and examples in excel.

Let’s get started.
Gradient Descent Gradient descent is an optimization algorithm used to
find the values of parameters (coefficients) of a function (f) that
minimizes a cost function (cost).

Gradient descent is best used when the parameters cannot be calculated
analytically
and must be searched for by an optimization algorithm.

epoch: which is a full training cycle on the entire training data set process. This part of code do: Monitor the network accuracy during training by specifying validation data and validation frequency. Shuffle the data every epoch. Finally, we Turn on the training progress plot, and turn off the command window output. so the code is listed below:

options = trainingOptions('sgdm',...
'InitialLearnRate',0.01,...
'MaxEpochs',4,...
'Shuffle','every-epoch',...
'ValidationData',imdsValidation,...
'ValidationFrequency',30,...
'Verbose',false,...
'Plots','training-progress');

5.Train Network Using Training Data

net = trainNetwork(imdsTrain,layers,options);

then,the training process begin

so在这里插入图片描述
So,till now the whole oroject is finished. It’s just a trying, and even not used to test whether it works in reality. But this orocess really help me to review the CNN I learned before.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值