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


Python math_ops.accumulate_n函数代码示例

本文整理汇总了Python中tensorflow.python.ops.math_ops.accumulate_n函数的典型用法代码示例。如果您正苦于以下问题:Python accumulate_n函数的具体用法?Python accumulate_n怎么用?Python accumulate_n使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: testInt

 def testInt(self):
   np.random.seed(54321)
   x = [np.random.randint(-128, 128, (5, 4, 3, 2, 1)) for _ in range(6)]
   tf_x = ops.convert_n_to_tensor(x)
   with self.test_session(use_gpu=True):
     self.assertAllEqual(sum(x), math_ops.accumulate_n(tf_x).eval())
     self.assertAllEqual(x[0] * 6, math_ops.accumulate_n([tf_x[0]] * 6).eval())
开发者ID:LongJun123456,项目名称:tensorflow,代码行数:7,代码来源:math_ops_test.py

示例2: testFloat

 def testFloat(self):
   np.random.seed(12345)
   x = [np.random.random((1, 2, 3, 4, 5)) - 0.5 for _ in range(5)]
   tf_x = ops.convert_n_to_tensor(x)
   with self.test_session(use_gpu=True):
     self.assertAllClose(sum(x), math_ops.accumulate_n(tf_x).eval())
     self.assertAllClose(x[0] * 5, math_ops.accumulate_n([tf_x[0]] * 5).eval())
开发者ID:LongJun123456,项目名称:tensorflow,代码行数:7,代码来源:math_ops_test.py

示例3: testFloat

 def testFloat(self):
   np.random.seed(12345)
   x = [np.random.random((1, 2, 3, 4, 5)) - 0.5 for _ in range(5)]
   tf_x = ops.convert_n_to_tensor(x)
   self.assertAllClose(sum(x), math_ops.accumulate_n(tf_x))
   self.assertAllClose(x[0] * 5,
                       math_ops.accumulate_n([tf_x[0]] * 5))
开发者ID:AnishShah,项目名称:tensorflow,代码行数:7,代码来源:accumulate_n_eager_test.py

示例4: testFloat

 def testFloat(self):
   np.random.seed(12345)
   x = [np.random.random((1, 2, 3, 4, 5)) - 0.5 for _ in range(5)]
   tf_x = ops.convert_n_to_tensor(x)
   for u in tf_x:
     print("shape=%s" % u.get_shape())
   with self.test_session():
     self.assertAllClose(sum(x), math_ops.accumulate_n(tf_x).eval())
     self.assertAllClose(x[0] * 5, math_ops.accumulate_n([tf_x[0]] * 5).eval())
开发者ID:govindap,项目名称:tensorflow,代码行数:9,代码来源:math_ops_test.py

示例5: testGrad

 def testGrad(self):
   np.random.seed(42)
   for num_inputs in range(1, 10):
     with self.cached_session(use_gpu=True) as sess:
       input_vars = [
           variables.Variable(10.0 * np.random.random())
           for _ in range(0, num_inputs)
       ]
       accum_n = math_ops.accumulate_n(input_vars)
       sess.run(variables.global_variables_initializer())
       accum_n_grad = gradients.gradients(accum_n, input_vars)
       self.assertAllEqual(
           np.repeat(1.0, num_inputs),  # d/dx (x + y + ...) = 1
           [g.eval() for g in accum_n_grad])
开发者ID:bunbutter,项目名称:tensorflow,代码行数:14,代码来源:accumulate_n_test.py

示例6: testSimple

 def testSimple(self):
   with self.cached_session():
     random_arrays = [
         np.random.rand(16, 16, 16, 16).astype(np.float32) for _ in range(20)
     ]
     random_tensors = [
         ops.convert_to_tensor(x, dtype=dtypes_lib.float32)
         for x in random_arrays
     ]
     tf_val = math_ops.accumulate_n(random_tensors)
     np_val = random_arrays[0]
     for random_array in random_arrays[1:]:
       np_val += random_array
     self.assertAllClose(np_val, self.evaluate(tf_val))
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:14,代码来源:cwise_ops_test.py

示例7: testWrongTypeOneInput

 def testWrongTypeOneInput(self):
   # Scenario that used to trigger a bug, even when testWrongType() worked
   with self.cached_session():
     with self.assertRaises(TypeError):
       a = variables.Variable(0.2, dtype=np.float32)
       math_ops.accumulate_n([a], tensor_dtype=np.int32)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:6,代码来源:cwise_ops_test.py

示例8: testWrongType

 def testWrongType(self):
   with self.cached_session():
     with self.assertRaises(TypeError):
       a = variables.Variable(0.2, dtype=np.float32)
       b = variables.Variable(0.1, dtype=np.float32)
       math_ops.accumulate_n([a, b], tensor_dtype=np.int32)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:6,代码来源:cwise_ops_test.py

示例9: testWrongShape

 def testWrongShape(self):
   with self.cached_session():
     with self.assertRaises(ValueError):
       a = variables.Variable(0.2)
       b = variables.Variable(0.1)
       math_ops.accumulate_n([a, b], shape=[2, 2])  # Should be shape=[]
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:6,代码来源:cwise_ops_test.py

示例10: testZeroArgs

 def testZeroArgs(self):
   with self.cached_session():
     with self.assertRaises(ValueError):
       tf_val = math_ops.accumulate_n([])
       self.evaluate(tf_val)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:5,代码来源:cwise_ops_test.py

示例11: body_fn

 def body_fn(i, acc, tensors):
   return i + 1, acc + math_ops.accumulate_n(tensors), tensors
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:2,代码来源:accumulate_n_test.py

示例12: fn

 def fn(first, second, third):
   return math_ops.accumulate_n([first, second, third])
开发者ID:AnishShah,项目名称:tensorflow,代码行数:2,代码来源:accumulate_n_eager_test.py

示例13: testMinimalEagerMode

 def testMinimalEagerMode(self):
   forty = constant_op.constant(40)
   two = constant_op.constant(2)
   answer = math_ops.accumulate_n([forty, two])
   self.assertEqual(42, answer.numpy())
开发者ID:AnishShah,项目名称:tensorflow,代码行数:5,代码来源:accumulate_n_eager_test.py

示例14: testUnknownShape

 def testUnknownShape(self):
   with self.session(use_gpu=True):
     x0 = array_ops.placeholder(dtype=dtypes_lib.int32, shape=[None])
     acc = math_ops.accumulate_n([x0, x0], shape=[None])
     self.assertAllEqual([2, 4], acc.eval(feed_dict={x0: [1, 2]}))
开发者ID:bunbutter,项目名称:tensorflow,代码行数:5,代码来源:accumulate_n_test.py

示例15: testIncompatibleShapes

 def testIncompatibleShapes(self):
   with self.cached_session():
     with self.assertRaises(ValueError):
       a = variables.Variable(np.array([0.1, 0.2]))
       b = variables.Variable(np.array([[0.3], [0.4]]))
       math_ops.accumulate_n([a, b])
开发者ID:bunbutter,项目名称:tensorflow,代码行数:6,代码来源:accumulate_n_test.py


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