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


Python tensorflow.Optimizer方法代碼示例

本文整理匯總了Python中tensorflow.Optimizer方法的典型用法代碼示例。如果您正苦於以下問題:Python tensorflow.Optimizer方法的具體用法?Python tensorflow.Optimizer怎麽用?Python tensorflow.Optimizer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.Optimizer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _optimize_clone

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import Optimizer [as 別名]
def _optimize_clone(optimizer, clone, num_clones, regularization_losses,
                    **kwargs):
  """Compute losses and gradients for a single clone.

  Args:
    optimizer: A tf.Optimizer  object.
    clone: A Clone namedtuple.
    num_clones: The number of clones being deployed.
    regularization_losses: Possibly empty list of regularization_losses
      to add to the clone losses.
    **kwargs: Dict of kwarg to pass to compute_gradients().

  Returns:
    A tuple (clone_loss, clone_grads_and_vars).
      - clone_loss: A tensor for the total loss for the clone.  Can be None.
      - clone_grads_and_vars: List of (gradient, variable) for the clone.
        Can be empty.
  """
  sum_loss = _gather_clone_loss(clone, num_clones, regularization_losses)
  clone_grad = None
  if sum_loss is not None:
    with tf.device(clone.device):
      clone_grad = optimizer.compute_gradients(sum_loss, **kwargs)
  return sum_loss, clone_grad 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:26,代碼來源:model_deploy.py

示例2: _optimize_clone

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import Optimizer [as 別名]
def _optimize_clone(optimizer, clone, num_clones, regularization_losses,
                    **kwargs):
  """Compute losses and gradients for a single clone.

  Args:
    optimizer: A tf.Optimizer  object.
    clone: A Clone namedtuple.
    num_clones: The number of clones being deployed.
    regularization_losses: Possibly empty list of regularization_losses
      to add to the clone losses.
    **kwargs: Dict of kwarg to pass to compute_gradients().

  Returns:
    A tuple (clone_loss, clone_grads_and_vars).
      - clone_loss: A tensor for the total loss for the clone.  Can be None.
      - clone_grads_and_vars: List of (gradient, variable) for the clone.
        Can be empty.
  """
  sum_loss = _gather_clone_loss(clone, num_clones, regularization_losses)
  clone_grad = None
  if sum_loss is not None:
    with tf.device(clone.device):
      clone_grad = optimizer.compute_gradients(sum_loss+clone.reg_loss, **kwargs)
  return sum_loss, clone_grad 
開發者ID:google-research,項目名稱:morph-net,代碼行數:26,代碼來源:model_deploy.py

示例3: compute_gradients

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import Optimizer [as 別名]
def compute_gradients(self, *args, **kwargs):
        """Compute gradients of all trainable variables.

        See Optimizer.compute_gradients() for more info.

        In DistributedOptimizer, compute_gradients() is overriden to also
        allreduce the gradients before returning them.
        """
        gradients = self._optimizer.compute_gradients(*args, **kwargs)
        if size() > 1:
            averaged_gradients = []
            with tf.name_scope(self._name + "_Allreduce"):
                for grad, var in gradients:
                    if grad is not None:
                        avg_grad = allreduce(grad,
                                             device_dense=self._device_dense,
                                             device_sparse=self._device_sparse,
                                             compression=self._compression)
                        averaged_gradients.append((avg_grad, var))
                    else:
                        averaged_gradients.append((None, var))
            return averaged_gradients
        else:
            return gradients 
開發者ID:mlperf,項目名稱:training_results_v0.6,代碼行數:26,代碼來源:__init__.py

示例4: _optimize_clone

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import Optimizer [as 別名]
def _optimize_clone(optimizer, clone, num_clones, regularization_losses,
                    **kwargs):
    """Compute losses and gradients for a single clone.

    Args:
      optimizer: A tf.Optimizer  object.
      clone: A Clone namedtuple.
      num_clones: The number of clones being deployed.
      regularization_losses: Possibly empty list of regularization_losses
        to add to the clone losses.
      **kwargs: Dict of kwarg to pass to compute_gradients().

    Returns:
      A tuple (clone_loss, clone_grads_and_vars).
        - clone_loss: A tensor for the total loss for the clone.  Can be None.
        - clone_grads_and_vars: List of (gradient, variable) for the clone.
          Can be empty.
    """
    sum_loss = _gather_clone_loss(clone, num_clones, regularization_losses)
    clone_grad = None
    if sum_loss is not None:
        with tf.device(clone.device):
            clone_grad = optimizer.compute_gradients(sum_loss, **kwargs)
    return sum_loss, clone_grad 
開發者ID:YingZhangDUT,項目名稱:Cross-Modal-Projection-Learning,代碼行數:26,代碼來源:model_deploy.py


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