CNN調(diào)優(yōu)總結(jié)

來源:Charlotte數(shù)據(jù)挖掘、深度學(xué)習(xí)愛好者 本文約11000字,建議閱讀15+分鐘
本文詳細(xì)對(duì)比了各種超參數(shù)對(duì)CNN模型性能的影響。
針對(duì)CNN優(yōu)化的總結(jié)
Systematic evaluation of CNN advances on the ImageNet
下面轉(zhuǎn)自:
https://nmarkou.blogspot.com.cy/2017/02/the-black-magic-of-deep-learning-tips.html

有助于充分利用 DNN 的小技巧
記得要 shuffle。不要讓你的網(wǎng)絡(luò)通過完全相同的 minibatch,如果框架允許,在每個(gè) epoch 都 shuffle 一次。 擴(kuò)展數(shù)據(jù)集。DNN 需要大量的數(shù)據(jù),而且模型在小的數(shù)據(jù)集上很容易過擬合。我強(qiáng)烈建議你要擴(kuò)展原始的數(shù)據(jù)集。如果你的是一個(gè)視覺任務(wù),可以增加噪點(diǎn)、增白,減少像素,旋轉(zhuǎn)或色移,模糊,等等可以擴(kuò)展的一切。有一點(diǎn)不好的是,假如你擴(kuò)展得太大,可能訓(xùn)練的數(shù)據(jù)大多數(shù)是相同的。我創(chuàng)建了一個(gè)應(yīng)用隨機(jī)變換的層來解決這個(gè)問題,這樣就不會(huì)有相同的樣本。若果你用的是語音數(shù)據(jù),可以進(jìn)行移位和失真處理。 在整個(gè)數(shù)據(jù)集上訓(xùn)練之前,先在非常小的子數(shù)據(jù)集上訓(xùn)練進(jìn)行過擬合,這樣你會(huì)知道你的網(wǎng)絡(luò)可以收斂。這個(gè) tip 來自 Karpathy。 始終使用 dropout 將過擬合的幾率最小化。在大小?> 256 (完全連接層或卷積層)之后就應(yīng)該使用 dropout。關(guān)于這一點(diǎn)有一篇很好的論文:Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning [Gal Yarin & Zoubin Ghahramani,2015]. 避免 LRN 池化,MAX 池化會(huì)更快。 避免 Sigmoid/TanH 的門,它們代價(jià)昂貴,容易飽和,而且可能會(huì)停止反向傳播。實(shí)際上,你的網(wǎng)絡(luò)越深,就越應(yīng)該避免使用 Sigmoid 和 TanH。可以使用更便宜而且更有效的 ReLU 和 PreLU 的門,正如在 Yoshua Bengio 等人的論文 Deep Sparse Rectifier Neural Networks 中所提到的,這兩者能夠促進(jìn)稀疏性,而且它們的反向傳播更加魯棒。 在最大池化之前不要使用 ReLU 或 PreLU ,而是在保存計(jì)算之后使用它。 不要使用 ReLU ,它們太舊了。雖然他們是非常有用的非線性函數(shù),可以解決很多問題。但是,你可以試試用它微調(diào)一個(gè)新模型,由于 ReLU 阻礙反向傳播,初始化不好,你沒法得到任何微調(diào)效果。但是你應(yīng)該用 PreLU 以及一個(gè)非常小的乘數(shù),通常是0.1。使用 PreLU 的話收斂更快,而且不會(huì)像 ReLU 那樣在初始階段被卡住。ELU 也很好,但成本高。 經(jīng)常使用批標(biāo)準(zhǔn)化。參考論文:Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift [Sergey Ioffe & Christian Szegedy,2015]。這會(huì)很有效。批標(biāo)準(zhǔn)化允許更快的收斂(非??欤┮约案〉臄?shù)據(jù)集。這樣你能夠節(jié)省時(shí)間和資源。 雖然大多數(shù)人喜歡刪除平均值,不過我不喜歡。我喜歡壓縮輸入數(shù)據(jù)為[-1,+1]。這可以說是訓(xùn)練和部署方面的技巧,而不是針對(duì)提升性能的技巧。 要能適用更小的模型。假如你是像我這樣部署深度學(xué)習(xí)模型,你很快就會(huì)體會(huì)到把千兆字節(jié)規(guī)模的模型推給用戶或地球另一端的服務(wù)器的痛苦。哪怕要犧牲一些準(zhǔn)確度,也應(yīng)該小型化。 假如你使用比較小的模型,可以試試 ensemble。通常 ensemble 5個(gè)網(wǎng)絡(luò)能夠提升準(zhǔn)確度約3%。 盡可能使用 xavier 初始化。你可以只在大的完全連接層上使用它,然后避免在 CNN 層上使用。有關(guān)這點(diǎn)的解釋可以閱讀這篇文章:An Explanation of Xavier Initialization(by Andy Jones) 如果你的輸入數(shù)據(jù)有空間參數(shù),可以試試端到端的 CNN。可以閱讀這篇論文:SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size [Forrest N. Iandola et. al. 2016],它介紹了一種新的方法,而且性能非常好,你可以嘗試應(yīng)用上面提到的tips。 修改你的模型,只要可能就使用 1x1 的 CNN 層,它的位置對(duì)提高性能很有幫助。 假如沒有高端的 GPU,就不要嘗試訓(xùn)練任何東西了。 假如你要利用模型或你自己的層來制作模板,記得把所有東西參數(shù)化,否則你得重建所有二進(jìn)制文件。 最后,要明白你在做什么。深度學(xué)習(xí)就像是機(jī)器學(xué)習(xí)里的中子彈,它不是任何任務(wù)、任何時(shí)候都有效的。了解你正在使用的結(jié)構(gòu)以及你試圖達(dá)成的目的,才不至于盲目地復(fù)制模型。
提升算法性能思路
1.?通過數(shù)據(jù)提升性能?
2.?通過算法提升性能?
3.?通過算法調(diào)參提升性能?
4.?通過嵌套模型提升性能
獲取更多數(shù)據(jù) 創(chuàng)造更多數(shù)據(jù) 重放縮你的數(shù)據(jù) 轉(zhuǎn)換你的數(shù)據(jù) 特征選取 重架構(gòu)你的問題
1) 獲取更多數(shù)據(jù)
Datasets Over Algorithms
如果你的數(shù)據(jù)是數(shù)值型向量,可以隨機(jī)構(gòu)造已有向量的修改版本。 如果你的數(shù)據(jù)是圖片,可以隨機(jī)構(gòu)造已有圖片的修改版本(平移、截取、旋轉(zhuǎn)等)。 如果你的數(shù)據(jù)是文本,類似的操作……
Image Augmentation for Deep Learning With Keras http://machinelearningmastery.com/image-augmentation-deep-learning-keras/ What is jitter? (Training with noise) ftp://ftp.sas.com/pub/neural/FAQ3.html#A_jitter
3) 重縮放(rescale)你的數(shù)據(jù)
當(dāng)應(yīng)用神經(jīng)網(wǎng)絡(luò)時(shí),一個(gè)傳統(tǒng)的經(jīng)驗(yàn)法則是:重縮放(rescale)你的數(shù)據(jù)至激活函數(shù)的邊界。
歸一化到0和1的區(qū)間。 重放縮到-1和1的區(qū)間 標(biāo)準(zhǔn)化(譯者注:標(biāo)準(zhǔn)化數(shù)據(jù)使之成為零均值,單位標(biāo)準(zhǔn)差)
Should I standardize the input variables (column vectors)? ftp://ftp.sas.com/pub/neural/FAQ2.html#A_std How To Prepare Your Data For Machine Learning in Python with Scikit-Learn http://machinelearningmastery.com/prepare-data-machine-learning-python-scikit-learn/
4) 數(shù)據(jù)變換
列數(shù)據(jù)看起來像偏斜的高斯分布嗎?考慮用Box-Cox變換調(diào)整偏態(tài)。 列數(shù)據(jù)看起來像指數(shù)分布嗎?考慮用對(duì)數(shù)變換。 列數(shù)據(jù)看起來有一些特征,但是它們被一些明顯的東西遮蓋了,嘗試取平方或者開平方根來轉(zhuǎn)換數(shù)據(jù) 你能離散化一個(gè)特征或者以某種方式組合特征,來更好地突出一些特征嗎?
你能利用類似PCA的投影方法來預(yù)處理數(shù)據(jù)嗎? 你能綜合多維特征至一個(gè)單一數(shù)值(特征)嗎? 你能用一個(gè)新的布爾標(biāo)簽去發(fā)現(xiàn)問題中存在一些有趣的方面嗎? 你能用其他方法探索出目前場(chǎng)景下的其他特殊結(jié)構(gòu)嗎?
How to Define Your Machine Learning Problem http://machinelearningmastery.com/how-to-define-your-machine-learning-problem/ Discover Feature Engineering, How to Engineer Features and How to Get Good at It http://machinelearningmastery.com/discover-feature-engineering-how-to-engineer-features-and-how-to-get-good-at-it/ How To Prepare Your Data For Machine Learning in Python with Scikit-Learn http://machinelearningmastery.com/prepare-data-machine-learning-python-scikit-learn/
5) 特征選擇
同樣的,如果你有時(shí)間,我建議在同一個(gè)網(wǎng)絡(luò)中嘗試選擇不同的視角來看待你的問題,評(píng)估它們,來看看分別有怎樣的性能。
或許你利用更少的特征就能達(dá)到同等甚至更好的性能。而且,這將使模型變得更快! 或許所有的特征選擇方法都剔除了同樣的特征子集。很好,這些方法在沒用的特征上達(dá)成了一致。 或許篩選過后的特征子集,能帶給特征工程的新思路。
An Introduction to Feature Selection http://machinelearningmastery.com/an-introduction-to-feature-selection/ Feature Selection For Machine Learning in Python http://machinelearningmastery.com/feature-selection-machine-learning-python/
6) 重新架構(gòu)你的問題
看看能夠在一個(gè)時(shí)間窗(時(shí)間周期)內(nèi)對(duì)已有的特征/數(shù)據(jù)做一個(gè)合并。 或許你的分類問題可以成為一個(gè)回歸問題(有時(shí)候是回歸到分類)。 或許你的二元輸出可以變成softmax輸出? 或許你可以轉(zhuǎn)而對(duì)子問題進(jìn)行建模。
How to Define Your Machine Learning Problem http://machinelearningmastery.com/how-to-define-your-machine-learning-problem/
通過算法提升性能
對(duì)算法進(jìn)行抽樣調(diào)查 借鑒已有文獻(xiàn) 重采樣方法
1) 對(duì)算法進(jìn)行抽樣調(diào)查
首先嘗試評(píng)估一些線性方法,例如邏輯回歸(logistic regression)和線性判別分析(linear discriminate analysis)。 評(píng)估一些樹類模型,例如CART, 隨機(jī)森林(Random Forest)和Gradient Boosting。 評(píng)估一些實(shí)例方法,例如支持向量機(jī)(SVM)和K-近鄰(kNN)。 評(píng)估一些其他的神經(jīng)網(wǎng)絡(luò)方法,例如LVQ, MLP, CNN, LSTM, hybrids等
A Data-Driven Approach to Machine Learning http://machinelearningmastery.com/a-data-driven-approach-to-machine-learning/ Why you should be Spot-Checking Algorithms on your Machine Learning Problems http://machinelearningmastery.com/why-you-should-be-spot-checking-algorithms-on-your-machine-learning-problems/ Spot-Check Classification Machine Learning Algorithms in Python with scikit-learn http://machinelearningmastery.com/spot-check-classification-machine-learning-algorithms-python-scikit-learn/
2) 借鑒已有文獻(xiàn)
How to Research a Machine Learning Algorithm http://machinelearningmastery.com/how-to-research-a-machine-learning-algorithm/ Google Scholar http://scholar.google.com/
3) 重采樣方法
或許你在使用一個(gè)簡(jiǎn)單的訓(xùn)練集/測(cè)試集分割,這是常規(guī)套路。如果是這樣,你需要確保這種分割針對(duì)你的問題具有代表性。單變量統(tǒng)計(jì)和可視化是一個(gè)好的開始。 或許你能利用硬件來加速估計(jì)的過程。例如,如果你有集群或者AWS云端服務(wù)(Amazon Web Services)賬號(hào),你可以并行地訓(xùn)練n個(gè)模型,然后獲取結(jié)果的均值和標(biāo)準(zhǔn)差來得到更魯棒的估計(jì)。 或許你可以利用hold-out驗(yàn)證方法來了解模型在訓(xùn)練后的性能(這在早停法(early stopping)中很有用,后面會(huì)講到)。 或許你可以先隱藏一個(gè)完全沒用過的驗(yàn)證集,等到你已經(jīng)完成模型選擇之后再使用它。
有些情況下你會(huì)發(fā)現(xiàn)在訓(xùn)練集的一部分樣本上訓(xùn)練得到的模型的性能,和在整個(gè)數(shù)據(jù)集上訓(xùn)練得到的模型的性能有很強(qiáng)的相關(guān)性。也許你可以先在小數(shù)據(jù)集上完成模型選擇和參數(shù)調(diào)優(yōu),然后再將最終的方法擴(kuò)展到全部數(shù)據(jù)集上。 或許你可以用某些方式限制數(shù)據(jù)集,只取一部分樣本,然后用它進(jìn)行全部的建模過程。
Evaluate the Performance Of Deep Learning Models in Keras http://machinelearningmastery.com/evaluate-performance-deep-learning-models-keras/ Evaluate the Performance of Machine Learning Algorithms in Python using Resampling http://machinelearningmastery.com/evaluate-performance-machine-learning-algorithms-python-using-resampling/
通過算法調(diào)參提升性能
診斷(Diagnostics) 權(quán)重初始化(Weight Initialization) 學(xué)習(xí)速率(Learning Rate) 激活函數(shù) 網(wǎng)絡(luò)拓?fù)洌∟etwork Topology) 批次和周期(Batches and Epochs) 正則化 優(yōu)化和損失 早停法
How to Grid Search Hyperparameters for Deep Learning Models in Python With Keras http://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/
1) 診斷
如果訓(xùn)練集上的模型總是優(yōu)于驗(yàn)證集上的模型,你可能遇到了過擬合,你可以使用諸如正則化的方法。 如果訓(xùn)練集和驗(yàn)證集上的模型都很差,你可能遇到了欠擬合,你可以提升網(wǎng)絡(luò)的容量,以及訓(xùn)練更多或者更久。 如果有一個(gè)拐點(diǎn)存在,在那之后訓(xùn)練集上的模型開始優(yōu)于驗(yàn)證集上的模型,你可能需要使用早停法。
對(duì)于難以訓(xùn)練的樣本,或許你需要更多的數(shù)據(jù)。 或許你應(yīng)該剔除訓(xùn)練集中易于建模的多余的樣本。 也許可以嘗試對(duì)訓(xùn)練集劃分不同的區(qū)域,在特定區(qū)域中用更專長(zhǎng)的模型。
Display Deep Learning Model Training History in Keras http://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/ Overfitting and Underfitting With Machine Learning Algorithms http://machinelearningmastery.com/overfitting-and-underfitting-with-machine-learning-algorithms/
2) 權(quán)重初始化
嘗試所有不同的初始化方法,考察是否有一種方法在其他情況不變的情況下(效果)更優(yōu)。 嘗試用無監(jiān)督的方法,例如自動(dòng)編碼(autoencoder),來進(jìn)行預(yù)先學(xué)習(xí)。 嘗試使用一個(gè)已經(jīng)存在的模型,只是針對(duì)你的問題重新訓(xùn)練輸入層和輸出層(遷移學(xué)習(xí)(transfer learning))
Initialization of deep networks http://deepdish.io/2015/02/24/network-initialization/
3) 學(xué)習(xí)率
實(shí)驗(yàn)很大和很小的學(xué)習(xí)率 格點(diǎn)搜索文獻(xiàn)里常見的學(xué)習(xí)速率值,考察你能學(xué)習(xí)多深的網(wǎng)絡(luò)。 嘗試隨周期遞減的學(xué)習(xí)率 嘗試經(jīng)過固定周期數(shù)后按比例減小的學(xué)習(xí)率。 嘗試增加一個(gè)動(dòng)量項(xiàng)(momentum term),然后對(duì)學(xué)習(xí)速率和動(dòng)量同時(shí)進(jìn)行格點(diǎn)搜索。
Using Learning Rate Schedules for Deep Learning Models in Python with Keras http://machinelearningmastery.com/using-learning-rate-schedules-deep-learning-models-python-keras/ What learning rate should be used for backprop? ftp://ftp.sas.com/pub/neural/FAQ2.html#A_learn_rate
4) 激活函數(shù)
Why use activation functions? ftp://ftp.sas.com/pub/neural/FAQ2.html#A_act
5) 網(wǎng)絡(luò)拓?fù)?/span>
嘗試一個(gè)隱藏層和許多神經(jīng)元(廣度模型)。 嘗試一個(gè)深的網(wǎng)絡(luò),但是每層只有很少的神經(jīng)元(深度模型)。 嘗試上述兩種方法的組合。 借鑒研究問題與你的類似的論文里面的結(jié)構(gòu)。 嘗試拓?fù)淠J剑ㄉ瘸觯╢an out)然后扇入(fan in))和書籍論文里的經(jīng)驗(yàn)法則(下有鏈接)
這些鏈接會(huì)給你很多啟發(fā)該嘗試哪些事情,至少對(duì)我來說是的。
How many hidden layers should I use? ftp://ftp.sas.com/pub/neural/FAQ3.html#A_hl How many hidden units should I use? ftp://ftp.sas.com/pub/neural/FAQ3.html#A_hu
6) Batches和周期
之前,我們已經(jīng)討論了學(xué)習(xí)率,網(wǎng)絡(luò)大小和周期之間的關(guān)系。
嘗試選取與訓(xùn)練數(shù)據(jù)同大小的batch size,但注意一下內(nèi)存(批次學(xué)習(xí)(batch learning)) 嘗試選取1作為batch size(在線學(xué)習(xí)(online learning)) 嘗試用格點(diǎn)搜索不同的小的batch size(8,16,32,…) 分別嘗試訓(xùn)練少量周期和大量周期。
What are batch, incremental, on-line … learning? ftp://ftp.sas.com/pub/neural/FAQ2.html#A_styles Intuitively, how does mini-batch size affect the performance of (stochastic) gradient descent? https://www.quora.com/Intuitively-how-does-mini-batch-size-affect-the-performance-of-stochastic-gradient-descent
7) 正則化
格點(diǎn)搜索不同的丟失比例。 分別在輸入,隱藏層和輸出層中試驗(yàn)dropout方法 dropout方法也有一些拓展,比如你也可以嘗試drop connect方法。
權(quán)重衰減(Weight decay)去懲罰大的權(quán)重 激活約束(Activation constraint)去懲罰大的激活值
Dropout Regularization in Deep Learning Models With Keras http://machinelearningmastery.com/dropout-regularization-deep-learning-models-keras/ What is Weight Decay? ftp://ftp.sas.com/pub/neural/FAQ3.html#A_decay
8) 優(yōu)化和損失
隨機(jī)梯度下降法是默認(rèn)的選擇。先好好利用它,配以不同的學(xué)習(xí)率和動(dòng)量。
ADAM RMSprop
An overview of gradient descent optimization algorithms http://sebastianruder.com/optimizing-gradient-descent/ What are conjugate gradients, Levenberg-Marquardt, etc.? ftp://ftp.sas.com/pub/neural/FAQ2.html#A_numanal On Optimization Methods for Deep Learning, 2011 PDF http://ai.stanford.edu/~ang/papers/icml11-OptimizationForDeepLearning.pdf
9) Early Stopping/早停法
How to Check-Point Deep Learning Models in Keras http://machinelearningmastery.com/check-point-deep-learning-models-keras/ What is early stopping? ftp://ftp.sas.com/pub/neural/FAQ3.html#A_stop
通過嵌套模型提升性能
組合模型 組合視角 堆疊(Stacking)
1) 組合模型
Ensemble Machine Learning Algorithms in Python with scikit-learn http://machinelearningmastery.com/ensemble-machine-learning-algorithms-python-scikit-learn/ How to Improve Machine Learning Results http://machinelearningmastery.com/how-to-improve-machine-learning-results/
2) 組合視角
3) stacking/堆疊
Stacked Generalization (Stacking) http://machine-learning.martinsewell.com/ensembles/stacking/
其余的可參考資源
Neural Network FAQ ftp://ftp.sas.com/pub/neural/FAQ.html How to Grid Search Hyperparameters for Deep Learning Models in Python With Keras http://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/ Must Know Tips/Tricks in Deep Neural Networks http://lamda.nju.edu.cn/weixs/project/CNNTricks/CNNTricks.html How to increase validation accuracy with deep neural net? http://stackoverflow.com/questions/37020754/how-to-increase-validation-accuracy-with-deep-neural-net
編輯:于騰凱 校對(duì):龔力
評(píng)論
圖片
表情
