foolyc

caffe solver

学习完caffe之后,对内容进行一定程度的梳理,这里主要整理caffe的Solver类。

Introduction to caffe::Solver

Basic Property and Function

  • scaffolds the optimization bookkeeping and creates the training network for learning and test network(s) for evaluation.
  • iteratively optimizes by calling forward / backward and updating parameters
    (periodically) evaluates the test networks
  • snapshots the model and solver state throughout the optimization

Solver Types

acording to 0, the solver can be classified into this serveral types:

  • Stochastic Gradient Descent
  • AdaDelta
  • Adaptive Gradient
  • Adam
  • Nesterov’s Accelerated Gradient
  • RMSprop

more details refer to [0]

process of Solver

刚接触caffe时,想必都是从caffe的./build/tools/caffe入手,为了搞清楚solver的流程,我们可以在eclipse中debug模式下过一遍train或者test的过程。

Solver::Solver()

caffe中的Solver类负责整个训练过程,而caffe::Net则是其具体依托,在Solver类的初始化过程中,Solver类主要完成了下TrainNet和TestNet的构造和初始化工作(主要函数为InitTrainNet、InitTestNet),主要流程如下图:

tips:这里注意了,网络参数的初始化工作就是在每个layer层的Layer::SetUp()中完成的

Computaion Flow in Solver::Solve()

caffe求解过程,solver执行的流程如下所示:

在一个solver类中核心函数是step函数,其参数iters表示迭代训练多少次,step 函数总最重要的部分是ComputeUpdateValue()函数。在ApplyUpdate()函数中每个部分的作用如下:

  • GetlearningRate()函数,根据学习率更新方式和迭代次数计算该迭代次数下的最新学习率,常见学习率更新策略包括fix,step,inv等
  • ClipGradient()函数对计算出来的梯度进行了限幅处理,即
  • Regularization()主要是对梯度进行规整花,常用的loss function中规整项为L1、L2
  • ComputeUpdateValue()根据所选solver类型的不同,进行权重更新值得计算

在计算权重更新值之后,调用Net::Update()对每个参数Blob进行更新

Reference

[0] caffe official website

[1] 深度学习21天实战caffe. 赵永科

本文由foolyc创作和发表,采用BY-NC-SA国际许可协议进行许可
转载请注明作者及出处,本文作者为foolyc
本文标题为caffe solver
本文链接为http://foolyc.com//2016/11/27/caffe-solver/.