上文提到,到目前为止,caffe总共提供了六种优化方法:

  • Stochastic Gradient Descent (type: "SGD"),
  • AdaDelta (type: "AdaDelta"),
  • Adaptive Gradient (type: "AdaGrad"),
  • Adam (type: "Adam"),
  • Nesterov’s Accelerated Gradient (type: "Nesterov") and
  • RMSprop (type: "RMSProp")

Solver就是用来使loss最小化的优化方法。对于一个数据集D,需要优化的目标函数是整个数据集中所有数据loss的平均值。

其中,fW(x(i))计算的是数据x(i)上的loss, 先将每个单独的样本x的loss求出来,然后求和,最后求均值。 r(W)是正则项(weight_decay),为了减弱过拟合现象。

如果采用这种Loss 函数,迭代一次需要计算整个数据集,在数据集非常大的这情况下,这种方法的效率很低,这个也是我们熟知的梯度下降采用的方法。

在实际中,通过将整个数据集分成几批(batches), 每一批就是一个mini-batch,其数量(batch_size)为N<<|D|,此时的loss 函数为:
 

有了loss函数后,就可以迭代的求解loss和梯度来优化这个问题。在神经网络中,用forward pass来求解loss,用backward pass来求解梯度。

在caffe中,默认采用的Stochastic Gradient Descent(SGD)进行优化求解。后面几种方法也是基于梯度的优化方法(like SGD),因此本文只介绍一下SGD。其它的方法,有兴趣的同学,可以去看文献原文。

1、Stochastic gradient descent(SGD)

随机梯度下降(Stochastic gradient descent)是在梯度下降法(gradient descent)的基础上发展起来的,梯度下降法也叫最速下降法,具体原理在网易公开课《机器学习》中,吴恩达教授已经讲解得非常详细。SGD在通过负梯度和上一次的权重更新值Vt的线性组合来更新W,迭代公式如下:


 
其中,  是负梯度的学习率(base_lr),是上一次梯度值的权重(momentum),用来加权之前梯度方向对现在梯度下降方向的影响。这两个参数需要通过tuning来得到最好的结果,一般是根据经验设定的。如果你不知道如何设定这些参数,可以参考相关的论文。

在深度学习中使用SGD,比较好的初始化参数的策略是把学习率设为0.01左右(base_lr: 0.01),在训练的过程中,如果loss开始出现稳定水平时,对学习率乘以一个常数因子(gamma),这样的过程重复多次。

对于momentum,一般取值在0.5--0.99之间。通常设为0.9,momentum可以让使用SGD的深度学习方法更加稳定以及快速。

关于更多的momentum,请参看Hinton的《A Practical Guide to Training Restricted Boltzmann Machines》。

实例:

  1. base_lr: 0.01
  2. lr_policy: "step"
  3. gamma: 0.1
  4. stepsize: 1000
  5. max_iter: 3500
  6. momentum: 0.9

lr_policy设置为step,则学习率的变化规则为 base_lr * gamma ^ (floor(iter / stepsize))

即前1000次迭代,学习率为0.01; 第1001-2000次迭代,学习率为0.001; 第2001-3000次迭代,学习率为0.00001,第3001-3500次迭代,学习率为10-5

上面的设置只能作为一种指导,它们不能保证在任何情况下都能得到最佳的结果,有时候这种方法甚至不work。如果学习的时候出现diverge(比如,你一开始就发现非常大或者NaN或者inf的loss值或者输出),此时你需要降低base_lr的值(比如,0.001),然后重新训练,这样的过程重复几次直到你找到可以work的base_lr。

2、AdaDelta

AdaDelta是一种”鲁棒的学习率方法“,是基于梯度的优化方法(like SGD)。

具体的介绍文献:

M. Zeiler ADADELTA: AN ADAPTIVE LEARNING RATE METHODarXiv preprint, 2012.

示例:

  1. net: "examples/mnist/lenet_train_test.prototxt"
  2. test_iter: 100
  3. test_interval: 500
  4. base_lr: 1.0
  5. lr_policy: "fixed"
  6. momentum: 0.95
  7. weight_decay: 0.0005
  8. display: 100
  9. max_iter: 10000
  10. snapshot: 5000
  11. snapshot_prefix: "examples/mnist/lenet_adadelta"
  12. solver_mode: GPU
  13. type: "AdaDelta"
  14. delta: 1e-6

从最后两行可看出,设置solver type为Adadelta时,需要设置delta的值。

3、AdaGrad

自适应梯度(adaptive gradient)是基于梯度的优化方法(like SGD)

具体的介绍文献:

Duchi, E. Hazan, and Y. Singer. Adaptive Subgradient Methods for Online Learning and Stochastic OptimizationThe Journal of Machine Learning Research, 2011.

示例:

  1. net: "examples/mnist/mnist_autoencoder.prototxt"
  2. test_state: { stage: 'test-on-train' }
  3. test_iter: 500
  4. test_state: { stage: 'test-on-test' }
  5. test_iter: 100
  6. test_interval: 500
  7. test_compute_loss: true
  8. base_lr: 0.01
  9. lr_policy: "fixed"
  10. display: 100
  11. max_iter: 65000
  12. weight_decay: 0.0005
  13. snapshot: 10000
  14. snapshot_prefix: "examples/mnist/mnist_autoencoder_adagrad_train"
  15. # solver mode: CPU or GPU
  16. solver_mode: GPU
  17. type: "AdaGrad"

4、Adam

是一种基于梯度的优化方法(like SGD)。

具体的介绍文献:

D. Kingma, J. Ba. Adam: A Method for Stochastic OptimizationInternational Conference for Learning Representations, 2015.

5、NAG

Nesterov 的加速梯度法(Nesterov’s accelerated gradient)作为凸优化中最理想的方法,其收敛速度非常快。

具体的介绍文献:

I. Sutskever, J. Martens, G. Dahl, and G. Hinton. On the Importance of Initialization and Momentum in Deep LearningProceedings of the 30th International Conference on Machine Learning, 2013.

示例:

  1. net: "examples/mnist/mnist_autoencoder.prototxt"
  2. test_state: { stage: 'test-on-train' }
  3. test_iter: 500
  4. test_state: { stage: 'test-on-test' }
  5. test_iter: 100
  6. test_interval: 500
  7. test_compute_loss: true
  8. base_lr: 0.01
  9. lr_policy: "step"
  10. gamma: 0.1
  11. stepsize: 10000
  12. display: 100
  13. max_iter: 65000
  14. weight_decay: 0.0005
  15. snapshot: 10000
  16. snapshot_prefix: "examples/mnist/mnist_autoencoder_nesterov_train"
  17. momentum: 0.95
  18. # solver mode: CPU or GPU
  19. solver_mode: GPU
  20. type: "Nesterov"

6、RMSprop

RMSprop是Tieleman在一次 Coursera课程演讲中提出来的,也是一种基于梯度的优化方法(like SGD)

具体的介绍文献:

T. Tieleman, and G. Hinton. RMSProp: Divide the gradient by a running average of its recent magnitudeCOURSERA: Neural Networks for Machine Learning.Technical report, 2012.

示例:

  1. net: "examples/mnist/lenet_train_test.prototxt"
  2. test_iter: 100
  3. test_interval: 500
  4. base_lr: 1.0
  5. lr_policy: "fixed"
  6. momentum: 0.95
  7. weight_decay: 0.0005
  8. display: 100
  9. max_iter: 10000
  10. snapshot: 5000
  11. snapshot_prefix: "examples/mnist/lenet_adadelta"
  12. solver_mode: GPU
  13. type: "RMSProp"
  14. rms_decay: 0.98

最后两行,需要设置rms_decay值。

affe(8) solver 优化方法的更多相关文章

  1. Caffe学习系列(8):solver优化方法

    上文提到,到目前为止,caffe总共提供了六种优化方法: Stochastic Gradient Descent (type: "SGD"), AdaDelta (type: &q ...

  2. [转]solver优化方法

    原文地址:http://www.cnblogs.com/denny402/p/5074212.html 到目前为止,caffe总共提供了六种优化方法: Stochastic Gradient Desc ...

  3. Caffe学习系列(9):solver优化方法

    介绍了各种优化算法 参考:http://www.cnblogs.com/denny402/p/5074212.html

  4. Deep Learning基础--参数优化方法

    1. 深度学习流程简介 1)一次性设置(One time setup)          -激活函数(Activation functions) - 数据预处理(Data Preprocessing) ...

  5. 提升网速的路由器优化方法(UPnP、QoS、MTU、交换机模式、无线中继)

    在上一篇<为什么房间的 Wi-Fi 信号这么差>中,猫哥从微波炉.相对论.人存原理出发,介绍了影响 Wi-Fi 信号强弱的几大因素,接下来猫哥再给大家介绍几种不用升级带宽套餐也能提升网速的 ...

  6. php-fpm优化方法详解

    php-fpm优化方法 php-fpm存在两种方式,一种是直接开启指定数量的php-fpm进程,不再增加或者减少:另一种则是开始时开启一定数量的php-fpm进程,当请求量变大时,动态的增加php-f ...

  7. 30多条mysql数据库优化方法,千万级数据库记录查询轻松解决(转载)

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  8. Android中ListView的几种常见的优化方法

    Android中的ListView应该算是布局中几种最常用的组件之一了,使用也十分方便,下面将介绍ListView几种比较常见的优化方法: 首先我们给出一个没有任何优化的Listview的Adapte ...

  9. php-fpm进程数优化方法

    原文地址:https://www.douban.com/note/315222037/ 背景最近将Wordpress迁移至阿里云.由于自己的服务器是云服务器,硬盘和内存都比较小,所以内存经常不够使,通 ...

随机推荐

  1. angular4(2-2)angular脚手架引入第三方类库(swiper)

    试了好多方法,npm install 方法失败了,下载到本地是可以使用的: 将swiper文件放到assets文件下: 项目目录下:(命令行) 因为ts并不能准确识别js语法,所以需要用ts中的int ...

  2. 关于linux下QIODevice类进行读取的几个方法的理解

    Qt中对读写设备的支持力度很大,其都继承与QIODevice类,其中有几个方法是非常值得注意的,不管是在用原始的serial port进行通信还是使用网络的TCP/IP 或者UDP或者HTTP等协议时 ...

  3. 16.boost图深度优先遍历DFS

    #include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...

  4. AJAX和JSON实际应用

    实现功能:登录验证 一.因为我是在SpringMVC框架上写的,首先得添加依赖: <dependencies> <!-- 用来测试的依赖 --> <dependency& ...

  5. Python学习---Day96

    转载:http://www.cnblogs.com/wupeiqi/articles/6229292.html Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可 ...

  6. Url 简单讲解

    eg: http://sb.test.com/login?name=liming&password=twotigers 协议 http https ftp 域名 sb.test.com 则是域 ...

  7. BZOJ3796 Mushroom追妹纸(二分答案+后缀数组+KMP)

    求出一个串使得这个串是\(s1,s2\)的子串.串中不包含\(s3\). 如果没有这个\(s3\)就可以二分答案,然后height小于二分值分一组.看看每组里是不是出现过\(s1,s2\)的后缀.判断 ...

  8. BZOJ 1085 / LOJ 2151 [SCOI2005]骑士精神 (剪枝/A*迭代搜索)

    题目大意:略 直接爆搜会T,我们优化一下,统计出当前棋盘和目标棋盘不同的位置的数量k,那么当前棋盘变成目标棋盘最少的移动次数是k-1 每次选择一个最大深度ma,那么如果当前走了dep步,显然必须保证d ...

  9. adb如何连接mumu模拟器并修改Android ID

    adb工具下载安装 https://dl.google.com/android/repository/platform-tools-latest-windows.zip 参考:https://blog ...

  10. React 使用link在url添加参数(url中不可见)

    1. 在要跳转页面添加<Link to={{ pathname: `/staffManagement/cardRecord`, state: {time: YYYY-MM-dd, name: s ...