深度学习常用优化器介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MOU_IT/article/details/82416622

    深度学习的优化算法从SGD-->SGDM-->NAG-->AdaGrad-->AdaDelta-->Adam-->Nadam这样的发展历程,理论知识参考这里,下面我们依次介绍TensorFlow中这些优化器的实现类,官方文档

1、tf.train.Optimizer

    优化器(optimizers)类的基类。这个类定义了在训练模型的时候添加一个操作的API。你基本上不会直接使用这个类,但是你会用到他的子类比如GradientDescentOptimizer, AdagradOptimizer, MomentumOptimizer.等等这些。 后面讲的时候会详细讲一下GradientDescentOptimizer 这个类的一些函数,然后其他的类只会讲构造函数,因为类中剩下的函数都是大同小异的。

2、tf.train.GradientDescentOptimizer

    这个类是实现梯度下降算法的优化器。(结合理论可以看到,这个构造函数需要的一个学习率就行了)

(1) __init__(learning_rate, use_locking=False,name=’GradientDescent’)

     参数: 
        learning_rate: A Tensor or a floating point value. 要使用的学习率 
        use_locking: 要是True的话,就对于更新操作(update operations.)使用锁 
        name: 名字,可选,默认是”GradientDescent”.

(2)compute_gradients(loss,var_list=None,gate_gradients=GATE_OP,aggregation_method=None,colocate_gradients_with_ops=False,grad_loss=None)

    作用:对于在变量列表(var_list)中的变量计算对于损失函数的梯度,这个函数返回一个(梯度,变量)对的列表,其中梯度就是相对应变量的梯度了。这是minimize()函数的第一个部分, 
    参数: 
      loss: 待减小的值 
      var_list: 默认是在GraphKey.TRAINABLE_VARIABLES. 
      gate_gradients: How to gate the computation of gradients. Can be GATE_NONE, GATE_OP, or GATE_GRAPH. 
   aggregation_method: Specifies the method used to combine gradient terms. Valid values are defined in the class AggregationMethod. 
      colocate_gradients_with_ops: If True, try colocating gradients with the corresponding op. 
      grad_loss: Optional. A Tensor holding the gradient computed for loss.

(3)apply_gradients(grads_and_vars,global_step=None,name=None)

    作用:把梯度“应用”(Apply)到变量上面去。其实就是按照梯度下降的方式加到上面去。这是minimize()函数的第二个步骤。 返回一个应用的操作。 
    参数: 
      grads_and_vars: compute_gradients()函数返回的(gradient, variable)对的列表 
      global_step: Optional Variable to increment by one after the variables have been updated. 
      name: 可选,名字

(4)minimize(loss,global_step=None,var_list=None,gate_gradients=GATE_OP,aggregation_method=None,colocate_gradients_with_ops=False,name=None,grad_loss=None)

    作用:非常常用的一个函数 
    通过更新var_list来减小loss,这个函数就是前面compute_gradients() 和apply_gradients().的结合

3、tf.train.AdadeltaOptimizer

    实现了 Adadelta算法的优化器,可以算是下面的Adagrad算法改进版本。

  构造函数: init(learning_rate=0.001, rho=0.95, epsilon=1e-08, use_locking=False, name=’Adadelta’)

    参数: 
      learning_rate: tensor或者浮点数,学习率 
      rho: tensor或者浮点数. The decay rate. 
      epsilon: A Tensor or a floating point value. A constant epsilon used to better conditioning the grad update. 
      use_locking: If True use locks for update operations. 
      name: 这个操作的名字(可选),默认是”Adadelta”

4、tf.train.AdagradOptimizer

   实现了 Adagrad 算法的优化器。

  构造函数:__init__(learning_rate, initial_accumulator_value=0.1, use_locking=False, name=’Adagrad’)

    参数:
      learning_rate: A Tensor or a floating point value. The learning rate.
      initial_accumulator_value: A floating point value. Starting value for the accumulators, must be positive.
      use_locking: If True use locks for update operations.
      name: Optional name prefix for the operations created when applying gradients. Defaults to "Adagrad".

5、tf.train.MomentumOptimizer

    实现了 Momentum 算法的优化器。

  构造函数:__init__(learning_rate, momentum, use_locking=False, name=’Momentum’, use_nesterov=False)

    参数:
      learning_rate: A Tensor or a floating point value. The learning rate. 
      momentum: A Tensor or a floating point value. The momentum. 
      use_locking: If True use locks for update operations. 
      name: Optional name prefix for the operations created when applying gradients. Defaults to “Momentum”.

6、tf.train.AdamOptimizer

    实现了Adam算法的优化器 。

   构造函数: __init__(learning_rate=0.001, beta1=0.9, beta2=0.999, epsilon=1e-08, use_locking=False, name=’Adam’)

    参数:
      learning_rate: A Tensor or a floating point value. The learning rate. 
      beta1: A float value or a constant float tensor. The exponential decay rate for the 1st moment estimates. 
      beta2: A float value or a constant float tensor. The exponential decay rate for the 2nd moment estimates. 
      epsilon: A small constant for numerical stability. 
      use_locking: If True use locks for update operations. 
      name: Optional name for the operations created when applying gradients. Defaults to “Adam”.

参考:https://blog.csdn.net/xierhacker/article/details/53174558

猜你喜欢

转载自blog.csdn.net/MOU_IT/article/details/82416622