【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。...
大家好,歡迎來(lái)到專欄《調(diào)參實(shí)戰(zhàn)》,雖然當(dāng)前自動(dòng)化調(diào)參研究越來(lái)越火,但那其實(shí)只是換了一些參數(shù)來(lái)調(diào),對(duì)參數(shù)的理解和調(diào)試在機(jī)器學(xué)習(xí)相關(guān)任務(wù)中是最基本的素質(zhì),在這個(gè)專欄中我們會(huì)帶領(lǐng)大家一步一步理解和學(xué)習(xí)調(diào)參。
本次主要講述圖像分類項(xiàng)目中的學(xué)習(xí)率的調(diào)參實(shí)踐。
作者&編輯 | 言有三
本文資源與結(jié)果展示
本文篇幅:3500字
背景要求:會(huì)使用Python和任一深度學(xué)習(xí)開源框架
附帶資料:Caffe代碼和數(shù)據(jù)集一份
同步平臺(tái):有三AI知識(shí)星球(一周內(nèi))
1 項(xiàng)目背景與準(zhǔn)備工作
對(duì)于很多初入機(jī)器學(xué)習(xí)/深度學(xué)習(xí)領(lǐng)域的朋友來(lái)說(shuō),往往只會(huì)套用公開的模型,對(duì)參數(shù)的理解和調(diào)試非常欠缺經(jīng)驗(yàn),很多經(jīng)驗(yàn)豐富的老鳥則往往自稱“煉丹師”,這就是因?yàn)?strong>參數(shù)的調(diào)試對(duì)于模型性能的影響確實(shí)非常大,輕則損害模型性能,重則甚至使得模型無(wú)法正常收斂。
圖像分類是整個(gè)計(jì)算機(jī)視覺領(lǐng)域中最基礎(chǔ)的任務(wù),實(shí)驗(yàn)起來(lái)比較簡(jiǎn)單,在學(xué)術(shù)界也常用于新模型的比較,因此我們選擇圖像分類任務(wù)來(lái)進(jìn)行調(diào)參的學(xué)習(xí)。
本次項(xiàng)目開發(fā)需要以下環(huán)境:
(1) Linux系統(tǒng),推薦ubuntu16.04或者ubuntu18.04。使用windows系統(tǒng)也可以完成,但是使用Linux效率更高。
(2) 最好擁有一塊顯存不低于6G的GPU顯卡,如果沒有使用CPU進(jìn)行訓(xùn)練速度較慢。
(3)?安裝好的Caffe開源框架。
2 數(shù)據(jù)集和基準(zhǔn)模型
下面我們首先介紹一下數(shù)據(jù)集和基準(zhǔn)模型。
2.1?數(shù)據(jù)集
在計(jì)算機(jī)視覺領(lǐng)域中,MNIST,CIFAR,ImageNet常常被用于任務(wù)比較,但是它們都有各自的問題。MNIST和CIFAR數(shù)據(jù)集圖像太小,與真實(shí)的計(jì)算機(jī)視覺任務(wù)相去甚遠(yuǎn)。ImageNet數(shù)據(jù)集超過(guò)100G,對(duì)于大部分個(gè)人研究者來(lái)說(shuō),不適合拿來(lái)快速進(jìn)行學(xué)習(xí)驗(yàn)證。
基于此,我們選擇了GHIM-10k數(shù)據(jù)集,這是一個(gè)圖像檢索數(shù)據(jù)集,包含20個(gè)類別,分別是日落,船舶,花卉,建筑物,汽車,山脈,昆蟲等自然圖像,各個(gè)類別擁有較好的多樣性,而類別之間也有比較好的區(qū)分度。數(shù)據(jù)集共10000張圖像,每個(gè)類別包含500張JPEG格式的大小為400×300或300×400的圖像。
這個(gè)數(shù)據(jù)集有以下幾個(gè)比較重要的優(yōu)點(diǎn)。
(1) 數(shù)據(jù)集規(guī)模不大,獲取也很容易,所有的讀者都可以輕易驗(yàn)證我們的實(shí)驗(yàn)結(jié)果。
(2) 全部都是真實(shí)圖片,來(lái)自于用戶相機(jī)拍攝,而且圖片清晰度足夠高。
(3) 數(shù)據(jù)集多樣性適中,包含了20類場(chǎng)景的自然場(chǎng)景,每一類的場(chǎng)景非常的均勻。圖片的尺寸是300*400或者400*300,規(guī)格統(tǒng)一,符合大多數(shù)深度學(xué)習(xí)圖像任務(wù)的處理分辨率,尤其是圖像分類。
(4) 數(shù)據(jù)集類別分布非常的均勻,我們選擇數(shù)據(jù)集的方式也是隨機(jī)但均勻的選取。我們將數(shù)據(jù)集按照9:1的比率進(jìn)行劃分,訓(xùn)練集中包含20類,每一類450張圖,測(cè)試集中包含20類,每一類50張圖。
2.2 基準(zhǔn)模型
如今深度學(xué)習(xí)模型已經(jīng)有了非常多的變種,而它的本質(zhì)并沒有變,就是以卷積+非線性激活函數(shù)組成的基礎(chǔ)單元進(jìn)行疊加的模式。
經(jīng)典的AlexNet是一個(gè)8層的網(wǎng)絡(luò),包含了5層卷積和3層全連接,這里我們也選擇一個(gè)類似的模型,包括5層卷積,1層全局池化,1層全連接,因?yàn)楣_的學(xué)術(shù)研究表明全連接層并不需要過(guò)多。
采用Caffe和Proto協(xié)議來(lái)定義網(wǎng)絡(luò),這樣的模型配置可以手動(dòng)進(jìn)行,非常適合一邊調(diào)試一邊進(jìn)行可視化,模型細(xì)節(jié)如下:
layer {
? ?name: "data"
? ?type: "ImageData"
? ?top: "data"
? ?top: "label"
? ?include {
? ? ?phase: TRAIN
? ?}
? ?transform_param {
? ? ?mirror: true
? ? ?crop_size: 224
? ? ?mean_value: 104.0
? ? ?mean_value: 117.0
? ? ?mean_value: 124.0
? ?}
? ?image_data_param {
? ? ?source: "list_train_shuffle.txt"
? ? ?batch_size: 16
? ? ?shuffle: true
? ? ?new_height: 256
? ? ?new_width: 256
? ?}
?}
layer {
? ?name: "data"
? ?type: "ImageData"
? ?top: "data"
? ?top: "label"
? ?include {
? ? ?phase: TEST
? ?}
? ?transform_param {
? ? ?mirror: false
? ? ?crop_size: 224
? ? ?mean_value: 104.0
? ? ?mean_value: 117.0
? ? ?mean_value: 124.0
? ?}
? ?image_data_param {
? ? ?source: "list_val_shuffle.txt"
? ? ?batch_size: 16
? ? ?shuffle: false
? ? ?new_height: 224
? ? ?new_width: 224
? ?}
?}
layer {
? bottom: "data"
? top: "conv1"
? name: "conv1"
? type: "Convolution"
? param {
? ? lr_mult: 1
? ? decay_mult: 1
? }
? param {
? ? lr_mult: 2
? ? decay_mult: 0
? }
? convolution_param {
? ? num_output: 64
? ? pad: 1
? ? kernel_size: 3? ??
? ? stride: 2
? ? weight_filler {
? ? ? type: "gaussian"
? ? ? std: 0.01
? ? }
? ? bias_filler {
? ? ? type: "constant"
? ? ? value: 0
? ? }
? }
}
layer {
? bottom: "conv1"
? top: "conv1"
? name: "relu1"
? type: "ReLU"
}
layer {
? bottom: "conv1"
? top: "conv2"
? name: "conv2"
? type: "Convolution"
? param {
? ? lr_mult: 1
? ? decay_mult: 1
? }
? param {
? ? lr_mult: 2
? ? decay_mult: 0
? }
? convolution_param {
? ? num_output: 64
? ? pad: 1
? ? kernel_size: 3
? ? stride: 2
? ? weight_filler {
? ? ? type: "gaussian"
? ? ? std: 0.01
? ? }
? ? bias_filler {
? ? ? type: "constant"
? ? ? value: 0
? ? }
? }
}
layer {
? bottom: "conv2"
? top: "conv2"
? name: "relu2"
? type: "ReLU"
}
layer {
? bottom: "conv2"
? top: "conv3"
? name: "conv3"
? type: "Convolution"
? param {
? ? lr_mult: 1
? ? decay_mult: 1
? }
? param {
? ? lr_mult: 2
? ? decay_mult: 0
? }
? convolution_param {
? ? num_output: 128
? ? pad: 1
? ? kernel_size: 3
? ? stride: 2
? ? weight_filler {
? ? ? type: "gaussian"
? ? ? std: 0.01
? ? }
? ? bias_filler {
? ? ? type: "constant"
? ? ? value: 0
? ? }
? }
}
layer {
? bottom: "conv3"
? top: "conv3"
? name: "relu3"
? type: "ReLU"
}
layer {
? bottom: "conv3"
? top: "conv4"
? name: "conv4"
? type: "Convolution"
? param {
? ? lr_mult: 1
? ? decay_mult: 1
? }
? param {
? ? lr_mult: 2
? ? decay_mult: 0
? }
? convolution_param {
? ? num_output: 128
? ? pad: 1
? ? stride: 2
? ? kernel_size: 3
? ? weight_filler {
? ? ? type: "gaussian"
? ? ? std: 0.01
? ? }
? ? bias_filler {
? ? ? type: "constant"
? ? ? value: 0
? ? }
? }
}
layer {
? bottom: "conv4"
? top: "conv4"
? name: "relu4"
? type: "ReLU"
}
layer {
? bottom: "conv4"
? top: "conv5"
? name: "conv5"
? type: "Convolution"
? param {
? ? lr_mult: 1
? ? decay_mult: 1
? }
? param {
? ? lr_mult: 2
? ? decay_mult: 0
? }
? convolution_param {
? ? num_output: 256
? ? pad: 1
? ? stride: 2
? ? kernel_size: 3
? ? weight_filler {
? ? ? type: "gaussian"
? ? ? std: 0.01
? ? }
? ? bias_filler {
? ? ? type: "constant"
? ? ? value: 0
? ? }
? }
}
layer {
? bottom: "conv5"
? top: "conv5"
? name: "relu5"
? type: "ReLU"
}
layer {
? ? bottom: "conv5"
? ? top: "pool5"
? ? name: "pool5"
? ? type: "Pooling"
? ? pooling_param {
? ? ? ? kernel_size: 7
? ? ? ? stride: 1
? ? ? ? pool: AVE
? ? }
}
layer {
? bottom: "pool5"
? top: "fc"
? name: "fc"
? type: "InnerProduct"
? ? inner_product_param {
? ? ? ? num_output: 20
? ? ? ? weight_filler {
? ? ? ? ? ? type: "xavier"
? ? ? ? }
? ? ? ? bias_filler {
? ? ? ? ? ? type: "constant"
? ? ? ? ? ? value: 0
? ? ? ? }
? ? }
}
layer {
? name: "accuracy_at_1"
? type: "Accuracy"
? bottom: "fc"
? bottom: "label"
? top: "accuracy_at_1"
? accuracy_param {
? ? top_k: 1
? }
}
layer {
? name: "accuracy_at_5"
? type: "Accuracy"
? bottom: "fc"
? bottom: "label"
? top: "accuracy_at_5"
? accuracy_param {
? ? top_k: 5
? }
}
layer {
? bottom: "fc"
? bottom: "label"
? top: "loss"
? name: "loss"
? type: "SoftmaxWithLoss"
}
使用在線工具h(yuǎn)ttp://ethereon.github.io/netscope/#/editor
對(duì)模型的可視化結(jié)果如下:
總結(jié)
以上是生活随笔為你收集整理的【调参实战】如何开始你的第一个深度学习调参任务?不妨从图像分类中的学习率入手。...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【杂谈】有三AI秋季划增加生成对抗网络小
- 下一篇: 【完结】你对深度学习模型的理解是否足够深