當前位置: 首頁>>代碼示例>>Python>>正文


Python training_ops.apply_adam方法代碼示例

本文整理匯總了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 
開發者ID:ChenglongChen,項目名稱:tensorflow-XNN,代碼行數:18,代碼來源:optimizer.py

示例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)) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:22,代碼來源:multistep_with_adamoptimizer.py

示例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 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:18,代碼來源:multistep_with_adamoptimizer.py

示例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 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:adam.py

示例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 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:15,代碼來源:nadam_optimizer.py

示例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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:33,代碼來源:training_ops_test.py

示例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 
開發者ID:chentingpc,項目名稱:NNCF,代碼行數:9,代碼來源:optimizer.py


注:本文中的tensorflow.python.training.training_ops.apply_adam方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。