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


Python control_flow_ops._Enter方法代碼示例

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


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

示例1: _ExitGrad

# 需要導入模塊: from tensorflow.python.ops import control_flow_ops [as 別名]
# 或者: from tensorflow.python.ops.control_flow_ops import _Enter [as 別名]
def _ExitGrad(op, grad):
  """Gradients for an exit op are calculated using an Enter op."""
  graph = ops.get_default_graph()
  # pylint: disable=protected-access
  grad_ctxt = graph._get_control_flow_context()
  # pylint: enable=protected-access
  if not grad_ctxt.back_prop:
    # The flag `back_prop` is set by users to suppress gradient
    # computation for this loop. If the attribute `back_prop` is false,
    # no gradient computation.
    return None

  # pylint: disable=protected-access
  if op._get_control_flow_context().grad_state:
    raise TypeError("Second-order gradient for while loops not supported.")
  # pylint: enable=protected-access

  if isinstance(grad, ops.Tensor):
    grad_ctxt.AddName(grad.name)
  else:
    if not isinstance(grad, (ops.IndexedSlices, sparse_tensor.SparseTensor)):
      raise TypeError("Type %s not supported" % type(grad))
    grad_ctxt.AddName(grad.values.name)
    grad_ctxt.AddName(grad.indices.name)
    dense_shape = grad.dense_shape
    if dense_shape is not None:
      grad_ctxt.AddName(dense_shape.name)
  grad_ctxt.Enter()
  # pylint: disable=protected-access
  result = control_flow_ops._Enter(
      grad, grad_ctxt.name, is_constant=False,
      parallel_iterations=grad_ctxt.parallel_iterations,
      name="b_exit")
  # pylint: enable=protected-access
  grad_ctxt.loop_enters.append(result)
  grad_ctxt.Exit()
  return result 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:39,代碼來源:control_flow_grad.py

示例2: _ExitGrad

# 需要導入模塊: from tensorflow.python.ops import control_flow_ops [as 別名]
# 或者: from tensorflow.python.ops.control_flow_ops import _Enter [as 別名]
def _ExitGrad(op, grad):
  """Gradients for an exit op are calculated using an Enter op."""
  graph = ops.get_default_graph()
  # pylint: disable=protected-access
  grad_ctxt = graph._get_control_flow_context()
  # pylint: enable=protected-access
  if not grad_ctxt.back_prop:
    # The flag `back_prop` is set by users to suppress gradient
    # computation for this loop. If the attribute `back_prop` is false,
    # no gradient computation.
    return None

  # pylint: disable=protected-access
  if op._get_control_flow_context().grad_state:
    raise TypeError("Second-order gradient for while loops not supported.")
  # pylint: enable=protected-access

  if isinstance(grad, ops.Tensor):
    grad_ctxt.AddName(grad.name)
  else:
    if not isinstance(grad, (ops.IndexedSlices, sparse_tensor.SparseTensor)):
      raise TypeError("Type %s not supported" % type(grad))
    grad_ctxt.AddName(grad.values.name)
    grad_ctxt.AddName(grad.indices.name)
    dense_shape = grad.dense_shape
    if dense_shape is not None:
      grad_ctxt.AddName(dense_shape.name)
  enter_fn = control_flow_ops._Enter  # pylint: disable=protected-access
  grad_ctxt.Enter()
  result = enter_fn(grad, grad_ctxt.name, is_constant=False,
                    parallel_iterations=grad_ctxt.parallel_iterations,
                    name="b_exit")
  grad_ctxt.Exit()
  return result 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:36,代碼來源:control_flow_grad.py

示例3: testRefEnter

# 需要導入模塊: from tensorflow.python.ops import control_flow_ops [as 別名]
# 或者: from tensorflow.python.ops.control_flow_ops import _Enter [as 別名]
def testRefEnter(self):
    with self.test_session():
      v = tf.Variable(7)

      enter_v = control_flow_ops._Enter(v, "foo_1", is_constant=True)
      nine = tf.constant(9)
      enter_nine = control_flow_ops.enter(nine, "foo_1")
      op = tf.assign(enter_v, enter_nine)
      v2 = control_flow_ops.with_dependencies([op], enter_v)
      v3 = control_flow_ops.exit(v2)
      tf.global_variables_initializer().run()
      self.assertEqual(9, v3.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:14,代碼來源:control_flow_ops_py_test.py

示例4: _ExitGrad

# 需要導入模塊: from tensorflow.python.ops import control_flow_ops [as 別名]
# 或者: from tensorflow.python.ops.control_flow_ops import _Enter [as 別名]
def _ExitGrad(op, grad):
  """Gradients for an exit op are calculated using an Enter op."""
  graph = ops.get_default_graph()
  # pylint: disable=protected-access
  grad_ctxt = graph._get_control_flow_context()
  # pylint: enable=protected-access
  if not grad_ctxt.back_prop:
    # The flag `back_prop` is set by users to suppress gradient
    # computation for this loop. If the attribute `back_prop` is false,
    # no gradient computation.
    return None

  # pylint: disable=protected-access
  if op._get_control_flow_context().grad_state:
    raise TypeError("Second-order gradient for while loops not supported.")
  # pylint: enable=protected-access

  if isinstance(grad, ops.Tensor):
    grad_ctxt.AddName(grad.name)
  else:
    if not isinstance(grad, (ops.IndexedSlices, sparse_tensor.SparseTensor)):
      raise TypeError("Type %s not supported" % type(grad))
    grad_ctxt.AddName(grad.values.name)
    grad_ctxt.AddName(grad.indices.name)
    if isinstance(grad, ops.IndexedSlices):
      dense_shape = grad.dense_shape
    else:
      dense_shape = grad.shape
    if dense_shape is not None:
      grad_ctxt.AddName(dense_shape.name)
  enter_fn = control_flow_ops._Enter  # pylint: disable=protected-access
  grad_ctxt.Enter()
  result = enter_fn(grad, grad_ctxt.name, is_constant=False,
                    parallel_iterations=grad_ctxt.parallel_iterations,
                    name="b_exit")
  grad_ctxt.Exit()
  return result 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:39,代碼來源:control_flow_grad.py


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