本文整理汇总了Python中tensorflow.python.training.training_ops.apply_gradient_descent方法的典型用法代码示例。如果您正苦于以下问题:Python training_ops.apply_gradient_descent方法的具体用法?Python training_ops.apply_gradient_descent怎么用?Python training_ops.apply_gradient_descent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.training.training_ops
的用法示例。
在下文中一共展示了training_ops.apply_gradient_descent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_gradient_descent [as 别名]
def _apply_dense(self, grad, var):
momentum_buffer = self.get_slot(var, "momentum")
learning_rate = math_ops.cast(self._learning_rate_tensor, var.dtype.base_dtype)
momentum = math_ops.cast(self._momentum_tensor, var.dtype.base_dtype)
nu = math_ops.cast(self._nu_tensor, var.dtype.base_dtype)
momentum_op = training_ops.apply_momentum(
var,
momentum_buffer,
nu * (1.0 - momentum) * learning_rate,
grad,
momentum,
use_locking=self._use_locking,
use_nesterov=False,
).op
with ops.control_dependencies([momentum_op]):
gd_op = training_ops.apply_gradient_descent(
var, (1.0 - nu) * learning_rate, grad, use_locking=self._use_locking
).op
return control_flow_ops.group(momentum_op, gd_op)
示例2: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_gradient_descent [as 别名]
def _apply_dense(self, grad, var):
return training_ops.apply_gradient_descent(
var,
math_ops.cast(self._learning_rate_tensor, var.dtype.base_dtype),
grad,
use_locking=self._use_locking).op
示例3: _testTypes
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_gradient_descent [as 别名]
def _testTypes(self, x, alpha, delta, use_gpu=None):
self.setUp()
with self.test_session(use_gpu=use_gpu):
var = variables.Variable(x)
variables.global_variables_initializer().run()
self.assertAllCloseAccordingToType(x, var.eval())
apply_sgd = training_ops.apply_gradient_descent(var, alpha, delta)
out = apply_sgd.eval()
self.assertShapeEqual(out, apply_sgd)
self.assertAllCloseAccordingToType(x - alpha * delta, out)