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


Python decoder._transpose_batch_time方法代码示例

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


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

示例1: _create_predictions

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def _create_predictions(self, decoder_output, features, labels=None):
    """Creates the dictionary of predictions that is returned by the model.
    """
    with tf.name_scope("create_predictions"):
      predicted_ids = _transpose_batch_time(decoder_output.predicted_ids)
      predicted_text = self.charset.get_text(predicted_ids)
      attention_scores = decoder_output.attention_scores
      original_images = features["image_orig"]
      prediction = {"predicted_ids": predicted_ids,
                    "predicted_text": predicted_text,
                    "images": original_images,
                    "attention_scores": attention_scores}
      if "name" in features:
        prediction["image_names"] = features['name']
      if labels:
        gt_text = self.charset.get_text(labels["label"])
        prediction["gt_text"] = gt_text
      tf.add_to_collection("prediction", prediction)
      return prediction 
开发者ID:FangShancheng,项目名称:conv-ensemble-str,代码行数:21,代码来源:model.py

示例2: conv_decoder_train

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def conv_decoder_train(self, encoder_output, labels):
    label_input = labels['label_input']
    length = labels['length']
    conv_block = ConvBlock(self.params,
                           self.num_charset,
                           is_training=True)

    next_layer = self.add_embedding(label_input, length)

    language, attention, att_scores = conv_block(encoder_output, next_layer)

    language_logit = _transpose_batch_time(language)
    attention_logit = _transpose_batch_time(attention)
    ensemble_logit = language_logit + attention_logit

    sample_ids = tf.cast(tf.argmax(ensemble_logit, axis=-1), tf.int32)

    return DecoderOutput(logits=(language_logit, attention_logit),
                         predicted_ids=sample_ids,
                         attention_scores=att_scores) 
开发者ID:FangShancheng,项目名称:conv-ensemble-str,代码行数:22,代码来源:decoder_conv.py

示例3: __init__

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def __init__(self, inputs, sequence_length, time_major=False, name=None):
        """Initializer.

        Args:
          inputs: A (structure of) input tensors.
          sequence_length: An int32 vector tensor.
          time_major: Python bool.  Whether the tensors in `inputs` are time major.
            If `False` (default), they are assumed to be batch major.
          name: Name scope for any created operations.

        Raises:
          ValueError: if `sequence_length` is not a 1D tensor.
        """
        with ops.name_scope(name, "TrainingHelper", [inputs, sequence_length]):
            inputs = ops.convert_to_tensor(inputs, name="inputs")
            self._inputs = inputs
            if not time_major:
                inputs = nest.map_structure(_transpose_batch_time, inputs)

            self._input_tas = nest.map_structure(_unstack_ta, inputs)
            self._sequence_length = ops.convert_to_tensor(
                sequence_length, name="sequence_length")
            if self._sequence_length.get_shape().ndims != 1:
                raise ValueError(
                    "Expected sequence_length to be a vector, but received shape: %s" %
                    self._sequence_length.get_shape())

            self._zero_inputs = nest.map_structure(
                lambda inp: array_ops.zeros_like(inp[0, :]), inputs)

            self._batch_size = shape_list(sequence_length)[0] 
开发者ID:qkaren,项目名称:Counterfactual-StoryRW,代码行数:33,代码来源:tf_helpers.py

示例4: __init__

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def __init__(self, inputs, sequence_length, time_major=False, name=None):
    """Initializer.

    Args:
      inputs: A (structure of) input tensors.
      sequence_length: An int32 vector tensor.
      time_major: Python bool.  Whether the tensors in `inputs` are time major.
        If `False` (default), they are assumed to be batch major.
      name: Name scope for any created operations.

    Raises:
      ValueError: if `sequence_length` is not a 1D tensor.
    """
    with ops.name_scope(name, "TrainingHelper", [inputs, sequence_length]):
      inputs = ops.convert_to_tensor(inputs, name="inputs")
      if not time_major:
        inputs = nest.map_structure(_transpose_batch_time, inputs)

      self._input_tas = nest.map_structure(_unstack_ta, inputs)
      self._sequence_length = ops.convert_to_tensor(
          sequence_length, name="sequence_length")
      if self._sequence_length.get_shape().ndims != 1:
        raise ValueError(
            "Expected sequence_length to be a vector, but received shape: %s" %
            self._sequence_length.get_shape())

      self._zero_inputs = nest.map_structure(
          lambda inp: array_ops.zeros_like(inp[0, :]), inputs)

      self._batch_size = array_ops.size(sequence_length) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:32,代码来源:helper.py

示例5: __init__

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def __init__(self, inputs, sequence_length, time_major=False, name=None):
    """Initializer.
    Args:
      inputs: A (structure of) input tensors.
      sequence_length: An int32 vector tensor.
      time_major: Python bool.  Whether the tensors in `inputs` are time major.
        If `False` (default), they are assumed to be batch major.
      name: Name scope for any created operations.
    Raises:
      ValueError: if `sequence_length` is not a 1D tensor.
    """
    with ops.name_scope(name, "TrainingHelper", [inputs, sequence_length]):
      inputs = ops.convert_to_tensor(inputs, name="inputs")
      self._inputs = inputs
      if not time_major:
        inputs = nest.map_structure(_transpose_batch_time, inputs)

      self._input_tas = nest.map_structure(_unstack_ta, inputs)
      self._sequence_length = ops.convert_to_tensor(
          sequence_length, name="sequence_length")
      if self._sequence_length.get_shape().ndims != 1:
        raise ValueError(
            "Expected sequence_length to be a vector, but received shape: %s" %
            self._sequence_length.get_shape())

      self._zero_inputs = nest.map_structure(
          lambda inp: array_ops.zeros_like(inp[0, :]), inputs)

      self._batch_size = array_ops.size(sequence_length) 
开发者ID:NVIDIA,项目名称:OpenSeq2Seq,代码行数:31,代码来源:helper.py

示例6: __init__

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def __init__(
      self,
      inputs,
      prenet=None,
      time_major=False,
      sample_ids_shape=None,
      sample_ids_dtype=None,
      mask_decoder_sequence=None
  ):
    """Initializer.

    Args:
      inputs (Tensor): inputs of shape [batch, time, n_feats]
      prenet: prenet to use, currently disabled and used in tacotron decoder
        instead.
      sampling_prob (float): see tacotron 2 decoder
      anneal_teacher_forcing (float): see tacotron 2 decoder
      stop_gradient (float): see tacotron 2 decoder
      time_major (bool): (float): see tacotron 2 decoder
      mask_decoder_sequence (bool): whether to pass finished when the decoder
        passed the sequence_length input or to pass unfinished to dynamic_decode
    """
    self._sample_ids_shape = tensor_shape.TensorShape(sample_ids_shape or [])
    self._sample_ids_dtype = sample_ids_dtype or dtypes.int32
    self._batch_size = inputs.get_shape()[0]
    self._mask_decoder_sequence = mask_decoder_sequence

    if not time_major:
      inputs = nest.map_structure(_transpose_batch_time, inputs)

    inputs = inputs[0, :, :]
    self._prenet = prenet
    if prenet is None:
      self._start_inputs = inputs
    else:
      self._start_inputs = self._prenet(inputs) 
开发者ID:NVIDIA,项目名称:OpenSeq2Seq,代码行数:38,代码来源:tacotron_helper.py

示例7: __init__

# 需要导入模块: from tensorflow.contrib.seq2seq.python.ops import decoder [as 别名]
# 或者: from tensorflow.contrib.seq2seq.python.ops.decoder import _transpose_batch_time [as 别名]
def __init__(self, inputs, sequence_length, time_major=False, name=None):
        """Initializer.

        Args:
          inputs: A (structure of) input tensors.
          sequence_length: An int32 vector tensor.
          time_major: Python bool.  Whether the tensors in `inputs` are time major.
            If `False` (default), they are assumed to be batch major.
          name: Name scope for any created operations.

        Raises:
          ValueError: if `sequence_length` is not a 1D tensor.
        """
        with ops.name_scope(name, "TrainingHelper", [inputs, sequence_length]):
            inputs = ops.convert_to_tensor(inputs, name="inputs")
            self._inputs = inputs
            if not time_major:
                inputs = nest.map_structure(_transpose_batch_time, inputs)

            self._input_tas = nest.map_structure(_unstack_ta, inputs)
            self._sequence_length = ops.convert_to_tensor(
                sequence_length, name="sequence_length")
            if self._sequence_length.get_shape().ndims != 1:
                raise ValueError(
                    "Expected sequence_length to be a vector, but received shape: %s" %
                    self._sequence_length.get_shape())

            self._zero_inputs = nest.map_structure(
                lambda inp: array_ops.zeros_like(inp[0, :]), inputs)
            self._start_inputs = self._zero_inputs
            self._batch_size = shape_list(sequence_length)[0] 
开发者ID:asyml,项目名称:texar,代码行数:33,代码来源:tf_helpers.py


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