1. 程式人生 > >【讀書1】【2017】MATLAB與深度學習——示例:MNIST(3)

【讀書1】【2017】MATLAB與深度學習——示例:MNIST(3)

程式碼的小批量訓練部分被單獨提取出來並顯示在下面的列表中。

The minibatch portion of the code isextracted and shown in the following listing.

bsize = 100;

blist = 1:bsize:(N-bsize+1);

for batch = 1:length(blist)

   ...

   begin= blist(batch);

   fork = begin:begin+bsize-1

   ...

          dW1= dW1 + delta2_x;

          dW5= dW5 + delta5*y4';

          dWo= dWo + delta *y5';

   end

   dW1= dW1 / bsize;

   dW5= dW5 / bsize;

   dWo= dWo / bsize;

   ...

end

小批量訓練的數目bsize設定為100。

The number of batches, bsize, is set to be100.

由於我們總共有8000個訓練資料點,每一個時代的權重調整需要80(= 8000/100)次。

As we have a total 8,000 training datapoints, the weights are adjusted 80 (=8,000/100) times for every epoch.

小批量處理中的變數blist包含第一個訓練資料點的位置。

The variable blist contains the location ofthe first training data point to be brought into the minibatch.

從第一個訓練資料點的位置開始,在每一次小批量處理中使用100個數據點形成訓練資料。

Starting from this location, the codebrings in 100 data points and forms the training data for the minibatch.

在這個例子中,變數blist儲存為下面的向量:

In this example, the variable blist storesthe following values:

blist= [ 1, 101, 201, 301, …, 7801, 7901 ]

只要通過blist確定出小批量處理的起始位置,那麼就可以每100個數據執行一次權重更新。

Once the starting point, begin, of theminibatch is found via blist, the weight update is calculated for every 100thdata point.

對100個權重更新進行求和並平均,完成權重調整。

The 100 weight updates are summed andaveraged, and the weights are adjusted.

重複該過程80次,則一個時代的運算結束。

Repeating this process 80 times completesone epoch.

另一個值得注意的是,MnistConv函式利用動量來調整權重。

Another noticeable aspect of the functionMnistConv is that it adjusts the weights using momentum.

這裡使用了變數momentum1、momentum5和momentumo。

The variables momentum1, momentum5, andmomentumo are used here.

以下程式碼實現動量更新:

The following part of the code implementsthe momentum update:

momentum1 = alphadW1 + betamomentum1;

W1 = W1 + momentum1;

momentum5 = alphadW5 + betamomentum5;

W5 = W5 + momentum5;

momentumo = alphadWo + betamomentumo;

Wo = Wo + momentumo;

現在我們已經掌握了整個程式碼的設計全貌。

We have now captured the big picture of thecode.

我們來看看程式碼中最重要的部分:學習規則。

Now, let’s look at the learning rule, themost important part of the code.

這個過程本身與以前沒有區別,因為ConvNet也採用反向傳播訓練。

The process itself is not distinct from theprevious ones, as ConvNet also employs back-propagation training.

首先我們要獲得網路的輸出。

The first thing that must be obtained isthe output of the network.

下面的列表顯示函式MnistConv的計算輸出部分。

The following listing shows the outputcalculation portion of the function MnistConv.

這可以從神經網路的體系結構中直觀地理解。

It can be intuitively understood from thearchitecture of the neural network.

——本文譯自Phil Kim所著的《Matlab Deep Learning》

更多精彩文章請關注微訊號:在這裡插入圖片描述