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


Python gen_array_ops._ref_identity方法代码示例

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


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

示例1: testUninitializedRefIdentity

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def testUninitializedRefIdentity(self):
    with self.test_session() as sess:
      v = gen_state_ops._variable(shape=[1], dtype=tf.float32, 
          name="v", container="", shared_name="")      
      inited = state_ops.is_variable_initialized(v)
      v_f, v_t = control_flow_ops.ref_switch(v, inited)
      # Both v_f and v_t are uninitialized references. However, an actual use
      # of the reference in the 'true' branch in the 'tf.identity' op will
      # not 'fire' when v is uninitialized, so this is a valid construction.
      # This test tests that _ref_identity allows uninitialized ref as input
      # so that this construction is allowed.
      v_f_op = gen_array_ops._ref_identity(v_f)
      v_t_op = gen_array_ops._ref_identity(v_t)
      with tf.control_dependencies([v_f_op]):
        assign_v = tf.assign(v, [1.0])
      with tf.control_dependencies([v_t_op]):
        orig_v = tf.identity(v)
      merged_op = control_flow_ops.merge([assign_v, orig_v])
      self.assertAllEqual([1.0], sess.run(merged_op.output)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:control_flow_ops_py_test.py

示例2: testWhileWithRefs_1

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def testWhileWithRefs_1(self):
    with self.test_session() as sess:
      x = tf.Variable(0).ref()
      i = tf.constant(0)
      c = lambda i, x: tf.less(i, 100)

      self.assertEqual(x.dtype, tf.int32_ref)

      def b(i, x):
        self.assertEqual(x.dtype, tf.int32_ref)
        return (i+1, gen_array_ops._ref_identity(x))

      r = tf.while_loop(c, b, [i, x], parallel_iterations=5)

      tf.global_variables_initializer().run()

      self.assertEqual(r[0].dtype, tf.int32)
      self.assertEqual(r[1].dtype, tf.int32_ref)

      value_i, value_x = sess.run(r)

    self.assertEqual(100, value_i)
    self.assertEqual(0, value_x) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:control_flow_ops_py_test.py

示例3: _Identity

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def _Identity(data, name=None):
  """Return a tensor with the same shape and contents as the input tensor.

  Args:
    data: A Tensor.
    name: A name for this operation (optional).

  Returns:
    A Tensor with the same type and value as the input Tensor.
  """
  data = ops.internal_convert_to_tensor_or_indexed_slices(data, as_ref=True)
  if isinstance(data, ops.Tensor):
    if data.dtype._is_ref_dtype:  # pylint: disable=protected-access
      return gen_array_ops._ref_identity(data, name=name)
    else:
      return array_ops.identity(data, name=name)
  else:
    if not isinstance(data, (ops.IndexedSlices, sparse_tensor.SparseTensor)):
      raise TypeError("Type %s not supported" % type(data))
    values = _Identity(data.values, name=name)
    indices = array_ops.identity(data.indices, name="indices")
    if isinstance(data, ops.IndexedSlices):
      dense_shape = data.dense_shape
      if dense_shape is not None:
        dense_shape = array_ops.identity(dense_shape, name="dense_shape")
      return ops.IndexedSlices(values, indices, dense_shape)
    else:
      dense_shape = array_ops.identity(data.dense_shape, name="dense_shape")
      return sparse_tensor.SparseTensor(indices, values, dense_shape) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:31,代码来源:control_flow_ops.py

示例4: testWhileWithRefsWithGradients_1

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def testWhileWithRefsWithGradients_1(self):
    with self.test_session() as sess:
      x = tf.Variable(0).ref()
      i = tf.constant(0)
      c = lambda i, x: tf.less(i, 10)

      self.assertEqual(x.dtype, tf.int32_ref)

      # pylint: disable=protected-access
      def body(i, x):
        self.assertEqual(x.dtype, tf.int32_ref)
        return [i+1, gen_array_ops._ref_identity(x)]
      # pylint: enable=protected-access

      r = tf.while_loop(c, body, [i, x], parallel_iterations=5)

      grad_ys = [tf.Variable(73).ref()]
      grad = tf.gradients([r[1]], [x], grad_ys=grad_ys)

      tf.global_variables_initializer().run()

      self.assertEqual(r[0].dtype, tf.int32)
      self.assertEqual(r[1].dtype, tf.int32_ref)

      value_i, value_x, value_x_grad = sess.run(r + grad)

    self.assertEqual(10, value_i)
    self.assertEqual(0, value_x)
    self.assertEqual(73, value_x_grad) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:31,代码来源:control_flow_ops_py_test.py

示例5: testRefIdentityShape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def testRefIdentityShape(self):
    with self.test_session():
      shape = [2, 3]
      tensor = tf.Variable(tf.constant([[1, 2, 3], [6, 5, 4]], dtype=tf.int32))
      self.assertEquals(shape, tensor.get_shape())
      self.assertEquals(shape, gen_array_ops._ref_identity(tensor).get_shape()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:identity_op_py_test.py

示例6: _Identity

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import _ref_identity [as 别名]
def _Identity(data, name=None):
  """Return a tensor with the same shape and contents as the input tensor.

  Args:
    data: A Tensor.
    name: A name for this operation (optional).

  Returns:
    A Tensor with the same type and value as the input Tensor.
  """
  data = ops.convert_to_tensor_or_indexed_slices(data, as_ref=True)
  if isinstance(data, ops.Tensor):
    if data.dtype.is_ref_dtype:
      return gen_array_ops._ref_identity(data, name=name)
    else:
      return array_ops.identity(data, name=name)
  else:
    if not isinstance(data, (ops.IndexedSlices, sparse_tensor.SparseTensor)):
      raise TypeError("Type %s not supported" % type(data))
    values = _Identity(data.values, name=name)
    indices = array_ops.identity(data.indices, name="indices")
    if isinstance(data, ops.IndexedSlices):
      dense_shape = data.dense_shape
      if dense_shape is not None:
        dense_shape = array_ops.identity(dense_shape, name="dense_shape")
      return ops.IndexedSlices(values, indices, dense_shape)
    else:
      dense_shape = array_ops.identity(data.shape, name="dense_shape")
      return sparse_tensor.SparseTensor(indices, values, dense_shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:31,代码来源:control_flow_ops.py


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