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


Python tensorflow.ConditionalAccumulator方法代码示例

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


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

示例1: testConstructorWithShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testConstructorWithShape(self):
    with tf.Graph().as_default():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1, 5, 2, 8]))
    self.assertTrue(isinstance(q.accumulator_ref, tf.Tensor))
    self.assertEquals(tf.string_ref, q.accumulator_ref.dtype)
    self.assertProtoEquals("""
      name:'Q' op:'ConditionalAccumulator'
      attr { key: 'dtype' value { type: DT_FLOAT } }
      attr { key: 'shape' value { shape { dim {size: 1 }
                                          dim {size: 5 }
                                          dim {size: 2 }
                                          dim {size: 8 }
      } } }
      attr { key: 'container' value { s: '' } }
      attr { key: 'shared_name' value { s: '' } }
      """, q.accumulator_ref.op.node_def) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:conditional_accumulator_test.py

示例2: testAccumulatorMultipleAccumulators

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorMultipleAccumulators(self):
    with self.test_session():
      q_f32_0 = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      q_f32_1 = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      q_f16_0 = tf.ConditionalAccumulator(
          tf.float16, name="Q", shape=tf.TensorShape([1]))
      q_f16_1 = tf.ConditionalAccumulator(
          tf.float16, name="Q", shape=tf.TensorShape([1]))

      accums = [q_f16_0, q_f16_1, q_f32_0, q_f32_1]
      for i in range(len(accums)):
        accums[i].apply_grad((i + 10.0,)).run()

      for i in range(len(accums)):
        result = accums[i].take_grad(1).eval()
        self.assertEqual(result, i + 10.0) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:conditional_accumulator_test.py

示例3: testAccumulatorApplyAndTakeGradWithShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorApplyAndTakeGradWithShape(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(tf.float32, name="Q", shape=(3, 2))
      elems = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]],
               [[10.0, 20.0], [30.0, 40.0], [50.0, 60.0]]]
      elems_ave = [[(a + b) / len(elems) for a, b in zip(x, y)]
                   for x, y in zip(elems[0], elems[1])]
      accum_ops = [q.apply_grad(x) for x in elems]
      takeg_t = q.take_grad(1)

      for accum_op in accum_ops:
        accum_op.run()

      is_all_equal = True
      val = takeg_t.eval()
      for i in range(len(val)):
        for j in range(len(val[i])):
          is_all_equal &= (val[i][j] == elems_ave[i][j])
      self.assertTrue(is_all_equal) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:conditional_accumulator_test.py

示例4: testAccumulatorDynamicShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorDynamicShape(self):
    with self.test_session() as sess:
      q = tf.ConditionalAccumulator(tf.float32, name="Q", shape=None)

      x = tf.placeholder(tf.float32)

      accum_op = q.apply_grad(x)

      elems = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]],
               [[10.0, 20.0], [30.0, 40.0], [50.0, 60.0]]]
      elems_ave = [[(a + b) / len(elems) for a, b in zip(c, d)]
                   for c, d in zip(elems[0], elems[1])]
      takeg_t = q.take_grad(1)

      for elem in elems:
        sess.run(accum_op, feed_dict={x: elem})

      is_all_equal = True
      val = takeg_t.eval()
      for i in range(len(val)):
        for j in range(len(val[i])):
          is_all_equal &= (val[i][j] == elems_ave[i][j])
      self.assertTrue(is_all_equal) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:conditional_accumulator_test.py

示例5: testAccumulatorWrongDynamicShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorWrongDynamicShape(self):
    with self.test_session() as sess:
      q = tf.ConditionalAccumulator(tf.float32, name="Q", shape=None)

      x = tf.placeholder(tf.float32)

      accum_op = q.apply_grad(x)

      # First successful apply_grad determines shape
      sess.run(accum_op, feed_dict={x: [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]})

      with self.assertRaises(tf.errors.InvalidArgumentError):
        sess.run(accum_op, feed_dict={x: [[1.0, 2.0], [3.0, 4.0]]})

      with self.assertRaises(tf.errors.InvalidArgumentError):
        sess.run(accum_op, feed_dict={x: [[1.0], [2.0], [3.0]]}) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:conditional_accumulator_test.py

示例6: testAccumulatorTakeGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorTakeGrad(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      elems = [10.0, 20.0]
      elems_ave = sum(elems) / len(elems)

      accum_ops = [q.apply_grad((x,), local_step=0) for x in elems]
      takeg_t = q.take_grad(1)

      for accum_op in accum_ops:
        accum_op.run()

      val = takeg_t.eval()
      self.assertEqual(elems_ave, val)

      accum_ops = [q.apply_grad((x,), local_step=1) for x in elems]
      takeg_t = q.take_grad(tf.constant(1))

      for accum_op in accum_ops:
        accum_op.run()

      val = takeg_t.eval()
      self.assertEqual(elems_ave, val) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:conditional_accumulator_test.py

示例7: testParallelApplyGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testParallelApplyGrad(self):
    with self.test_session() as sess:
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      elems = [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0]
      accum_ops = [q.apply_grad((x,), local_step=0) for x in elems]
      takeg_t = q.take_grad(1)

      def apply_grad(accum_op):
        sess.run(accum_op)

      threads = [self.checkedThread(
          target=apply_grad, args=(o,)) for o in accum_ops]

      for thread in threads:
        thread.start()
      for thread in threads:
        thread.join()

      val = takeg_t.eval()

      self.assertEqual(val, sum(elems) / len(elems)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:conditional_accumulator_test.py

示例8: testAccumulatorCancel

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorCancel(self):
    with self.test_session() as sess:
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      takeg_t = q.take_grad(1)

      takeg_thread = self.checkedThread(
          self._blocking_takeg, args=(sess, takeg_t))

      takeg_thread.start()

      time.sleep(1.0)

      sess.close()  # Will cancel blocked operation

      takeg_thread.join() 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:conditional_accumulator_test.py

示例9: testConstructor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testConstructor(self):
    with tf.Graph().as_default():
      q = tf.ConditionalAccumulator(tf.float32, name="Q")
    self.assertTrue(isinstance(q.accumulator_ref, tf.Tensor))
    self.assertEquals(tf.string_ref, q.accumulator_ref.dtype)
    self.assertProtoEquals("""
      name:'Q' op:'ConditionalAccumulator'
      attr { key: 'dtype' value { type: DT_FLOAT } }
      attr { key: 'shape' value { shape { unknown_rank: true} } }
      attr { key: 'container' value { s: '' } }
      attr { key: 'shared_name' value { s: '' } }
      """, q.accumulator_ref.op.node_def) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:conditional_accumulator_test.py

示例10: testAccumulatorSizeEmpty

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorSizeEmpty(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(tf.float32, name="Q")
      self.assertEqual(q.num_accumulated().eval(), 0) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:6,代码来源:conditional_accumulator_test.py

示例11: testAccumulatorSetGlobalStep

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorSetGlobalStep(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      set_global_step_op = q.set_global_step(1)
      set_global_step_op.run() 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:conditional_accumulator_test.py

示例12: testAccumulatorApplyGradFloat32

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorApplyGradFloat32(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      accum_op = q.apply_grad((10.0,))
      accum_op.run() 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:conditional_accumulator_test.py

示例13: testAccumulatorApplyGradWithWrongShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorApplyGradWithWrongShape(self):
    q = tf.ConditionalAccumulator(tf.float32, name="Q", shape=(3, 2))

    with self.assertRaises(ValueError):
      q.apply_grad([[1.0, 2.0], [3.0, 4.0]])

    with self.assertRaises(ValueError):
      q.apply_grad([[1.0], [2.0], [3.0]]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:10,代码来源:conditional_accumulator_test.py

示例14: testAccumulatorSizeAfterApplyGradAndTakeGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorSizeAfterApplyGradAndTakeGrad(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      accum_op = q.apply_grad((10.0,))
      extract_t = q.take_grad(2)

      # Applying gradient multiple times to increase size from 0 to 2.
      self.assertEqual(q.num_accumulated().eval(), 0)
      accum_op.run()
      self.assertEqual(q.num_accumulated().eval(), 1)
      accum_op.run()
      self.assertEqual(q.num_accumulated().eval(), 2)

      # Extract will reduce size to 0
      extract_t.op.run()
      self.assertEqual(q.num_accumulated().eval(), 0)

      # Take gradients always sets the size back to 0 if successful.
      accum_op = q.apply_grad((10.0,), local_step=1)
      accum_op.run()
      accum_op.run()
      accum_op.run()
      accum_op.run()
      self.assertEqual(q.num_accumulated().eval(), 4)
      extract_t.op.run()
      self.assertEqual(q.num_accumulated().eval(), 0) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:29,代码来源:conditional_accumulator_test.py

示例15: testAccumulatorInvalidTakeGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ConditionalAccumulator [as 别名]
def testAccumulatorInvalidTakeGrad(self):
    with self.test_session():
      q = tf.ConditionalAccumulator(
          tf.float32, name="Q", shape=tf.TensorShape([1]))
      elems = [10.0, 20.0]
      accum_ops = [q.apply_grad((x,)) for x in elems]

      takeg_t = q.take_grad(-1)

      for accum_op in accum_ops:
        accum_op.run()

      with self.assertRaises(tf.errors.InvalidArgumentError):
        takeg_t.eval() 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:16,代码来源:conditional_accumulator_test.py


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