當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。