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


Python tensorflow.FixedLenSequenceFeature方法代码示例

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


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

示例1: _mapper

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def _mapper(example_proto):
  features = {
      'samples': tf.FixedLenSequenceFeature([1], tf.float32, allow_missing=True),
      'label': tf.FixedLenSequenceFeature([], tf.string, allow_missing=True)
  }
  example = tf.parse_single_example(example_proto, features)

  wav = example['samples'][:, 0]

  wav = wav[:16384]
  wav_len = tf.shape(wav)[0]
  wav = tf.pad(wav, [[0, 16384 - wav_len]])

  label = tf.reduce_join(example['label'], 0)

  return wav, label 
开发者ID:acheketa,项目名称:cwavegan,代码行数:18,代码来源:dump_tfrecord.py

示例2: _read_single_sequence_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def _read_single_sequence_example(file_list, tokens_shape=None):
  """Reads and parses SequenceExamples from TFRecord-encoded file_list."""
  tf.logging.info('Constructing TFRecordReader from files: %s', file_list)
  file_queue = tf.train.string_input_producer(file_list)
  reader = tf.TFRecordReader()
  seq_key, serialized_record = reader.read(file_queue)
  ctx, sequence = tf.parse_single_sequence_example(
      serialized_record,
      sequence_features={
          data_utils.SequenceWrapper.F_TOKEN_ID:
              tf.FixedLenSequenceFeature(tokens_shape or [], dtype=tf.int64),
          data_utils.SequenceWrapper.F_LABEL:
              tf.FixedLenSequenceFeature([], dtype=tf.int64),
          data_utils.SequenceWrapper.F_WEIGHT:
              tf.FixedLenSequenceFeature([], dtype=tf.float32),
      })
  return seq_key, ctx, sequence 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:19,代码来源:inputs.py

示例3: example_reading_spec

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def example_reading_spec(self):
    data_fields, data_items_to_decoders = (
        super(ImageVqav2Tokens10kLabels3k, self).example_reading_spec())
    data_fields["image/image_id"] = tf.FixedLenFeature((), tf.int64)
    data_fields["image/question_id"] = tf.FixedLenFeature((), tf.int64)
    data_fields["image/question"] = tf.FixedLenSequenceFeature(
        (), tf.int64, allow_missing=True)
    data_fields["image/answer"] = tf.FixedLenSequenceFeature(
        (), tf.int64, allow_missing=True)

    data_items_to_decoders[
        "question"] = tf.contrib.slim.tfexample_decoder.Tensor(
            "image/question")
    data_items_to_decoders[
        "targets"] = tf.contrib.slim.tfexample_decoder.Tensor(
            "image/answer")
    return data_fields, data_items_to_decoders 
开发者ID:yyht,项目名称:BERT,代码行数:19,代码来源:vqa.py

示例4: _parse_record

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def _parse_record(example_proto):
        context_features = {
            "length": tf.FixedLenFeature([], dtype=tf.int64)
        }
        sequence_features = {
            "tokens": tf.FixedLenSequenceFeature([], dtype=tf.int64),
            "labels": tf.FixedLenSequenceFeature([], dtype=tf.int64)
        }

        context_parsed, sequence_parsed = tf.parse_single_sequence_example(serialized=example_proto,
            context_features=context_features, sequence_features=sequence_features)

        return context_parsed['length'], sequence_parsed['tokens'], sequence_parsed['labels']

    # Read training data from TFRecord file, shuffle, loop over data infinitely and
    # pad to the longest sentence 
开发者ID:sertiscorp,项目名称:thai-word-segmentation,代码行数:18,代码来源:model.py

示例5: parse_sequence_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def parse_sequence_example(serialized_example, num_views):
  """Parses a serialized sequence example into views, sequence length data."""
  context_features = {
      'task': tf.FixedLenFeature(shape=[], dtype=tf.string),
      'len': tf.FixedLenFeature(shape=[], dtype=tf.int64)
  }
  view_names = ['view%d' % i for i in range(num_views)]
  fixed_features = [
      tf.FixedLenSequenceFeature(
          shape=[], dtype=tf.string) for _ in range(len(view_names))]
  sequence_features = dict(zip(view_names, fixed_features))
  context_parse, sequence_parse = tf.parse_single_sequence_example(
      serialized=serialized_example,
      context_features=context_features,
      sequence_features=sequence_features)
  views = tf.stack([sequence_parse[v] for v in view_names])
  lens = [sequence_parse[v].get_shape().as_list()[0] for v in view_names]
  assert len(set(lens)) == 1
  seq_len = tf.shape(sequence_parse[v])[0]
  return context_parse, views, seq_len 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:22,代码来源:data_providers.py

示例6: deserialize_fasta_sequence

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def deserialize_fasta_sequence(example):
    context = {
        'protein_length': tf.FixedLenFeature([1], tf.int64),
        'id': tf.FixedLenFeature([], tf.string)
    }

    features = {
        'primary': tf.FixedLenSequenceFeature([1], tf.int64),
    }

    context, features = tf.parse_single_sequence_example(
        example,
        context_features=context,
        sequence_features=features
    )

    return {'id': context['id'],
            'primary': tf.to_int32(features['primary'][:, 0]),
            'protein_length': tf.to_int32(context['protein_length'][0])} 
开发者ID:songlab-cal,项目名称:tape-neurips2019,代码行数:21,代码来源:serialize_fasta.py

示例7: parse_sequence_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def parse_sequence_example(serialized_example, num_views):
  """Parses a serialized sequence example into views, sequence length data."""
  context_features = {
      'task': tf.FixedLenFeature(shape=[], dtype=tf.string),
      'len': tf.FixedLenFeature(shape=[], dtype=tf.int64)
  }
  view_names = ['view%d' % i for i in range(num_views)]
  fixed_features = [
      tf.FixedLenSequenceFeature(
          shape=[], dtype=tf.string) for _ in range(len(view_names))]
  sequence_features = dict(zip(view_names, fixed_features))
  context_parse, sequence_parse = tf.parse_single_sequence_example(
      serialized=serialized_example,
      context_features=context_features,
      sequence_features=sequence_features)
  views = tf.stack([sequence_parse[v] for v in view_names])
  lens = [sequence_parse[v].get_shape().as_list()[0] for v in view_names]
  assert len(set(lens)) == 1
  seq_len = tf.shape(sequence_parse[view_names[-1]])[0]
  return context_parse, views, seq_len 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:22,代码来源:data_providers.py

示例8: testSequenceExampleListWithInconsistentDataFails

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def testSequenceExampleListWithInconsistentDataFails(self):
    original = sequence_example(feature_lists=feature_lists({
        "a": feature_list([
            int64_feature([-1, 0]), float_feature([2, 3])
        ])
    }))

    serialized = original.SerializeToString()

    self._test(
        {
            "example_name": "in1",
            "serialized": tf.convert_to_tensor(serialized),
            "sequence_features": {"a": tf.FixedLenSequenceFeature(
                (2,), tf.int64)}
        },
        expected_err=(tf.OpError, "Feature list: a, Index: 1."
                      "  Data types don't match. Expected type: int64")) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:parsing_ops_test.py

示例9: testSequenceExampleListWithWrongDataTypeFails

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def testSequenceExampleListWithWrongDataTypeFails(self):
    original = sequence_example(feature_lists=feature_lists({
        "a": feature_list([
            float_feature([2, 3])
        ])
    }))

    serialized = original.SerializeToString()

    self._test(
        {
            "example_name": "in1",
            "serialized": tf.convert_to_tensor(serialized),
            "sequence_features": {"a": tf.FixedLenSequenceFeature(
                (2,), tf.int64)}
        },
        expected_err=(tf.OpError,
                      "Feature list: a, Index: 0.  Data types don't match."
                      " Expected type: int64")) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:parsing_ops_test.py

示例10: testSequenceExampleListWithWrongShapeFails

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def testSequenceExampleListWithWrongShapeFails(self):
    original = sequence_example(feature_lists=feature_lists({
        "a": feature_list([
            int64_feature([2, 3]), int64_feature([2, 3, 4])
        ]),
    }))

    serialized = original.SerializeToString()

    self._test(
        {
            "example_name": "in1",
            "serialized": tf.convert_to_tensor(serialized),
            "sequence_features": {"a": tf.FixedLenSequenceFeature(
                (2,), tf.int64)}
        },
        expected_err=(tf.OpError, r"Name: in1, Key: a, Index: 1."
                      r"  Number of int64 values != expected."
                      r"  values size: 3 but output shape: \[2\]")) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:parsing_ops_test.py

示例11: testSequenceExampleWithMissingFeatureListFails

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def testSequenceExampleWithMissingFeatureListFails(self):
    original = sequence_example(feature_lists=feature_lists({}))

    # Test fails because we didn't add:
    #  feature_list_dense_defaults = {"a": None}
    self._test(
        {
            "example_name": "in1",
            "serialized": tf.convert_to_tensor(original.SerializeToString()),
            "sequence_features": {"a": tf.FixedLenSequenceFeature(
                (2,), tf.int64)}
        },
        expected_err=(
            tf.OpError,
            "Name: in1, Feature list 'a' is required but could not be found."
            "  Did you mean to include it in"
            " feature_list_dense_missing_assumed_empty or"
            " feature_list_dense_defaults?")) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:parsing_ops_test.py

示例12: create_tensorrec_dataset_from_tfrecord

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def create_tensorrec_dataset_from_tfrecord(tfrecord_path):
    """
    Loads a TFRecord file and creates a Dataset with the contents.
    :param tfrecord_path: str
    :return: tf.data.Dataset
    """

    def parse_tensorrec_tfrecord(example_proto):
        features = {
            'row_index': tf.FixedLenSequenceFeature((), tf.int64, allow_missing=True),
            'col_index': tf.FixedLenSequenceFeature((), tf.int64, allow_missing=True),
            'values': tf.FixedLenSequenceFeature((), tf.float32, allow_missing=True),
            'd0': tf.FixedLenFeature((), tf.int64),
            'd1': tf.FixedLenFeature((), tf.int64),
        }
        parsed_features = tf.parse_single_example(example_proto, features)
        return (parsed_features['row_index'], parsed_features['col_index'], parsed_features['values'],
                parsed_features['d0'], parsed_features['d1'])

    dataset = tf.data.TFRecordDataset(tfrecord_path).map(parse_tensorrec_tfrecord)
    return dataset 
开发者ID:jfkirk,项目名称:tensorrec,代码行数:23,代码来源:input_utils.py

示例13: _read_sequence_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def _read_sequence_example(filename_queue,
                           n_labels=50, n_samples=59049, n_segments=10):
  reader = tf.TFRecordReader()
  _, serialized_example = reader.read(filename_queue)
  context, sequence = tf.parse_single_sequence_example(
    serialized_example,
    context_features={
      'raw_labels': tf.FixedLenFeature([], dtype=tf.string)
    },
    sequence_features={
      'raw_segments': tf.FixedLenSequenceFeature([], dtype=tf.string)
    })

  segments = tf.decode_raw(sequence['raw_segments'], tf.float32)
  segments.set_shape([n_segments, n_samples])

  labels = tf.decode_raw(context['raw_labels'], tf.uint8)
  labels.set_shape([n_labels])
  labels = tf.cast(labels, tf.float32)

  return segments, labels 
开发者ID:tae-jun,项目名称:sample-cnn,代码行数:23,代码来源:batch_inputs.py

示例14: parse_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def parse_fn(serialized_example):
  """Parse a serialized example."""
  
  # user_id is not currently used.
  context_features = {
    'user_id': tf.FixedLenFeature([], dtype=tf.int64)
  }
  sequence_features = {
    'movie_ids': tf.FixedLenSequenceFeature([], dtype=tf.int64)
  }
  parsed_feature, parsed_sequence_feature = tf.parse_single_sequence_example(
    serialized=serialized_example,
    context_features=context_features,
    sequence_features=sequence_features
  )
  movie_ids = parsed_sequence_feature['movie_ids']
  return movie_ids 
开发者ID:GoogleCloudPlatform,项目名称:realtime-embeddings-matching,代码行数:19,代码来源:input_pipeline.py

示例15: read_dataset

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import FixedLenSequenceFeature [as 别名]
def read_dataset(filename, num_channels=39):
    """Read data from tfrecord file."""

    def parse_fn(example_proto):
        """Parse function for reading single sequence example."""
        sequence_features = {
            'inputs': tf.FixedLenSequenceFeature(shape=[num_channels], dtype=tf.float32),
            'labels': tf.FixedLenSequenceFeature(shape=[], dtype=tf.string)
        }

        context, sequence = tf.parse_single_sequence_example(
            serialized=example_proto,
            sequence_features=sequence_features
        )

        return sequence['inputs'], sequence['labels']

    dataset = tf.data.TFRecordDataset(filename)
    dataset = dataset.map(parse_fn)

    return dataset 
开发者ID:WindQAQ,项目名称:listen-attend-and-spell,代码行数:23,代码来源:dataset_utils.py


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