--- tags: cs231 --- # Lecture 7: Training Neural Networks, part II ## Fancier Optimization ### SGD Question 1. $W \leftarrow W-\eta\dfrac{\partial L}{\partial W}$ 2. What if loss changes quickly in one direction and slowly in another?  函數的形狀如果沒有等向性,非延伸形狀的函數,就會以沒有效率的路徑來進行探索。 3. What if the loss function has a local minima or saddle point?  - zero gradient - 在高維度時,local minima在任一方向前損失皆會上升,但saddle point則會在某些方向loss上升,某些方向loss下降。 - 在saddle point附近的點雖然gradient不為0,但是斜率小,導致前進速度非常緩慢。 4. Our gradients come from minibatches so they can be noisy! - 通過小批量來對損失與梯度進行估計,代表不是每一步都會計算真正的梯度,而是在當前點對梯度进行noise的估计。 - 需花費很長時間才能得到極小值。 ### Optimization 1. Momentum - $v \leftarrow \alpha v-\eta\dfrac{\partial L}{\partial W}$ $W \leftarrow W+v$ - 站在物理角度,v是對應速度。第一個式子代表物體往梯度方向受力,並將這個這個力量加上物體速度。 - $\alpha v$這是當物體沒有受力時,逐漸減速的功能。相當於地面摩擦力或空氣阻力,$\alpha$同常設為0.9。 - 在local minima或saddle point,即使沒有梯度,一旦加上速度,通過時仍會有速度。 - 減少起伏程度,因為x軸受力非常小,但是承受的失力是同方向,所以固定往同方向加速。相對來說,y軸受力較大,但因為正負方向穿插受力而彼此相抵,使得y軸方向的速度不穩定。 2. Nesterov Mometum  这是根據之前的速度向前進一步,然后计算此處的梯度。當前進到下一步時,實際上是在速度的方向上前進,这就是從多个點上合併信息。 3. AdaGrad  - Adagrad算法則是在學習過程中對學習率不斷的調整,這種技巧叫做「學習率衰減(Learning rate decay)」。通常在神經網路學習,一開始會用大的學習率,接著在變小的學習率,從上述例子可以發現,大的學習率可以較快走到最佳值或是跳出局部極值,但越後面到要找到極值就需要小的學習率。 - 問題:當時間越来越大的时候,在訓練過程中使用AdaGrad會讓步長變得越來越小。 4. RMSProp  - 在RMSProp中仍然計算梯度的平方,但並非簡單地在訓練中累加梯度平方,而是讓梯度平方按照一定比率下降。 5. Adam  - Adam算法结合速度动量和利用梯度平方两个方法, 6. Others - DEMON Adam: Decaying momentum Adam [An overview of gradient descent optimization algorithms](https://ruder.io/optimizing-gradient-descent/index.html#otherrecentoptimizers) [Decaying momentum helps neural network training](https://arxiv.org/abs/1910.04952) ### learning rate 1. 方法 - step decay - exponential decay: $\alpha = \alpha_{0}e^{-kt}$ - 1/t decay: $\alpha = \alpha_{0}/(1+kt)$ 2. learning rate是一種二階超參數,通常不要一開始就使用。先觀察損失函數曲線再決定哪裡開始衰減。 ### Second-Order Optimzation  1. No hyperparameters. No learning rate. 2. Hessian matrix has O(N^2) elements. [Newton method](https://www.wikiwand.com/zh-hk/%E6%87%89%E7%94%A8%E6%96%BC%E6%9C%80%E5%84%AA%E5%8C%96%E7%9A%84%E7%89%9B%E9%A0%93%E6%B3%95) 3. [Quasi-Newton method](https://www.wikiwand.com/zh-hk/%E6%93%AC%E7%89%9B%E9%A0%93%E6%B3%95). L-BFGS 4. Hessian matrix 其他應用 - [求極值](https://baike.baidu.com/item/%E9%BB%91%E5%A1%9E%E7%9F%A9%E9%98%B5) - [邊緣偵測](https://blog.csdn.net/lwzkiller/article/details/55050275?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3) ## Regularization  ### 降低 training & validation gap 的方法: 1. dropout 2. batch normalization 3. data augmentation 4. drop connect 5. fractional max pooling 6. stocastic depth ### Rationale (common pattern) <b>Training</b>: Add random noise <b>Testing</b>: Marginalize over the noise ### <ins>*dropout*</ins>      - 有時候 dropout 比 batch normalization 好的地方是,可以透過調整 P 值來調整 regularization strength。 參考論文:http://jmlr.org/papers/volume15/srivastava14a.old/srivastava14a.pdf ### <ins>*batch normalization*</ins>  - 用 batch normalization 不但可以讓訓練加速,而且本身就會有 regularization 的效果 (randomness: 每個 batch 的 mean / variance 都會不同) ### <ins>*data augmentation*</ins>  概念解釋:  在training以及testing資料上有做一些不一樣的處理,training的部分有使用Multiple scale training。在每次training 時,從一個固定的亂數範圍中,random一個數字,並縮放至那個數字,並隨機剪裁成所需大小。在testing的部分有使用多個crop進行預測,將資料rescale成一個大小,並利用固定的crop大小預測左上、右上、左下、右下跟中間,並平均成最後預測結果。 ### <ins>*drop connect*</ins>  ### <ins>*fractional max pooling*</ins> normal  fractional  ### <ins>*stocastic depth*</ins>  ## Transfer Learning * 使用場景: 通常用來解決訓練目標需要海量資料來做訓練,但又缺少海量資料時 * 抽象作法:把已經訓練過的模型參數遷移到新的模型,幫助新模型的訓練,加快新模型的訓練的效率  |資料 |作法 | |--|--| |Small Dataset|1. 精選你所在意的重要features->c class<br>2.reinitialize the last matrix<br>3. train linear model+最後一層的參數| |Bigger Dataset|train more layers| ### 不同狀況使用不同的方法  ### Transfer Learning在CNN中很常見 <font color=blue>如果你缺少巨量資料</font> -> <font color=green>下載別人(權威研究機構)發布的pretrained model</font> -> <font color=purple>reinitialize or finetune that model</font> ## 問題 | 組別 |<center> 問題 </center>| |:-------------------:|----------------------| | 第一組 |1. 為什麼在 saddle points 附近前進的速度會很慢,反倒是在 saddle points 不太會有什麼問題?不太懂...<br>2.正規化中dropout事都採用random嗎,還是有其他方法嗎?| | 第二組 |<center>報告組</center>| | 第三組 |1.可以再解釋一下有關Transfer learning P93的表格嗎?<br>2.Hessian matrix不太懂(影片說他很少用在深度學習,那他實際可以應用在哪呢?約在影片50分左右講這個)<br>| | 第四組 |1. Optimization這項技術,在近年來有沒有新的研究結果,且有一定的使用比例?|
×
Sign in
Email
Password
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