caffe 中base_lr、weight_decay、lr_mult、decay_mult代表什么意思?
在機(jī)器學(xué)習(xí)或者模式識(shí)別中,會(huì)出現(xiàn)overfitting,而當(dāng)網(wǎng)絡(luò)逐漸overfitting時(shí)網(wǎng)絡(luò)權(quán)值逐漸變大,因此,為了避免出現(xiàn)overfitting,會(huì)給誤差函數(shù)添加一個(gè)懲罰項(xiàng),常用的懲罰項(xiàng)是所有權(quán)重的平方乘以一個(gè)衰減常量之和。其用來懲罰大的權(quán)值。
The learning rate is a parameter that determines how much an updating step influences the current value of the weights. While weight decay is an additional term in the weight update rule that causes the weights to exponentially decay to zero, if no other update is scheduled.
So let's say that we have a cost or error function?E(w)?that we want to minimize. Gradient descent tells us to modify the weights?w?in the direction of steepest descent in?E:
wi←wi?η?E?wi,where?η?is the learning rate, and if it's large you will have a correspondingly large modification of the weights?wi(in general it shouldn't be too large, otherwise you'll overshoot the local minimum in your cost function).
In order to effectively limit the number of free parameters in your model so as to avoid over-fitting, it is possible to regularize the cost function. An easy way to do that is by introducing a zero mean Gaussian prior over the weights, which is equivalent to changing the cost function to?E?(w)=E(w)+λ2w2. In practice this penalizes large weights and effectively limits the freedom in your model. The regularization parameter?λ?determines how you trade off the original cost?E?with the large weights penalization.
Applying gradient descent to this new cost function we obtain:
wi←wi?η?E?wi?ηλwi.The new term??ηλwi?coming from the regularization causes the weight to decay in proportion to its size.
In your solver you likely have a learning rate set as well as weight decay. ?lr_mult indicates what to multiply the learning rate by for a particular layer. ?This is useful if you want to update some layers with a smaller learning rate (e.g. when finetuning some layers while training others from scratch) or if you do not want to update the weights for one layer (perhaps you keep all the conv layers the same and just retrain fully connected layers). ?decay_mult is the same, just for weight decay.
?
參考資料:http://stats.stackexchange.com/questions/29130/difference-between-neural-net-weight-decay-and-learning-rate
http://blog.csdn.net/u010025211/article/details/50055815
https://groups.google.com/forum/#!topic/caffe-users/8J_J8tc1ZHc
視覺層(Vision Layers)及參數(shù)
所有的層都具有的參數(shù),如name, type, bottom, top和transform_param請(qǐng)參看我的前一篇文章:Caffe學(xué)習(xí)系列(2):數(shù)據(jù)層及參數(shù)
本文只講解視覺層(Vision Layers)的參數(shù),視覺層包括Convolution, Pooling,?Local Response Normalization (LRN), im2col等層。
1、Convolution層:
就是卷積層,是卷積神經(jīng)網(wǎng)絡(luò)(CNN)的核心層。
層類型:Convolution
lr_mult: 學(xué)習(xí)率的系數(shù),最終的學(xué)習(xí)率是這個(gè)數(shù)乘以solver.prototxt配置文件中的base_lr。如果有兩個(gè)lr_mult, 則第一個(gè)表示權(quán)值的學(xué)習(xí)率,第二個(gè)表示偏置項(xiàng)的學(xué)習(xí)率。一般偏置項(xiàng)的學(xué)習(xí)率是權(quán)值學(xué)習(xí)率的兩倍。
在后面的convolution_param中,我們可以設(shè)定卷積層的特有參數(shù)。
必須設(shè)置的參數(shù):
? num_output: 卷積核(filter)的個(gè)數(shù)
? kernel_size: 卷積核的大小。如果卷積核的長(zhǎng)和寬不等,需要用kernel_h和kernel_w分別設(shè)定
其它參數(shù):
? ?stride: 卷積核的步長(zhǎng),默認(rèn)為1。也可以用stride_h和stride_w來設(shè)置。
? ?pad: 擴(kuò)充邊緣,默認(rèn)為0,不擴(kuò)充。 擴(kuò)充的時(shí)候是左右、上下對(duì)稱的,比如卷積核的大小為5*5,那么pad設(shè)置為2,則四個(gè)邊緣都擴(kuò)充2個(gè)像素,即寬度和高度都擴(kuò)充了4個(gè)像素,這樣卷積運(yùn)算之后的特征圖就不會(huì)變小。也可以通過pad_h和pad_w來分別設(shè)定。
weight_filler: 權(quán)值初始化。 默認(rèn)為“constant",值全為0,很多時(shí)候我們用"xavier"算法來進(jìn)行初始化,也可以設(shè)置為”gaussian" bias_filler: 偏置項(xiàng)的初始化。一般設(shè)置為"constant",值全為0。 bias_term: 是否開啟偏置項(xiàng),默認(rèn)為true, 開啟 group: 分組,默認(rèn)為1組。如果大于1,我們限制卷積的連接操作在一個(gè)子集內(nèi)。如果我們根據(jù)圖像的通道來分組,那么第i個(gè)輸出分組只能與第i個(gè)輸入分組進(jìn)行連接。 輸入:n*c0*w0*h0 輸出:n*c1*w1*h1 其中,c1就是參數(shù)中的num_output,生成的特征圖個(gè)數(shù) w1=(w0+2*pad-kernel_size)/stride+1; h1=(h0+2*pad-kernel_size)/stride+1; 如果設(shè)置stride為1,前后兩次卷積部分存在重疊。如果設(shè)置pad=(kernel_size-1)/2,則運(yùn)算后,寬度和高度不變。 示例: layer {name: "conv1"type: "Convolution"bottom: "data"top: "conv1"param {lr_mult: 1}param {lr_mult: 2}convolution_param {num_output: 20kernel_size: 5stride: 1weight_filler {type: "xavier"}bias_filler {type: "constant"}} } 2、Pooling層 也叫池化層,為了減少運(yùn)算量和數(shù)據(jù)維度而設(shè)置的一種層。 層類型:Pooling 必須設(shè)置的參數(shù): kernel_size: 池化的核大小。也可以用kernel_h和kernel_w分別設(shè)定。 其它參數(shù): pool: 池化方法,默認(rèn)為MAX。目前可用的方法有MAX, AVE, 或STOCHASTIC pad: 和卷積層的pad的一樣,進(jìn)行邊緣擴(kuò)充。默認(rèn)為0 stride: 池化的步長(zhǎng),默認(rèn)為1。一般我們?cè)O(shè)置為2,即不重疊。也可以用stride_h和stride_w來設(shè)置。 示例: layer {name: "pool1"type: "Pooling"bottom: "conv1"top: "pool1"pooling_param {pool: MAXkernel_size: 3stride: 2} }pooling層的運(yùn)算方法基本是和卷積層是一樣的。
輸入:n*c*w0*h0 輸出:n*c*w1*h1 和卷積層的區(qū)別就是其中的c保持不變 w1=(w0+2*pad-kernel_size)/stride+1; h1=(h0+2*pad-kernel_size)/stride+1; 如果設(shè)置stride為2,前后兩次卷積部分不重疊。100*100的特征圖池化后,變成50*50. 3、Local Response Normalization (LRN)層 此層是對(duì)一個(gè)輸入的局部區(qū)域進(jìn)行歸一化,達(dá)到“側(cè)抑制”的效果。可去搜索AlexNet或GoogLenet,里面就用到了這個(gè)功能 層類型:LRN 參數(shù):全部為可選,沒有必須 local_size: 默認(rèn)為5。如果是跨通道LRN,則表示求和的通道數(shù);如果是在通道內(nèi)LRN,則表示求和的正方形區(qū)域長(zhǎng)度。 alpha: 默認(rèn)為1,歸一化公式中的參數(shù)。 beta: 默認(rèn)為5,歸一化公式中的參數(shù)。 norm_region: 默認(rèn)為ACROSS_CHANNELS。有兩個(gè)選擇,ACROSS_CHANNELS表示在相鄰的通道間求和歸一化。WITHIN_CHANNEL表示在一個(gè)通道內(nèi)部特定的區(qū)域內(nèi)進(jìn)行求和歸一化。與前面的local_size參數(shù)對(duì)應(yīng)。 歸一化公式:對(duì)于每一個(gè)輸入, 去除以,得到歸一化后的輸出 示例: layers {name: "norm1"type: LRNbottom: "pool1"top: "norm1"lrn_param {local_size: 5alpha: 0.0001beta: 0.75} }4、im2col層
如果對(duì)matlab比較熟悉的話,就應(yīng)該知道im2col是什么意思。它先將一個(gè)大矩陣,重疊地劃分為多個(gè)子矩陣,對(duì)每個(gè)子矩陣序列化成向量,最后得到另外一個(gè)矩陣。
?
看一看圖就知道了:
在caffe中,卷積運(yùn)算就是先對(duì)數(shù)據(jù)進(jìn)行im2col操作,再進(jìn)行內(nèi)積運(yùn)算(inner product)。這樣做,比原始的卷積操作速度更快。
看看兩種卷積操作的異同:
轉(zhuǎn)載于:https://www.cnblogs.com/JZ-Ser/p/7150950.html
總結(jié)
以上是生活随笔為你收集整理的caffe 中base_lr、weight_decay、lr_mult、decay_mult代表什么意思?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat:基础安装和使用教程
- 下一篇: 初步了解虚拟化