您当前位置: 主页 > 天富APP下载
作者:佚名
2024-03-12 12:04 浏览: 分类:天富APP下载

tensorflow之Optimizers(tensorflow的优化器)

一.概述

1.默认情况下,优化器训练目标函数所依赖的所有可训练变量。如果你不想训练某一个变量,你可以将关键词trainable设置为False。举例如下:

 

2.tf.Variable类的完全定义

tf.Variable(initial_value=None, trainable=True, collections=None,validate_shape=True, caching_device=None, name=None, variable_def=None, dtype=None,expected_shape=None, import_scope=None)

3.可以要求优化器采用特定变量的渐变,也可以修改优化程序计算的渐变

 

4.更底层的功能

 

格式:

tf.gradients(ys,xs,?grad_ys=None,?name='gradients',colocate_gradients_with_ops=False,gate_gradients=False,aggregation_method=None,stop_gradients=None)
解释说明:

对求导函数而言,其主要功能即求导公式:?y/?x。在tensorflow中,y和x都是tensor。

接受求导值和不仅可以是tensor,还可以是list,形如[tensor1, tensor2, …, tensorn]。当和都是list时,它们的求导关系为:

  • 实现对求导
  • 求导返回值是一个list,list的长度等于
  • 假设返回值是[grad1, grad2, grad3],=[y1, y2],=[x1, x2, x3]。则,真实的计算过程为:?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

在仅训练模型的某些部分时,这尤其有用。

5.更多的Optimizer

  • tf.train.GradientDescentOptimizer
  • tf.train.AdadeltaOptimizer
  • tf.train.AdagradOptimizer
  • tf.train.AdagradDAOptimizer
  • tf.train.MomentumOptimizer
  • tf.train.AdamOptimizer
  • tf.train.FtrlOptimizer
  • tf.train.ProximalGradientDescentOptimizer
  • tf.train.ProximalAdagradOptimizer
  • tf.train.RMSPropOptimizer

使用结论:RMSprop is an extension of Adagrad that deals with its radically diminishing learning rates. It is identical to Adadelta, except that Adadelta uses the RMS of parameter updates in the numerator update rule. Adam, finally, adds bias-correction and momentum to RMSprop. Insofar,RMSprop, Adadelta, and Adam are very similar algorithms that do well in similar circumstances.Kingma et al. [15] show that its bias-correction helps Adam slightly outperform RMSprop towards the end of optimization as gradients become sparser. Insofar, Adam might be the best overall choice.

推荐:使用AdamOptimizer

二.代码实例与说明

?

手赚资讯
安卓赚钱苹果赚钱
阅读头条转发赚钱

平台注册入口