下面将描述的是基于yolov2.cfg文件,对于学习率的调整方法
缩写
lr = learning rate
bn = batch size
主要文件
读取cfg配置参数的主要文件为src/parser.c
yolov2.cfg中相关部分
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
这里有很多的参数读入,我们此处只关心学习率。
学习率受到多个参数控制,首先我们先找到burn_in
net->burn_in = option_find_int_quiet(options, "burn_in", 0);
读入的burn_in在src/network.c中的
float get_current_rate(network *net)
函数中使用到了
这里利用了bn和burn_in进行对比,返回一个新的当前学习率
if (batch_num < net->burn_in) return net->learning_rate * pow((float)batch_num / net->burn_in, net->power);
完成burn_in个batch之后,下面学习率更新将根据net->policy进行选择,而yolov2中选择的policy为
steps
还是在这个函数中,跳到STEPS的case查看,记住yolov2.cfg中引入的steps和scales
switch (net->policy) {
...
case STEPS:
rate = net->learning_rate;
for(i = 0; i < net->num_steps; ++i){
if(net->steps[i] > batch_num) return rate;
rate *= net->scales[i];
}
return rate;
分析这段代码,可以知道,learning rate在bn到了一定的值之后,会让rate缩小scale的倍数,再进行返回。