深度学习(3)手写数字识别问题
生活随笔
收集整理的這篇文章主要介紹了
深度学习(3)手写数字识别问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
深度學習(3)手寫數字識別問題
- 1. 問題歸類
- 2. 數據集
- 3. Image
- 4. Input and Output
- 5. Regression VS Classification
- 6. Computation Graph
- 7. 兩個問題
- 8. Particularly
- 9. 如何訓練模型?→\to→ Loss
- 10. 總結
- 11. Deep Learning?
- 12. Classification Procedure
- 13. We need TensorFlow
- 14. Next
1. 問題歸類
Discrete Prediction(離散值的預測)
- y=w?x+by=w*x+by=w?x+b
- [up, left, down, right]
- [dog, cat, whale, bird, …]
手寫數字識別問題屬于離散值的預測。
2. 數據集
- MNIST
- 7000 images per category
- train/test splitting: 60k vs 10k
3. Image
- [28, 28, 1]
圖片是由28行×28列,共784個像素點組成,[0, 255]代表圖片像素的灰度值,其中0代表純白色,255代表純黑色,1代表每個像素點的灰度值,也就是每個像素點只有1個維度,就是其灰度值。 - →\to→ [784]
將28×28的數據變為一維,將第二行的像素點拼接到一行后,后面26行同理,這樣一張圖片就變為了擁有784個元素的一維數據。
4. Input and Output
(1) 輸入
x:[b,784]x:[b,784]x:[b,784]
輸入是[b, 784],b可以理解為共有多少張圖片,784表示每張圖片有784個像素點。
(2) 編碼方式
- dog=0, cat=1, fish=2, …
缺點: 不確定性高,例如要是預測值為1.5,就會產生判斷失誤。 - dog = [1, 0, 0, …],其中“1”表示該預測值為“dog”的概率,“0”表示該預測值為“cat”的概率,…,這些概率和為1。
cat = [0, 1, 0, …]
fish = [0, 0, 1, …]
這種編碼方式被稱為one-hot編碼。
5. Regression VS Classification
(1) 模型
- y=x?x+by=x*x+by=x?x+b
- y∈Rdy∈R^dy∈Rd
(2) 輸出
- out=X@W+bout=X@W+bout=X@W+b
- out:[0.1,0.8,0.02,0.08]out:[0.1,0.8,0.02,0.08]out:[0.1,0.8,0.02,0.08]
(3) 預測
- pred=argmax(out)pred=argmax(out)pred=argmax(out)
- pred:1pred:1pred:1
- label:2label:2label:2
6. Computation Graph
- out=X@W+bout=X@W+bout=X@W+b
- X:[b,784]X:[b,784]X:[b,784]
- W:[784,10]W:[784,10]W:[784,10]
- b:[10]b:[10]b:[10]
7. 兩個問題
(1) It’s Linear!
- out=X@W+bout=X@W+bout=X@W+b
- →\to→
- out=f(X@W+b)out=f(X@W+b)out=f(X@W+b)
- out=relu(X@W+b)out=relu(X@W+b)out=relu(X@W+b)
(2) It’s too simple!
- out=relu(X@W+b)out=relu(X@W+b)out=relu(X@W+b)
- →\to→
- h1=relu(X@W1+b1)h_1=relu(X@W_1+b_1)h1?=relu(X@W1?+b1?)
- h2=relu(h1@W2+b2)h_2=relu(h_1@W_2+b_2)h2?=relu(h1?@W2?+b2?)
- out=relu(h2@W3+b3)out=relu(h_2@W_3+b_3)out=relu(h2?@W3?+b3?)
8. Particularly
(1)X:[v1,v2,…,v784]X:[v_1,v_2,…,v_784]X:[v1?,v2?,…,v7?84]
- X:[1,784]
(2) h1=relu(X@W1+b1)h_1=relu(X@W_1+b_1)h1?=relu(X@W1?+b1?)
- W_1:[784,512]
→[1,784]@[784,512]+[512]=[1,512]+[512]=[1,512]\to [1,784]@[784,512]+[512]=[1,512]+[512]=[1,512]→[1,784]@[784,512]+[512]=[1,512]+[512]=[1,512] - b1:[1,512]b_1:[1,512]b1?:[1,512]
(3) h2=relu(h1@W2+b2)h_2=relu(h_1@W_2+b_2)h2?=relu(h1?@W2?+b2?)
- W_2:[512,256]
→[1,512]@[512,256]+[256]=[1,256]+[256]=[1,256]\to [1,512]@[512,256]+[256]=[1,256]+[256]=[1,256]→[1,512]@[512,256]+[256]=[1,256]+[256]=[1,256] - b2:[1,256]b_2:[1,256]b2?:[1,256]
(4) out=relu(h2@W3+b3)out=relu(h_2@W_3+b_3)out=relu(h2?@W3?+b3?)
- W_3:[256,10]
→[1,256]@[256,10]+[10]=[1,10]+[10]=[1,10]\to [1,256]@[256,10]+[10]=[1,10]+[10]=[1,10]→[1,256]@[256,10]+[10]=[1,10]+[10]=[1,10] - b3:[1,10]b_3:[1,10]b3?:[1,10]
從以上計算過程可以看出,神經網絡其實是一個降維的過程,圖片由原來的[1,784][1,784][1,784]降為[1,512][1,512][1,512],再降為[1,256][1,256][1,256],最后降為[1,10][1,10][1,10]。
→[0,0,0.01,0.1,0.8,0,…]\to [0,0,0.01,0.1,0.8,0,…]→[0,0,0.01,0.1,0.8,0,…]
根據以上輸出可以判斷這張圖片為“5”的概率最大,所以這張圖片的預測值為“5”。
9. 如何訓練模型?→\to→ Loss
- out:[1,10]
→\to→ - Y/label: 0~9
- eg.: 1 →\to→ [0,1,0,0,0,0,0,0,0,0]
- eg.: 3 →\to→ [0,0,0,1,0,0,0,0,0,0]
→\to→
- Euclidean Distance(歐式距離): out→Labelout \to Labelout→Label
- MSE,即∑(y?out)2\sum(y-out)^2∑(y?out)2
10. 總結
- out=relu{relu{relu[X@W1+b1]@W2+b2}@W3+b3}out=relu\{relu\{relu[X@W_1+b_1]@W_2+b_2\}@W_3+b_3\}out=relu{relu{relu[X@W1?+b1?]@W2?+b2?}@W3?+b3?}
- pred=argmax(out)pred=argmax(out)pred=argmax(out)
- loss=MSE(out,label)loss=MSE(out,label)loss=MSE(out,label)
- minimizelossminimize lossminimizeloss
- [W1′,b1′,W2′,b2′,W3′,b3′][W_1',b_1',W_2',b_2',W_3',b_3'][W1′?,b1′?,W2′?,b2′?,W3′?,b3′?]
11. Deep Learning?
- We have not seen it.
- But we already master it.
- We will show you It’s(almost)Deep Learning!
12. Classification Procedure
- Step1. Compute h1,h2,outh_1,h_2,outh1?,h2?,out
- Step2. Compute LossLossLoss
- Step3. Compute gradient and update[W1′,b1′,W2′,b2′,W3′,b3′][W_1',b_1',W_2',b_2',W_3',b_3'][W1′?,b1′?,W2′?,b2′?,W3′?,b3′?]
- Step4. Loop
13. We need TensorFlow
- 數據量龐大;
- TensorFlow計算和處理更快。
14. Next
- Step1. have fun on MNIST classification
- Step2. and we learn TensorFlow
- Step3. and we implement Step1. by ourselves!
參考文獻:
[1] 龍良曲:《深度學習與TensorFlow2入門實戰》
總結
以上是生活随笔為你收集整理的深度学习(3)手写数字识别问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 猜一猜以下哪种动物属于秦岭四宝?蚂蚁庄园
- 下一篇: 美国计划强制电动汽车配备行人警示器,19