zoukankan      html  css  js  c++  java
  • solver解析与设置

    Caffe的solver参数设置: http://caffe.berkeleyvision.org/tutorial/solver.html

    
    

    net: "path to prototxt (train and val)"

    test_iter

    每次test_interval的test的迭代次数,假设测试样本总数为10000张图片,一次性执行全部的话效率很低,所以将测试数据分为几个批次进行测试,

    每个批次的数量就是batch_size。如果batch_size=100,那么需要迭代100次才能将10000个数据全部执行完,所以test_iter设置为100。

    Caffe默认的迭代次数是50,当batch_size=1时可以通过设置test_iter为20000来修改迭代次数实现测试样本全覆盖。

    test_interval测试间隔,每训练多少次进行一次测试。

    test_initialization:表示是否在训练之前进行一次TestALL()操作,其中如果设置了snapshot,会进行一次snapshot动作;

    iter_size: 处理batchsize*itersize张图片后,才调用一次ApplyUpdate函数根据学习率、method(SGD、AdaSGD等)进行梯度下降

    Caffe的solver类提供了6种优化算法,配置文件中可以通过type关键字设置:
        Stochastic Gradient Descent (type: “SGD”)
        AdaDelta (type: “AdaDelta”)
        Adaptive Gradient (type: “AdaGrad”)
        Adam (type: “Adam”)
        Nesterov’s Accelerated Gradient (type: “Nesterov”)
        RMSprop (type: “RMSProp”)
    inv: (type:
    “inv”逐渐下降 return base_lr*(1+gamma*iter)^(-power) 简单地讲,solver就是一个告诉caffe你需要网络如何被训练的一个配置文件
    lr_policy
    这个参数代表的是learning rate应该遵守什么样的变化规则,这个参数对应的是字符串,选项及说明如下:
    “step” - 需要设置一个stepsize参数,返回base_lr * gamma ^ ( floor ( iter / stepsize ) ),iter为当前迭代次数
    “multistep” - 和step相近,但是需要stepvalue参数,step是均匀等间隔变化,而multistep是根据stepvalue的值进行变化
    “fixed” - 保持base_lr不变
    “exp” - 返回base_lr * gamma ^ iter, iter为当前迭代次数
    “poly” - 学习率进行多项式误差衰减,返回 base_lr ( 1 - iter / max_iter ) ^ ( power )
    “sigmoid” - 学习率进行sigmod函数衰减,返回 base_lr ( 1/ 1+exp ( -gamma * ( iter - stepsize ) ) )
    base_lr:网络基准学习率0.1,lr过大会导致不收敛,过小会导致收敛过慢;并且根据学习策略和对应的gamma值,进行学习率调整;
    lr = base_lr * gamma ^ ( floor ( iter / stepsize ) )
    gamma:α 是lr的衰减系数,如 0.1
    stepsize:是lr的衰减步长,
    momentum:μ 上一次梯度更新的权重,如 0.9;
    weight_decay:权重衰减项,用于防止过拟合,如 0.0005

    SGD

    Stochastic gradient descent (type: “SGD”) updates the weights W by a linear combination of the negative gradient ∇L(W) and the previous weight update Vt. The learning rate α is the weight of the negative gradient. The momentum μ is the weight of the previous update.

    Formally, we have the following formulas to compute the update value Vt+1 and the updated weights Wt+1 at iteration t+1, given the previous weight update Vt and current weights Wt:

    Vt+1=μVt−α∇L(Wt) 
    Wt+1=Wt+Vt+1 
    The learning “hyperparameters” (α and μ) might require a bit of tuning for best results. If you’re not sure where to start, take a look at the “Rules of thumb” below, and for further information you might refer to Leon Bottou’s Stochastic Gradient Descent Tricks [1].

    [1] L. Bottou. Stochastic Gradient Descent Tricks. Neural Networks: Tricks of the Trade: Springer, 2012.

    display:间隔多少迭代次数对结果进行输出;

    average_loss:取多次foward的loss作平均,进行显示输出

    max_iter: 最大迭代次数;

    snapshot:间隔多少迭代次数进行一次模型的保存;

    solver_mode:选择CPU训练或者GPU训练;

    snapshot_prefix:"训练模型保存的路径及前缀";


    就个人经验而论 batchsize越大越好1.震荡明显减少 2.收敛速度加快 3.同样学习率下大batch可以收敛到更好的水平。目前没发现什么大batch过早陷入局部最优的现象,在我这都是batch越大,精度越高;
    Batch Size(批处理大小)对于模型来说是非常重要,在梯度下降方法训练模型时,Batch Size的大小决定了梯度下降的方向收敛的效果和速率,以及内存的利用率。一般来说:过于小的Batch Size可能导致模型不收敛,随着Batch Size的增大,模型的处理速度会加快,但同时达到最优精度的epoch数量也随之增多;因此,Batch Size可能达到时间最优,以及收敛精度最优。所以在选择时一方面根据计算能力来选择,一方面需要进行不同的试验选择相对较优的Batch Size。

      

  • 相关阅读:
    蓝牙模块连接后出现ANR,日志记录
    移动基站问题
    从地址栏获取字符串
    jquery升级换代
    手机屏幕的触点
    屏幕翻转后要干什么
    条件判断后吸住底部的总结
    mouseenter 和 mouseleave
    自动垂直居中的js
    数学方法代替浮动解决自动换行排列
  • 原文地址:https://www.cnblogs.com/hansjorn/p/7760910.html
Copyright © 2011-2022 走看看