當前位置: 首頁>>代碼示例>>Python>>正文


Python parsing_ops.parse_single_sequence_example方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.parsing_ops.parse_single_sequence_example方法的典型用法代碼示例。如果您正苦於以下問題:Python parsing_ops.parse_single_sequence_example方法的具體用法?Python parsing_ops.parse_single_sequence_example怎麽用?Python parsing_ops.parse_single_sequence_example使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.parsing_ops的用法示例。


在下文中一共展示了parsing_ops.parse_single_sequence_example方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decode

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import parse_single_sequence_example [as 別名]
def decode(self, serialized_example, items=None):
    """Decodes the given serialized TF-SequenceExample.

    Args:
      serialized_example: a serialized TF-SequenceExample tensor.
      items: the list of items to decode. These must be a subset of the item
        keys in self._items_to_handlers. If `items` is left as None, then all
        of the items in self._items_to_handlers are decoded.

    Returns:
      the decoded items, a list of tensor.
    """

    context, feature_list = parsing_ops.parse_single_sequence_example(
        serialized_example, self._keys_to_context_features,
        self._keys_to_sequence_features)

    # Reshape non-sparse elements just once:
    for k in self._keys_to_context_features:
      v = self._keys_to_context_features[k]
      if isinstance(v, parsing_ops.FixedLenFeature):
        context[k] = array_ops.reshape(context[k], v.shape)

    if not items:
      items = self._items_to_handlers.keys()

    outputs = []
    for item in items:
      handler = self._items_to_handlers[item]
      keys_to_tensors = {
          key: context[key] if key in context else feature_list[key]
          for key in handler.keys
      }
      outputs.append(handler.tensors_to_item(keys_to_tensors))
    return outputs 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:37,代碼來源:tfexample_decoder.py

示例2: parse_feature_columns_from_sequence_examples

# 需要導入模塊: from tensorflow.python.ops import parsing_ops [as 別名]
# 或者: from tensorflow.python.ops.parsing_ops import parse_single_sequence_example [as 別名]
def parse_feature_columns_from_sequence_examples(
    serialized,
    context_feature_columns,
    sequence_feature_columns,
    name=None,
    example_name=None):
  """Parses tf.SequenceExamples to extract tensors for given `FeatureColumn`s.

  Args:
    serialized: A scalar (0-D Tensor) of type string, a single serialized
      `SequenceExample` proto.
    context_feature_columns: An iterable containing the feature columns for
      context features. All items should be instances of classes derived from
      `_FeatureColumn`. Can be `None`.
    sequence_feature_columns: An iterable containing the feature columns for
      sequence features. All items should be instances of classes derived from
      `_FeatureColumn`. Can be `None`.
    name: A name for this operation (optional).
    example_name: A scalar (0-D Tensor) of type string (optional), the names of
      the serialized proto.

  Returns:
    A tuple consisting of:
    context_features: a dict mapping `FeatureColumns` from
      `context_feature_columns` to their parsed `Tensors`/`SparseTensor`s.
    sequence_features: a dict mapping `FeatureColumns` from
      `sequence_feature_columns` to their parsed `Tensors`/`SparseTensor`s.
  """
  # Sequence example parsing requires a single (scalar) example.
  try:
    serialized = array_ops.reshape(serialized, [])
  except ValueError as e:
    raise ValueError(
        'serialized must contain as single sequence example. Batching must be '
        'done after parsing for sequence examples. Error: {}'.format(e))

  if context_feature_columns is None:
    context_feature_columns = []
  if sequence_feature_columns is None:
    sequence_feature_columns = []

  check_feature_columns(context_feature_columns)
  context_feature_spec = fc.create_feature_spec_for_parsing(
      context_feature_columns)

  check_feature_columns(sequence_feature_columns)
  sequence_feature_spec = fc._create_sequence_feature_spec_for_parsing(  # pylint: disable=protected-access
      sequence_feature_columns, allow_missing_by_default=False)

  return parsing_ops.parse_single_sequence_example(serialized,
                                                   context_feature_spec,
                                                   sequence_feature_spec,
                                                   example_name,
                                                   name) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:56,代碼來源:feature_column_ops.py


注:本文中的tensorflow.python.ops.parsing_ops.parse_single_sequence_example方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。