当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.foldr方法代码示例

本文整理汇总了Python中tensorflow.foldr方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.foldr方法的具体用法?Python tensorflow.foldr怎么用?Python tensorflow.foldr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.foldr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testFoldr_Scoped

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import foldr [as 别名]
def testFoldr_Scoped(self):
    with self.test_session() as sess:
      with tf.variable_scope("root") as varscope:
        elems = tf.constant([1, 2, 3, 4, 5, 6], name="data")

        r = tf.foldr(simple_scoped_fn, elems)
        # Check that we have the one variable we asked for here.
        self.assertEqual(len(tf.trainable_variables()), 1)
        self.assertEqual(tf.trainable_variables()[0].name, "root/body/two:0")
        sess.run([tf.global_variables_initializer()])
        self.assertAllEqual(450, r.eval())

        # Now let's reuse our single variable.
        varscope.reuse_variables()
        r = tf.foldr(simple_scoped_fn, elems, initializer=10)
        self.assertEqual(len(tf.trainable_variables()), 1)
        self.assertAllEqual(1282, r.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:functional_ops_test.py

示例2: foldr

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import foldr [as 别名]
def foldr(fn, elems, initializer=None, name=None):
    """Reduce elems using fn to combine them from right to left.

    # Arguments
        fn: Callable that will be called upon each element in elems and an
            accumulator, for instance `lambda acc, x: acc + x`
        elems: tensor
        initializer: The first value used (`elems[-1]` in case of None)
        name: A string name for the foldr node in the graph

    # Returns
        Tensor with same type and shape as `initializer`.
    """
    return tf.foldr(fn, elems, initializer=initializer, name=name) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:tensorflow_backend.py

示例3: testFoldr_Simple

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import foldr [as 别名]
def testFoldr_Simple(self):
    with self.test_session():
      elems = tf.constant([1, 2, 3, 4, 5, 6], name="data")

      r = tf.foldr(lambda a, x: tf.mul(tf.add(a, x), 2), elems)
      self.assertAllEqual(450, r.eval())

      r = tf.foldr(
          lambda a, x: tf.mul(tf.add(a, x), 2), elems, initializer=10)
      self.assertAllEqual(1282, r.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:functional_ops_test.py

示例4: testFold_Grad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import foldr [as 别名]
def testFold_Grad(self):
    with self.test_session():
      elems = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name="data")
      v = tf.constant(2.0, name="v")

      r = tf.foldl(
          lambda a, x: tf.mul(a, x), elems, initializer=v)
      r = tf.gradients(r, v)[0]
      self.assertAllEqual(720.0, r.eval())

      r = tf.foldr(
          lambda a, x: tf.mul(a, x), elems, initializer=v)
      r = tf.gradients(r, v)[0]
      self.assertAllEqual(720.0, r.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:16,代码来源:functional_ops_test.py


注:本文中的tensorflow.foldr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。