parse_net_options(options, net);

29 篇文章 1 订阅
27 篇文章 2 订阅

parse_net_options(options, net);函数主体如下

void parse_net_options(list *options, network *net)
{
    net->batch = option_find_int(options, "batch",1);//初始化训练批,每batch个样本更新一次参数。
    net->learning_rate = option_find_float(options, "learning_rate", .001);//初始化学习率
    net->momentum = option_find_float(options, "momentum", .9);//初始化动量
    net->decay = option_find_float(options, "decay", .0001);//初始化权重衰减正则项,防止过拟合
    int subdivs = option_find_int(options, "subdivisions",1);//如果内存不够大,将batch分割为subdivisions个子batch,每个子batch的大小为batch/subdivisions。 在darknet代码中,会将batch/subdivisions命名为batch。
    net->time_steps = option_find_int_quiet(options, "time_steps",1);
    net->notruth = option_find_int_quiet(options, "notruth",0);
    net->batch /= subdivs;
    net->batch *= net->time_steps;
    net->subdivisions = subdivs;
    net->random = option_find_int_quiet(options, "random", 0);

    net->adam = option_find_int_quiet(options, "adam", 0);//选择优化函数并初始化
    if(net->adam){
        net->B1 = option_find_float(options, "B1", .9);
        net->B2 = option_find_float(options, "B2", .999);
        net->eps = option_find_float(options, "eps", .0000001);
    }

    net->h = option_find_int_quiet(options, "height",0);//初始化高宽和通道数
    net->w = option_find_int_quiet(options, "width",0);
    net->c = option_find_int_quiet(options, "channels",0);
    net->inputs = option_find_int_quiet(options, "inputs", net->h * net->w * net->c);//初始化输入,就是高x宽x通道
    net->max_crop = option_find_int_quiet(options, "max_crop",net->w*2);//最大裁剪默认为宽的2倍
    net->min_crop = option_find_int_quiet(options, "min_crop",net->w);//最小裁剪默认为宽
    net->max_ratio = option_find_float_quiet(options, "max_ratio", (float) net->max_crop / net->w);
    net->min_ratio = option_find_float_quiet(options, "min_ratio", (float) net->min_crop / net->w);//此为最大旋转角度
    net->center = option_find_int_quiet(options, "center",0);
    net->clip = option_find_float_quiet(options, "clip", 0);

    net->angle = option_find_float_quiet(options, "angle", 0);//通过旋转角度来生成更多训练样本
    net->aspect = option_find_float_quiet(options, "aspect", 1);
    net->saturation = option_find_float_quiet(options, "saturation", 1);//通过调整饱和度来生成更多训练样本
    net->exposure = option_find_float_quiet(options, "exposure", 1);//通过调整曝光量来生成更多训练样本
    net->hue = option_find_float_quiet(options, "hue", 0);//通过调整色调来生成更多训练样本

    if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied");//如果输入等于0或宽高通道等于0则报错

    char *policy_s = option_find_str(options, "policy", "constant");//调整学习率的policy,有如下policy:CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM,yolo使用了STEP
    net->policy = get_policy(policy_s);
    net->burn_in = option_find_int_quiet(options, "burn_in", 0);
    net->power = option_find_float_quiet(options, "power", 4);
    if(net->policy == STEP){
        net->step = option_find_int(options, "step", 1);//根据batch_num调整学习率
        net->scale = option_find_float(options, "scale", 1); //学习率变化的比例,累计相乘
    } else if (net->policy == STEPS){
        char *l = option_find(options, "steps");
        char *p = option_find(options, "scales");
        if(!l || !p) error("STEPS policy must have steps and scales in cfg file");

        int len = strlen(l);
        int n = 1;
        int i;
        for(i = 0; i < len; ++i){
            if (l[i] == ',') ++n;
        }
        int *steps = calloc(n, sizeof(int));
        float *scales = calloc(n, sizeof(float));
        for(i = 0; i < n; ++i){
            int step    = atoi(l);
            float scale = atof(p);
            l = strchr(l, ',')+1;
            p = strchr(p, ',')+1;
            steps[i] = step;
            scales[i] = scale;
        }
        net->scales = scales;
        net->steps = steps;
        net->num_steps = n;
    } else if (net->policy == EXP){
        net->gamma = option_find_float(options, "gamma", 1);
    } else if (net->policy == SIG){
        net->gamma = option_find_float(options, "gamma", 1);
        net->step = option_find_int(options, "step", 1);
    } else if (net->policy == POLY || net->policy == RANDOM){
    }
    net->max_batches = option_find_int(options, "max_batches", 0);//训练达到max_batches后停止学习
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值