本文整理汇总了Python中tensorflow.python.training.training_ops.apply_adam方法的典型用法代码示例。如果您正苦于以下问题:Python training_ops.apply_adam方法的具体用法?Python training_ops.apply_adam怎么用?Python training_ops.apply_adam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.training.training_ops
的用法示例。
在下文中一共展示了training_ops.apply_adam方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_dense(self, grad, var):
m = self.get_slot(var, "m")
v = self.get_slot(var, "v")
return training_ops.apply_adam(
var,
m,
v,
math_ops.cast(self._beta1_power, var.dtype.base_dtype),
math_ops.cast(self._beta2_power, var.dtype.base_dtype),
math_ops.cast(self._lr_t, var.dtype.base_dtype),
math_ops.cast(self._beta1_t, var.dtype.base_dtype),
math_ops.cast(self._beta2_t, var.dtype.base_dtype),
math_ops.cast(self._epsilon_t, var.dtype.base_dtype),
grad,
use_locking=self._use_locking,
use_nesterov=True).op
示例2: _apply_cond
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_cond(self, apply_fn, grad, var, *args, **kwargs):
"""Apply conditionally if counter is zero."""
grad_acc = self.get_slot(var, "grad_acc")
def apply_adam(grad_acc, apply_fn, grad, var, *args, **kwargs):
total_grad = (grad_acc + grad) / tf.cast(self._n_t, grad.dtype)
adam_op = apply_fn(total_grad, var, *args, **kwargs)
with tf.control_dependencies([adam_op]):
grad_acc_to_zero_op = grad_acc.assign(
tf.zeros_like(grad_acc), use_locking=self._use_locking)
return tf.group(adam_op, grad_acc_to_zero_op)
def accumulate_gradient(grad_acc, grad):
assign_op = tf.assign_add(grad_acc, grad, use_locking=self._use_locking)
return tf.group(assign_op) # Strip return value
return tf.cond(
tf.equal(self._get_iter_variable(), 0),
lambda: apply_adam(grad_acc, apply_fn, grad, var, *args, **kwargs),
lambda: accumulate_gradient(grad_acc, grad))
示例3: _apply_dense_in_action
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_dense_in_action(self, grad, var):
m = self.get_slot(var, "m")
v = self.get_slot(var, "v")
beta1_power, beta2_power = self._get_beta_accumulators()
return training_ops.apply_adam(
var,
m,
v,
tf.cast(beta1_power, var.dtype.base_dtype),
tf.cast(beta2_power, var.dtype.base_dtype),
tf.cast(self._lr_t, var.dtype.base_dtype),
tf.cast(self._beta1_t, var.dtype.base_dtype),
tf.cast(self._beta2_t, var.dtype.base_dtype),
tf.cast(self._epsilon_t, var.dtype.base_dtype),
grad,
use_locking=self._use_locking).op
示例4: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_dense(self, grad, var):
m = self.get_slot(var, "m")
v = self.get_slot(var, "v")
return training_ops.apply_adam(
var, m, v,
math_ops.cast(self._beta1_power, var.dtype.base_dtype),
math_ops.cast(self._beta2_power, var.dtype.base_dtype),
math_ops.cast(self._lr_t, var.dtype.base_dtype),
math_ops.cast(self._beta1_t, var.dtype.base_dtype),
math_ops.cast(self._beta2_t, var.dtype.base_dtype),
math_ops.cast(self._epsilon_t, var.dtype.base_dtype),
grad, use_locking=self._use_locking).op
示例5: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_dense(self, grad, var):
m = self.get_slot(var, "m")
v = self.get_slot(var, "v")
return training_ops.apply_adam(
var, m, v,
math_ops.cast(self._beta1_power, var.dtype.base_dtype),
math_ops.cast(self._beta2_power, var.dtype.base_dtype),
math_ops.cast(self._lr_t, var.dtype.base_dtype),
math_ops.cast(self._beta1_t, var.dtype.base_dtype),
math_ops.cast(self._beta2_t, var.dtype.base_dtype),
math_ops.cast(self._epsilon_t, var.dtype.base_dtype),
grad, use_locking=self._use_locking,
use_nesterov=True).op
示例6: _testTypesForAdam
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _testTypesForAdam(self, var, m, v, grad, use_gpu):
self.setUp()
with self.test_session(use_gpu=use_gpu):
var_t = variables.Variable(var)
m_t = variables.Variable(m)
v_t = variables.Variable(v)
t = 1
beta1 = np.array(0.9, dtype=var.dtype)
beta2 = np.array(0.999, dtype=var.dtype)
beta1_power = beta1**t
beta2_power = beta2**t
lr = np.array(0.001, dtype=var.dtype)
epsilon = np.array(1e-8, dtype=var.dtype)
beta1_t = constant_op.constant(beta1, self._toType(var.dtype), [])
beta2_t = constant_op.constant(beta2, self._toType(var.dtype), [])
beta1_power_t = variables.Variable(beta1_power)
beta2_power_t = variables.Variable(beta2_power)
lr_t = constant_op.constant(lr, self._toType(var.dtype), [])
epsilon_t = constant_op.constant(epsilon, self._toType(var.dtype), [])
variables.global_variables_initializer().run()
self.assertAllCloseAccordingToType(var, var_t.eval())
new_var, _, _ = self._adamUpdateNumpy(var, grad, t, m, v,
lr, beta1, beta2, epsilon)
apply_adam = training_ops.apply_adam(var_t, m_t, v_t, beta1_power_t,
beta2_power_t, lr_t,
beta1_t, beta2_t, epsilon_t, grad)
out = apply_adam.eval()
self.assertShapeEqual(out, apply_adam)
self.assertAllCloseAccordingToType(new_var, out)
示例7: _apply_dense
# 需要导入模块: from tensorflow.python.training import training_ops [as 别名]
# 或者: from tensorflow.python.training.training_ops import apply_adam [as 别名]
def _apply_dense(self, grad, var):
m = self.get_slot(var, "m")
v = self.get_slot(var, "v")
return training_ops.apply_adam(
var, m, v, self._beta1_power, self._beta2_power,
self._lr_t, self._beta1_t, self._beta2_t,
self._epsilon_t, grad, use_locking=self._use_locking).op