HaoYu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 視訊串流與追蹤筆記整理 ## 什麼是機器學習 機器學習就是讓機器能自動找到一個function 主要分成幾大類 * 回歸(Regression) 輸出是一個連續的數值,比如PM2.5數值預測。 * 分類(Classification) 輸出是一個離散的值。 * Binary Classification 輸出 0或、Yes或No * Multi-Category Classification 輸出[1,2,3,…,N],比如圖像分類里判斷一張圖片是貓還是狗還是其他動物等 * 生成(Generation) 指讓機器學習如何創造/生成,產生有結構的複雜東西,比如生成翻譯、圖片等。 ## 該如何提供機器學習的資料 通常在數據集當中存在特徵與標籤(label),透過使用 Loss function 判斷現在找到的函數好壞,Loss越小,函數越好。 以 AlpahGo 為例子解說 * Supervised Learning 我們需要為機器提供的數據就類似棋譜(如果現在棋局長這樣,那下一步我們該怎麽落棋最好) * Reinforcement Learning 讓機器跟自己、別人下棋,把下棋之結果作為Reward,引導機器學習該怎麼下棋。 * 無監督學習(Unsupervised Learning) 只提供數據特徵,但不提供標籤。 ## 如何選擇訓練模型 模型越複雜,在訓練集上的誤差越小,但在測試集上的誤差不一定越小。 因為當模型過於複雜時,越容易被數據影響,可能導致overfitting 的現象。 誤差主要又可分成兩大類 * Bias: 使用相同模型在不同數據上所得到的函數是不同的,取這些函數的期望值與實際真實的函數的差距就稱為​ Bias * Variance: 使用相同模型在不同數據上所得到的函數不會是相同的,而函數之間的離散程度就稱為 Variance ### Bias V.S Variance 越簡單的 Model , Bias 越大 Variance 越小 越難的 Model , Bias 越小 Variance 越大 Error 可來自 Bias 或 Variance * 若 Error 主要來自 Bias 則稱為 underfitting * 需要設計更複雜的模型 * 在 input 中增加可能會造成影響的 feature * 增加訓練的疊代次數 * 調整超參數 ( 修改模型架構 ) * 如果有使用正規化 ( Regularization ) 可先將其移除 * 若 Error 主要來自 Variance 則稱為 overfitting * 增加資料量 * 如果沒有使用正規化 ( Regularization ) 可以將其加入 * Early Stopping * 降低特徵維度 * 調整超參數 ( 修改模型架構 ) * 更換一個較為簡單的模型​ ### 交叉驗證(Cross Validation) 在機器學習中,通常不能將全部的數據用於訓練模型,否則我們將沒有數據集可以用來評估模型的正確率。 **The Validation Set Approach:** 將數據集劃分成 Training Set 以及 Validation Set,只用部分的數據訓練模型,剩餘的用來檢驗模型正確性。缺點是依賴於訓練集和測試集的劃分方法。 ## Gradient Descent Gradient Descent 可以降低 loss function 的值,loss function 越小,通常也代表更好的模型。 假設現在的模型 f 中只有一個參數 w ,則 Loss function 為 L(f)=L(w),梯度下降算法如下(若模型有多個參數,按照相同的方法更新各參數即可) * Step1 :初始化參數 * 選取初始值 $w^0$($w^0$並不一定是隨機選取),令 $w=w^0$。 * Step2 :計算梯度 * 令 $\frac{dL(f)}{dw}|_{w=w0}$ ,也就是圖形在 $w^0$ 上的點對 $w$ 做微分,判斷接下來參數該移動的方向,如果模型有多個參數,則計算Loss functuon 在各個參數方向上的偏微分 * Step3 : 更新模型參數 * $w^1=w^0 - \eta\frac{dL(f)}{dw}|_{w=w0}$ , $\eta$ 為 Learning Rate w 的變化量取決於梯度和學習率(Learning Rate)的大小:梯度絕對值或學習率越大,則 w 變化量越大,接著反覆迭代 Step2 與 Step3 可以使 Loss function 的值達到局部最小值。 如果模型有多個參數,用 Step2 計算出的各項偏微分更新對應之參數,並且反覆迭代 Step2 與 Step3。 優點: * 1. 梯度是在全部的數據上計算出來的,因此每次迭代都是朝著整體的最優化方向進行更新。 缺點: * 1. 每更新一次參數,就要遍歷全部數據集,計算起來非常慢。 * 2. 容易陷入局部極小值點,因為在極小值點(鞍點)梯度為0,所以參數不會更新。 ### Stochastic Gradient Descent 普通梯度下降中(BGD)需要計算所有樣本的Loss值再進行梯度下降,而 SGD 隨機選擇計算一個樣本的 Loss 值,就進行梯度下降 優點: * 1. 與 BGD 相比,更新參數速度較快。 * 2. 與 BGD 相比,SGD可能會跳出局部極小值點,因為在極小值(鞍點)的時候它計算梯度是隨機選擇的一個樣本,這個梯度未必是0。 缺點: * 1. SGD 每次的更新並不是向著整體最優化方向,速度快,但準確度可能下降,找的並非全局最優解。 ### Mini-Batch Gradient Descent MBGD每次使用一部份的數據更新,是 BGD 和 SGD 的一個折衷。 缺點: * 1. 不能保證很好的收斂性,依賴學習率。如果學習率太小,收斂慢,如果太大就會在極小值附近震蕩。 * 2. 要如何選擇 batch-size 的大小仍是個不好判斷的議題 ### Adaptive Learning Rate 梯度下降的過程中,學習率如果一直是個定值其實不合理,我們應該在初始時學習率較大,找到局部極值時再縮小學習率 比如: $\eta^t=\frac{\eta}{\sqrt{t+1}}$ 但更好的方法其實是讓每個參數擁有各自的學習率,比如 Adagrad ## 分類問題 假設有兩個不同的類別 A 和 B ,要判斷 input 屬於哪種類別,可以將此分類問題看成計算 input 屬於該類別的機率,因此我們將分類問題看成了機率計算的問題。 給定一隻烏龜找他的屬性分類,我們在水系的神奇寶貝訓練集分佈中雖然找不到烏龜的這個點,但這不代表水系中沒有這隻烏龜。 下圖中的藍色點代表訓練集,但訓練集並不代表整體的水系神奇寶貝,因為水系神奇寶貝可能有好幾千隻,但我們的資料只有部份神奇寶貝。 我們假定我們的樣本屬於常態分佈(Gaussian distribution),因此要計算烏龜屬於水系的常態分佈的機率是否高於其他系的機率,是的話則將其歸類在水系。 ![](https://i.imgur.com/doOphQe.png) 常態分佈的公式又可被2個參數影響,分別是 Mean(常態分布的中心位置)和 Covariance Matrix(常態分布的離散程度) 我們試圖特定之 Mean 以及 Covariance Matrix 使訓練集特徵機率達到最大的常態分佈(Maximum likelihood) 每個類別的特徵符合一個常態分布,每個常態分布也有不同的Mean 和 Covariance Matrix,通常我們會讓每個類別對應的常態分布共享一個 Covariance Matrix(由各別 Covariance Matrix 對樣本數做加權平均和),這樣可以有效減少模型的參數,緩解 overfitting 的現象。 使用常態分佈以及共用 Covariance Matrix 可以得到一個結論 $P(C1|x)=\sigma(z)=\frac{1}{1+e^{-z}}$ , sigmoid function $z=\sum^N_{i=1} w_ix_i + b$ 詳細推導的過程請觀看線上影片時長59分以後的部份 [Classification ](https://www.bilibili.com/video/BV1JE411g7XF?p=10/1..:20) ### Logistic Regression 邏輯迴歸是用來處理二分類問題,目標是找到一條直線可以將資料做分類。主要是利用 sigmoid function 將輸出轉換成 0~1 的值,表示可能為這個類別的機率值。而線性迴歸是用來預測一個連續的值,目標是想找一條直線可以逼近真實的資料 ![](https://i.imgur.com/DXT3U0z.png) 假設訓練集如下圖所示,有2個類別 $C1$ 和 $C2$ ![](https://i.imgur.com/yBxrWQo.jpg) 從模型 $f_{w,b}(x)=P_w,b(C1|x)$ 取樣得到訓練集的機率為 $L(w,b)=f_{w,b}(x^1)f_{w,b}(x^2)(1-f_{w,b}(x^3))...f_{w,b}(x^N)$ 我們想求得 $w^*$, $b^*$ 兩個參數 使得$L(w,b)$ 之機率為最高 , 也就是 $arg$ $max_{w,b} L(w,b)$ ,這也相當於求 $arg$ $minx_{w,b} -lnL(w,b)$ $-lnL(w,b) = -lnf_{w,b}(x^1)-lnf_{w,b}(x^2)-ln(1-f_{w,b}(x^3))....$ 其中 $lnf_{w,b}(x^n)= \hat{y}\cdot lnf_{w,b}(x^n)+(1-\hat{y})\cdot ln(1-f_{w,b}(x^n))$ 因此 $-lnL(w,b))= \sum^N_{n=1} -[\hat{y}\cdot lnf_{w,b}(x^n)+(1-\hat{y})\cdot ln(1-f_{w,b}(x^n))]$ ### Entropy 當我們使用二進位來表達一個事件的狀態時,假設一個城市有 8 種不同的天氣狀況 , 我們需要使用至少 3 個 bits 來表達狀況 , 假設事件機率是均等的 , 即 $P=0.125$。 我們所需要的 bit 數之公式為 $-log_2P$ 從這個公式我們可以發現 ,當事件機率發生越高時,我們所需要的 bit 數越少 ,這代表的是 低機率事件我們需要用更多的 bit 去表示(低機率事件需要更多的資訊量去傳達隱含的資訊)。 Entropy 即為表達事件所需要的平均 bit 數,公式為 $Entropy = -\sum P(i)\cdot log_2P(i)$ ### Cross-Entropy Cross-entropy 用意是在觀測預測的機率分佈與實際機率分布的誤差範圍 ,如上面所述,當我們的預測值與實際值差的越多,代表內涵的資訊量愈大,也就是不確定的因素越多, Cross-entropy 會越高,而我們要所要找的是 Cross-Entropy 越低的結果。 這個結論也等價於 loss function 的結論 ,找到預測與實際誤差最小的函數, 所以在分類問題上,我們可以將 Cross-Entropy 當成 loss function。 公式如下: P : true distribution Q : predicted distribution $H(p,q)=-\sum P(i)\cdot log_2Q(i)$ ### Loss 與 Cross-Entropy 之關係 模型 $f_{w,b}(x)=P_w,b(C1|x)$ 想求得 $w^*$, $b^*$ 兩個參數 , 使得$L(w,b)$ 之機率為最高的這個問題 等價於$arg$ $minx_{w,b} -lnL(w,b)$ $-lnL(w,b))= \sum^N_{n=1} -[\hat{y}\cdot lnf_{w,b}(x^n)+(1-\hat{y})\cdot ln(1-f_{w,b}(x^n))]$ 又恰好等價於有兩個 Bernoulli distribution $p$ 跟 $q$ , 在 $p$ 中有 $p(x=1)=\hat{y^n}$ , $p(x=0)=1-\hat{y^n}$ , 在 $q$ 中有 $q(x=1)=f(x^n)$ , $q(x=0)=1-f(x^n)$ p 跟 q 的 Cross-Entropy 當我們對 $\frac{-\partial lnL(w,b)}{\partial​ w_i}=\sum^N_{n=1} -(\hat{y^n-f_{w,b}(x^n)})(x^n_i)$ (推導過程省略) 梯度更新為 : $w_{i+1}=w_i - \eta\sum^N_{n=1} -(\hat{y^n-f_{w,b}(x^n)})(x^n_i)$ 更新的步伐跟學習率 ,實際值與預測值之差距以及input 有關係。 ### 為什麽 Logistic Regression model 中的 Loss function 不使用 Square Error ![](https://i.imgur.com/CVg9gy9.jpg) 如上圖所示 , 當選取的點離目標太遙遠或是很接近時,參數更新速度過於緩慢或是不更新。 下圖為比較兩種不同 Loss fuction 的的曲線圖。 ![](https://i.imgur.com/6SX9og7.jpg) ### Multi-Class Classification 不能把 多種類別的 Classification 問題用 Logistic regression​ 的方式處理 比如: 數字1 , 2 ,3 分別當作三個不同的 class 機器會以為 3跟2 這兩個類別 比 3跟1 這兩個類別更接近,但實際上有可能根本不存在這種關係。 ![](https://i.imgur.com/PSIMfoN.jpg) ### Softmax ![](https://i.imgur.com/HBLKvbI.jpg) 可以看出 softmax 類似於 normalization , 但 softmax 做的是使值較大的更好被辨識。 **binary-class 分類時 使用 sigmoid function** **Multi-class 分類時使用 softmax** ## 邏輯回歸的限制 如下圖所示,假如有2個類別,數據集中有4個樣本,每個樣本有2維特徵,將這4個樣本畫在圖上。 ![](https://i.imgur.com/isOIlvV.jpg) 我們無法在當前的圖上使用邏輯回歸找到一條將兩種 class 區分開來的 boundry,那我們可以怎麽辦呢? 我們可以嘗試 Feature Transformation 我們可以把原始的數據/特徵轉換到另外一個空間,在這個新的特徵空間中,找到一條 boundry 將不同類別區隔開。 ![](https://i.imgur.com/G7OpzJn.jpg) 但並不是每次做 Feature Transformation 都很好找到轉換的方法,我們並不一定知道怎麽進行特徵變換,於是我們想讓機器自己學會進行特徵變換,這可以通過 cascade 多個邏輯回歸模型實現,即把多個邏輯回歸模型連接起來。 ![](https://i.imgur.com/0tUgSom.jpg) 我們將上圖中每一個邏輯回歸模型稱做神經元(Neuron),多個Neuron形成一個神經網絡(Neuron network) ## 神經網絡 ### 結構 * 輸入層(Input Layer) * 隱藏層(Hidden Layers) * 輸入層和輸出層之間的層。Deep指有很多隱藏層,多少層才稱為"Deep"並沒有一個明確的標準,我們可以將 Hidden Layers 可以看成特徵提取器(Feature Extractor),作用是替代特徵工程(Feature Engineering)。 * 輸出層(Output Layer) * 可以看成分類器 ![](https://i.imgur.com/aQB8nHk.png) * 機器學習中,人類需要手工做特徵工程(Feature Engineering),人類需要思考如何提取特征。 * 深度學習中,人類可以不做特徵工程,但遇到新的問題:如何設計一個合適的神經網絡結構。 有些問題適合用機器學習 , 有些適合用深度學習 ,端看你想處理什麼問題。 給定 Layer層數 , 以及各層 Layer 有幾個 neuron 就相當於決定 function set , 而決定一個好的 function set 很重要。 ### 激活函數 激活函數可以分為線性激活函數(線性方程控制輸入到輸出的映射,如f(x)=x等)以及非線性激活函數(非線性方程控制輸入到輸出的映射,比如Sigmoid、Tanh、ReLU等) 因為神經網絡中每一層的輸入輸出都是一個線性求和的過程,下一層的輸出只是承接了上一層輸入函數的線性變換,所以如果沒有激活函數,那麽無論你構造的神經網絡多麽複雜,有多少層,最後的輸出都是輸入的線性組合,純粹的線性組合並不能夠解決更為覆雜的問題。而引入激活函數之後,我們會發現常見的激活函數都是非線性的,因此也會給神經元引入非線性元素,使得神經網絡可以逼近其他的任何非線性函數,這樣可以使得神經網絡應用到更多非線性模型中 ### 神經網絡訓練問題(DNN) 在深度學習中,一般有兩種問題: * 在訓練集上性能不好 * 修改神經網絡架構,比如換成更好的激活函數,因為sigmoid函數會導致梯度消失,可以換成ReLU、Leaky ReLU、Parametric ReLU、Maxout等方法。 * 有關激活函數可以參照此文 [激活函數](https://zhuanlan.zhihu.com/p/350814230) * 調整學習率,比如RMSProp、Momentum、Adam * 有關調整學習率可以參照此文 [調整學習率](https://zhuanlan.zhihu.com/p/350816087) * 在測試集上性能不好 * Early Stopping * 如果學習率調整得較好,隨著迭代次數增加,神經網絡在訓練集上的loss會越來越小,但因為驗證集(Validation set)和訓練集不完全一樣,所以神經網絡在驗證集上的loss可能不降反升,所以我們應該在神經網絡在驗證集上loss最小時停止訓練 * Regularization * 比較不常用 * [dropout](https://www.796t.com/content/1547209261.html) 當深度學習中有一個新的方法被提出時,它往往是針對這兩個問題其中之一進行改善。 ### Backpropagation 由於在神經網路中要更新梯度的參數量過於龐大,我們用了一個更有效的梯度下降方式,也就是Backpropagation ![](https://i.imgur.com/ZIf3QCP.jpg) 如下圖所示,$z=x_1w_1+x_2w_2+b$,根據 chain rule 可知 $\frac{\partial C}{\partial W} =\frac{\partial Z}{\partial W}\frac{\partial C}{\partial Z}$ ,其中 $\frac{\partial Z}{\partial W}$為 Forward Pass、$\frac{\partial C}{\partial Z}$ 為Backward Pass ![](https://i.imgur.com/yJ2810f.jpg) #### Forward Pass 由於 $z=x_1w_1+x_2w_2+b$,每個 weight 計算出來的 Forward Pass 值 = 上一層 layer 的輸出值 ![](https://i.imgur.com/ZLunDdt.jpg) #### Backward Pass $\frac{\partial C}{\partial Z}$ 為Backward Pass,從下圖中我們可以發現 Backward Pass 還跟下一層layer 的 Backward Pass 有關係 ![](https://i.imgur.com/je7Uj3a.jpg) 仔細區分還可區分成 2種 case * 下一層為 Output layer * 下一層不為 Output layer 輸出層的 $\frac{\partial C}{\partial {Z^"}}$ 可輕易求得 ![](https://i.imgur.com/Qw997uU.jpg) 如果下一層不為 Output layer,則我們遞迴前進直到下一層為 Output layer 當我們從後面往前面算完之後,即可求出 $\frac{\partial C}{\partial Z}$ ![](https://i.imgur.com/ZwVcs5m.jpg) 有了 $\frac{\partial Z}{\partial W}$ 也有了 $\frac{\partial C}{\partial Z}$ 即可求得我們想要的梯度 ## CNN 常常被用來做圖像處理 常見的圖片性質 * Some patterns are much smaller than the whole image * 在識別某個 pattern時,神經元並不需要圖片的所有像素點,對於一張人類全身照的圖片,我們只需要看到頭部而非整張圖片就可以判斷它是一個人臉 * The same patterns appear in different regions * 人臉可以在圖片的中間區域,也可以在圖片的某個角落區域,所以識別不同區域中的相同 pattern 的多個分類器(或detector)應該用同一組參數或者共享參數 * Subsampling the pixels will not change the object * 將圖片縮小並不會影響我們理解圖片,所以我們可以通過將圖片變小,進而用更少的參數處理圖片 ### CNN 架構說明 ![](https://i.imgur.com/MX8WXzp.png) 圖片經過 convolution layer 然後再進行 max pooling,這個步驟可以進行多次;之後將數據展開(Flatten),再將展開的數據傳進 Fully Connected Feedforward network 得到最後的圖片分類結果 ![](https://i.imgur.com/8jmRcqC.png) ### Convolution ![](https://i.imgur.com/TIEIkFn.png) 以上圖說明, network 的 input 是一張 6x6 的黑白圖片,所以每個 pixel 可以用 0 or 1 表達 上圖中的 filter 是 3x3 的 size,意味著他在偵測一個 3*3 的 pattern,偵測過程中,並不會去看整張 image,而是只看部份的圖片中的 pixel,並判斷某一個 pattern 有沒有出現 Fliter 其實就是一個 matrix ,matrix 中的每一個 element,就跟 neuron 的 weight 和 bias 一樣 需要通過 training data 學習出來的,而不是人去設計的 所以每個 Fliter 裡面的值是甚麼,要做什麼事情,都是學習出來的成果 ![](https://i.imgur.com/ch3s9nq.png) 從圖片的左上角開始進行 convolution , 每次向右移動一個距離,這個距離就叫做 stride ,由你自己設定,每次filter 停下來的時候就跟對應的 filter size pixel matrix 做一個內積 觀察上圖的 filter 1 ,它的斜對角是 1,1,1,所以這個fliter 的工作就是找出有沒有連續的從左上角到右下角的1,1,1 出現在這個image中, 檢測到的結果已在上左圖用藍色標示出來,此時 fliter 在左上和左下得到最大的值,也就是說該 fliter 所要偵測的 pattern 出現在 image 的左上角和左下角 ### Feature map ![](https://i.imgur.com/qtDSBPN.png) 在一個 convolution 的layer裡面,會有一堆 filter ,每一個 filter 做完會得到一個 4x4 matrix,將所有的 filter 做完之後,就會得到很多個 4*4matrix,將這些matrix 合起來,就叫做 Feature Map CNN 對不同 scale 的相同 pattern 在處理上存在一定的困難,因為現在每一個 filter size都是一樣的,如果有同一個pattern,它有不同的size,CNN並不能夠自動處理這個問題 ### Convolution vs Fully Connected ![](https://i.imgur.com/nNX738z.png) 比照 fully connected 的 neuron 是必須連接到所有36個 input 上的,但是我們現在只用連接 9 個 input ,因為我們知道要 detect 一個 pattern,不用看整張 image,看 9 個 input pixel 就夠了,所以當我們這麼做的時候,就用了比較少的參數 ### Max pooling ![](https://i.imgur.com/7OwsId4.png) 根據 filter 1,我們得到一個 4x4 的 matrix,根據filter2,你得到另外一個 4x4 的 matrix,接下來,我們要做什麼事呢? 我們把 output 四個分為一組,每一組裡面通過選取平均值或最大值的方式,把原來 4 個value合成一個 value,這件事情相當於在image每相鄰的四塊區域內都挑出一塊來檢測,這種subsampling 的方式就可以讓你的 image 縮小! ### Convolution + Max pooling ![](https://i.imgur.com/kLKD53A.png) 做完一次 convolution 加一次 max pooling,我們就把原來 6x6 的image,變成了一個 2x2的 image;至於這個2x2的 image ,它每一個 pixel 的深度,也就是每一個 pixel 用幾個 value 來表示,取決於你有幾個 filter,也就是說filter 數量代表深度多深。 新的比較小的 image,它表示的是不同區域上提取到的特徵,實際上不同的 filter 檢測的是該 image 同一區域上的不同特徵屬性,所以每一層 channel (通道)代表的是一種屬性,一塊區域有一種不同的屬性,就有一層不同的channel,對應的就會有一個不同的filter對其進行 convolution 操作。 ### Flatten ![](https://i.imgur.com/8dDpT8c.png) ### Normalization 在訓練過程中,隨著網絡加深,分布逐漸發生變動,導致整體分布逐漸往激活函數(e.g sigmoid)的飽和區間移動,從而反向傳播時底層出現梯度消失,也就是收斂越來越慢的原因。 而Normalization則是把分布強行拉回到均值為0方差為1的標準正態分布,使得激活輸入值落在非線性函數對輸入比較敏感的區域,這樣輸入的小變化就會導致損失函數較大的變化,避免梯度消失問題產生,加速收斂。 #### Batch Normalization BN 是針對 batch 去做計算 隱式的默認每個 batch 間的分布是大致相同的的,當batch size足夠大時,每個 mini-batch 可以較好地反映真實數據的分布;但是,若batch size較小,每個mini-batch 就無法反映所有數據的真實分布,因此,BN 操作對batch size的選擇有較高的要求。 [BN , LN ,IN ,GN ](https://blog.csdn.net/QLeelq/article/details/122600391) 差異請點選此文 ## 常見 CNN ### [GoogLeNet](https://ithelp.ithome.com.tw/articles/10205210)​ ### [ResNet](https://ithelp.ithome.com.tw/articles/10204727) * 提出 Residual net 使很深的模型效能上升 ### [SENet](https://iter01.com/582587.html) * 預測 channel 的重要性 ### [DenseNet](https://zhuanlan.zhihu.com/p/37189203) * 是前面所有層與後面層的密集連接(dense connection)。DenseNet的特色是通過特徵在channel上的連接來實現特徵重用(feature reuse) ### [MobileNet](https://iter01.com/590254.html) * 使 convolution 計算量減少 ## 3-2 Object detection and localization [傳統的物件偵測](https://medium.com/coding-like-coffee/%E7%89%A9%E4%BB%B6%E5%81%B5%E6%B8%AC-object-detection-902ee7ba758b​) * sliding windows 的運算量太大 [OverFeat 論文提出的改善](https://medium.com/coding-like-coffee/%E7%89%A9%E4%BB%B6%E5%81%B5%E6%B8%AC-object-detection-%E4%BA%8C-6dc482601904) * 使用 卷積層 取代 FC 層 , 使用卷積化的方式實作 Sliding Windows (可共用大量運算) * 缺點:邊界框(Bounding Box)的位置並不會太準確 使用 Region proposal 抓取可能有物體存在的區塊 ([Selective Search](https://zhuanlan.zhihu.com/p/2746736)) 再送入神經網路中 ### [RCNN](https://zhuanlan.zhihu.com/p/27473413) ![](https://i.imgur.com/WiRiHM6.png) * 對 2000 個 region 進行特徵提取 , 計算量整體還是偏多 ### [SPPnet](https://zhuanlan.zhihu.com/p/27485018) ![](https://i.imgur.com/fPHsYwc.png) * 對於最後一層卷積層的輸出pooling一下,但是這個pooling窗口的尺寸及步伐設置為相對值,也就是輸出尺寸的一個比例值,這樣對於任意輸入經過這層後都能得到一個固定的輸出 * 輸入不需要放縮到指定大小,增加了一個池化層,還有最重要的一點是每幅圖片只需要提取一次特徵 * SPP也需要訓練CNN提取特徵,然後訓練SVM分類這些特徵。需要巨大的存儲空間,並且分開訓練也很複雜。而且selective search的方法提取特徵是在CPU上進行的,相對於GPU來說還是比較慢的 ### [Fast RCNN](https://zhuanlan.zhihu.com/p/27582096) * SoftMax 取代 SVM 識別檢測全部放到了卷積神經網絡的框架里面,速度快,美中不足的是,區域建議網絡還是Selective Search,網絡其他部分都能在GPU中運行,而這部分需要在CPU中運行 ### [Faster RCNN](https://zhuanlan.zhihu.com/p/27988828) * 將 Region proposal放入 CNN 中 上述提及的方法皆為 two-stage

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully