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


Python functional_ops._symbolic_gradient方法代碼示例

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


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

示例1: testGradientFunc

# 需要導入模塊: from tensorflow.python.ops import functional_ops [as 別名]
# 或者: from tensorflow.python.ops.functional_ops import _symbolic_gradient [as 別名]
def testGradientFunc(self):

    @function.Defun(tf.float32, func_name="XSquarePlusOneFn")
    def XSquarePlusOne(x):
      return x * x + 1.0

    @function.Defun(tf.float32, tf.float32)
    def XSquarePlusOneGrad(x, dy):
      dx = functional_ops._symbolic_gradient(
          input=[x, dy], Tout=[tf.float32], f="XSquarePlusOneFn", name="dx")
      return dx

    g = tf.Graph()
    with g.as_default():
      call_f = XSquarePlusOne([2.0])
      call_g = XSquarePlusOneGrad([2.0], [0.1])

      with tf.Session() as sess:
        self.assertAllClose([5.0], sess.run(call_f))
        self.assertAllClose([0.4], sess.run(call_g)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:22,代碼來源:function_test.py

示例2: _SymGrad

# 需要導入模塊: from tensorflow.python.ops import functional_ops [as 別名]
# 或者: from tensorflow.python.ops.functional_ops import _symbolic_gradient [as 別名]
def _SymGrad(op, out_grads):
  """Backprop through a function call node op given its outputs' gradients."""
  f_in = [x for x in op.inputs] + out_grads
  f_types = [x.dtype for x in op.inputs]
  f = attr_value_pb2.NameAttrList()
  f.name = op.type
  for k in op.node_def.attr:
    f.attr[k].CopyFrom(op.node_def.attr[k])
  # pylint: disable=protected-access
  in_grads = functional_ops._symbolic_gradient(input=f_in, Tout=f_types, f=f)
  # pylint: enable=protected-access
  return in_grads 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:gradients_impl.py

示例3: testSymGradShape

# 需要導入模塊: from tensorflow.python.ops import functional_ops [as 別名]
# 或者: from tensorflow.python.ops.functional_ops import _symbolic_gradient [as 別名]
def testSymGradShape(self):
    g = tf.Graph()
    with g.as_default():
      x = tf.placeholder(tf.float32, [25, 4])
      y = tf.placeholder(tf.float32, [200, 100])
      dz = tf.placeholder(tf.float32, [1])
      # We assume Foo is a function of (x, y) -> (z) Then, Foo's
      # gradient function is (x, y, dz) -> (dx, dy).  dx's shape
      # should be the same as x's; and dy's shape should be the same
      # as y's.
      dx, dy = functional_ops._symbolic_gradient(
          input=[x, y, dz], Tout=[tf.float32] * 2, f="Foo")
      self.assertEqual(x.get_shape(), dx.get_shape())
      self.assertEqual(y.get_shape(), dy.get_shape()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:function_test.py


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