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


Python tensor_array_ops.TensorArray方法代码示例

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


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

示例1: convert_network_state_tensorarray

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def convert_network_state_tensorarray(tensorarray):
  """Converts a source TensorArray to a source Tensor.

  Performs a permutation between the steps * [stride, D] shape of a
  source TensorArray and the (flattened) [stride * steps, D] shape of
  a source Tensor.

  The TensorArrays used during recurrence have an additional zeroth step that
  needs to be removed.

  Args:
    tensorarray: TensorArray object to be converted.

  Returns:
    Tensor object after conversion.
  """
  tensor = tensorarray.stack()  # Results in a [steps, stride, D] tensor.
  tensor = tf.slice(tensor, [1, 0, 0], [-1, -1, -1])  # Lop off the 0th step.
  tensor = tf.transpose(tensor, [1, 0, 2])  # Switch steps and stride.
  return tf.reshape(tensor, [-1, tf.shape(tensor)[2]]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:22,代码来源:network_units.py

示例2: create_array

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def create_array(self, stride):
    """Creates a new tensor array to store this layer's activations.

    Arguments:
      stride: Possibly dynamic batch * beam size with which to initialize the
        tensor array

    Returns:
      TensorArray object
    """
    check.Gt(self.dim, 0, 'Cannot create array when dimension is dynamic')
    tensor_array = ta.TensorArray(dtype=tf.float32,
                                  size=0,
                                  dynamic_size=True,
                                  clear_after_read=False,
                                  infer_shape=False,
                                  name='%s_array' % self.name)

    # Start each array with all zeros. Special values will still be learned via
    # the extra embedding dimension stored for each linked feature channel.
    initial_value = tf.zeros([stride, self.dim])
    return tensor_array.write(0, initial_value) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:24,代码来源:network_units.py

示例3: create

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def create(self,
             fixed_embeddings,
             linked_embeddings,
             context_tensor_arrays,
             attention_tensor,
             during_training,
             stride=None):
    """Constructs a feed-forward unit based on the features and context tensors.

    Args:
      fixed_embeddings: list of NamedTensor objects
      linked_embeddings: list of NamedTensor objects
      context_tensor_arrays: optional list of TensorArray objects used for
          implicit recurrence.
      attention_tensor: optional Tensor used for attention.
      during_training: whether to create a network for training (vs inference).
      stride: int scalar tensor containing the stride required for
          bulk computation.

    Returns:
      A list of tensors corresponding to the list of layers.
    """
    pass 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:25,代码来源:network_units.py

示例4: _TensorArrayWriteGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArrayWriteGrad(op, flow):
  """Gradient for TensorArrayWrite.

  Args:
    op: Forward TensorArrayWrite op.
    flow: Gradient `Tensor` flow to TensorArrayWrite.

  Returns:
    A grad `Tensor`, the gradient created in an upstream ReadGrad or PackGrad.
  """
  # handle is the output store_handle of TensorArrayReadGrad or
  # the handle output of TensorArrayWriteGrad.  we must use this one.
  handle = op.inputs[0]
  index = op.inputs[1]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = (tensor_array_ops.TensorArray(dtype=dtype, handle=handle, flow=flow,
                                    colocate_with_first_write_call=False)
       .grad(source=grad_source, flow=flow))
  grad = g.read(index)
  return [None, None, grad, flow] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:tensor_array_grad.py

示例5: _TensorArrayScatterGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArrayScatterGrad(op, flow):
  """Gradient for TensorArrayScatter.

  Args:
    op: Forward TensorArrayScatter op.
    flow: Gradient `Tensor` flow to TensorArrayScatter.

  Returns:
    A grad `Tensor`, the gradient created in upstream ReadGrads or PackGrad.
  """
  handle = op.inputs[0]
  indices = op.inputs[1]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = (tensor_array_ops.TensorArray(dtype=dtype, handle=handle, flow=flow,
                                    colocate_with_first_write_call=False)
       .grad(source=grad_source, flow=flow))
  grad = g.gather(indices)
  return [None, None, grad, flow] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:tensor_array_grad.py

示例6: _TensorArraySplitGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArraySplitGrad(op, flow):
  """Gradient for TensorArraySplit.

  Args:
    op: Forward TensorArraySplit op.
    flow: Gradient `Tensor` flow to TensorArraySplit.

  Returns:
    A grad `Tensor`, the gradient created in upstream ReadGrads or PackGrad.
  """
  handle = op.inputs[0]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = (tensor_array_ops.TensorArray(dtype=dtype, handle=handle, flow=flow,
                                    colocate_with_first_write_call=False)
       .grad(source=grad_source, flow=flow))
  grad = g.concat()
  # handle, value, lengths, flow_in
  return [None, grad, None, flow] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:tensor_array_grad.py

示例7: _maybe_split_batch_beams

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _maybe_split_batch_beams(self, t, s):
    """Maybe splits the tensor from a batch by beams into a batch of beams.

    We do this so that we can use nest and not run into problems with shapes.

    Args:
      t: Tensor of dimension [batch_size*beam_width, s]
      s: Tensor, Python int, or TensorShape.

    Returns:
      Either a reshaped version of t with dimension
      [batch_size, beam_width, s] if t's first dimension is of size
      batch_size*beam_width or t if not.

    Raises:
      TypeError: If t is an instance of TensorArray.
      ValueError: If the rank of t is not statically known.
    """
    _check_maybe(t)
    if t.shape.ndims >= 1:
      return self._split_batch_beams(t, s)
    else:
      return t 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:25,代码来源:beam_search_decoder.py

示例8: _maybe_merge_batch_beams

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _maybe_merge_batch_beams(self, t, s):
    """Splits the tensor from a batch by beams into a batch of beams.

    More exactly, t is a tensor of dimension [batch_size*beam_width, s]. We
    reshape this into [batch_size, beam_width, s]

    Args:
      t: Tensor of dimension [batch_size*beam_width, s]
      s: Tensor, Python int, or TensorShape.

    Returns:
      A reshaped version of t with dimension [batch_size, beam_width, s].

    Raises:
      TypeError: If t is an instance of TensorArray.
      ValueError:  If the rank of t is not statically known.
    """
    _check_maybe(t)
    if t.shape.ndims >= 2:
      return self._merge_batch_beams(t, s)
    else:
      return t 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:beam_search_decoder.py

示例9: _TensorArrayWriteGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArrayWriteGrad(op, flow):
  """Gradient for TensorArrayWrite.

  Args:
    op: Forward TensorArrayWrite op.
    flow: Gradient `Tensor` flow to TensorArrayWrite.

  Returns:
    A grad `Tensor`, the gradient created in an upstream ReadGrad or PackGrad.
  """
  # handle is the output store_handle of TensorArrayReadGrad or
  # the handle output of TensorArrayWriteGrad.  we must use this one.
  handle = op.inputs[0]
  index = op.inputs[1]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = tensor_array_ops.TensorArray(
      dtype=dtype, handle=handle, flow=flow).grad(
          source=grad_source, flow=flow)
  grad = g.read(index)
  return [None, None, grad, flow] 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:23,代码来源:tensor_array_grad.py

示例10: _TensorArrayScatterGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArrayScatterGrad(op, flow):
  """Gradient for TensorArrayScatter.

  Args:
    op: Forward TensorArrayScatter op.
    flow: Gradient `Tensor` flow to TensorArrayScatter.

  Returns:
    A grad `Tensor`, the gradient created in upstream ReadGrads or PackGrad.
  """
  handle = op.inputs[0]
  indices = op.inputs[1]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = tensor_array_ops.TensorArray(
      dtype=dtype, handle=handle, flow=flow).grad(
          source=grad_source, flow=flow)
  grad = g.gather(indices)
  return [None, None, grad, flow] 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:tensor_array_grad.py

示例11: _TensorArraySplitGrad

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _TensorArraySplitGrad(op, flow):
  """Gradient for TensorArraySplit.

  Args:
    op: Forward TensorArraySplit op.
    flow: Gradient `Tensor` flow to TensorArraySplit.

  Returns:
    A grad `Tensor`, the gradient created in upstream ReadGrads or PackGrad.
  """
  handle = op.inputs[0]
  dtype = op.get_attr("T")
  grad_source = _GetGradSource(flow)
  g = tensor_array_ops.TensorArray(
      dtype=dtype, handle=handle, flow=flow).grad(
          source=grad_source, flow=flow)
  grad = g.concat()
  # handle, value, lengths, flow_in
  return [None, grad, None, flow] 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:tensor_array_grad.py

示例12: normalize_tensors

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def normalize_tensors(tensors):
  """Converts a nested structure of tensor-like objects to tensors.
  * `SparseTensor`-like inputs are converted to `SparseTensor`.
  * `TensorArray` inputs are passed through.
  * Everything else is converted to a dense `Tensor`.
  Args:
    tensors: A nested structure of tensor-like, list,
      `SparseTensor`, `SparseTensorValue`, or `TensorArray` objects.
  Returns:
    A nested structure of tensor, `SparseTensor`, or `TensorArray` objects.
  """
  flat_tensors = nest.flatten(tensors)
  prepared = []
  with ops.name_scope("normalize_tensors"):
    for i, t in enumerate(flat_tensors):
      if sparse_tensor_lib.is_sparse(t):
        prepared.append(sparse_tensor_lib.SparseTensor.from_value(t))
      elif isinstance(t, tensor_array_ops.TensorArray):
        prepared.append(t)
      else:
        prepared.append(ops.convert_to_tensor(t, name="component_%d" % i))
  return nest.pack_sequence_as(tensors, prepared) 
开发者ID:yyht,项目名称:BERT,代码行数:24,代码来源:strcuture.py

示例13: create_array

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def create_array(self, stride):
    """Creates a new tensor array to store this layer's activations.

    Arguments:
      stride: Possibly dynamic batch * beam size with which to initialize the
        tensor array

    Returns:
      TensorArray object
    """
    check.Gt(self.dim, 0, 'Cannot create array when dimension is dynamic')
    tensor_array = ta.TensorArray(
        dtype=tf.float32,
        size=0,
        dynamic_size=True,
        clear_after_read=False,
        infer_shape=False,
        name='%s_array' % self.name)

    # Start each array with all zeros. Special values will still be learned via
    # the extra embedding dimension stored for each linked feature channel.
    initial_value = tf.zeros([stride, self.dim])
    return tensor_array.write(0, initial_value) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:25,代码来源:network_units.py

示例14: testTensorArrayWriteRead

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def testTensorArrayWriteRead(self):
    with self.test_session(use_gpu=self._use_gpu) as session:
      ta = tensor_array_ops.TensorArray(
          dtype=tf.float32, tensor_array_name="foo", size=3, infer_shape=False)

      w0 = ta.write(0, [[4.0, 5.0]])
      w1 = w0.write(1, [[1.0]])
      w2 = w1.write(2, -3.0)

      r0 = w2.read(0)
      r1 = w2.read(1)
      r2 = w2.read(2)

      d0, d1, d2 = session.run([r0, r1, r2])
      self.assertAllEqual([[4.0, 5.0]], d0)
      self.assertAllEqual([[1.0]], d1)
      self.assertAllEqual(-3.0, d2) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:tensor_array_ops_test.py

示例15: _testTensorArrayWritePack

# 需要导入模块: from tensorflow.python.ops import tensor_array_ops [as 别名]
# 或者: from tensorflow.python.ops.tensor_array_ops import TensorArray [as 别名]
def _testTensorArrayWritePack(self, tf_dtype, legacy):
    dtype = tf_dtype.as_numpy_dtype()
    with self.test_session(use_gpu=self._use_gpu):
      ta = tensor_array_ops.TensorArray(
          dtype=tf_dtype, tensor_array_name="foo", size=3)

      if tf_dtype == tf.string:
        # In Python3, np.str is unicode, while we always want bytes
        convert = lambda x: np.asarray(x).astype("|S")
      else:
        convert = lambda x: np.asarray(x).astype(dtype)

      w0 = ta.write(0, convert([[4.0, 5.0]]))
      w1 = w0.write(1, convert([[6.0, 7.0]]))
      w2 = w1.write(2, convert([[8.0, 9.0]]))

      if legacy:
        c0 = w2._legacy_pack()
      else:
        c0 = w2.pack()

      self.assertAllEqual(
          convert([[[4.0, 5.0]], [[6.0, 7.0]], [[8.0, 9.0]]]), c0.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:tensor_array_ops_test.py


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