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


Python tensorflow.parse_example方法代码示例

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


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

示例1: _extract_features_batch

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def _extract_features_batch(self, serialized_batch):
        features = tf.parse_example(
            serialized_batch,
            features={'images': tf.FixedLenFeature([], tf.string),
                'imagepaths': tf.FixedLenFeature([], tf.string),
                'labels': tf.VarLenFeature(tf.int64),
                 })

        bs = features['images'].shape[0]
        images = tf.decode_raw(features['images'], tf.uint8)
        w, h = tuple(CFG.ARCH.INPUT_SIZE)
        images = tf.cast(x=images, dtype=tf.float32)
        #images = tf.subtract(tf.divide(images, 128.0), 1.0)
        images = tf.reshape(images, [bs, h, -1, CFG.ARCH.INPUT_CHANNELS])

        labels = features['labels']
        labels = tf.cast(labels, tf.int32)

        imagepaths = features['imagepaths']

        return images, labels, imagepaths 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:23,代码来源:read_tfrecord.py

示例2: prepare_serialized_examples

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def prepare_serialized_examples(self, serialized_examples):
    # set the mapping from the fields to data types in the proto
    num_features = len(self.feature_names)
    assert num_features > 0, "self.feature_names is empty!"
    assert len(self.feature_names) == len(self.feature_sizes), \
    "length of feature_names (={}) != length of feature_sizes (={})".format( \
    len(self.feature_names), len(self.feature_sizes))

    feature_map = {"video_id": tf.FixedLenFeature([], tf.string),
                   "labels": tf.VarLenFeature(tf.int64)}
    for feature_index in range(num_features):
      feature_map[self.feature_names[feature_index]] = tf.FixedLenFeature(
          [self.feature_sizes[feature_index]], tf.float32)

    features = tf.parse_example(serialized_examples, features=feature_map)

    labels = tf.sparse_to_indicator(features["labels"], self.num_classes)
    labels.set_shape([None, self.num_classes])
    concatenated_features = tf.concat([
        features[feature_name] for feature_name in self.feature_names], 1)

    return features["video_id"], concatenated_features, labels, tf.ones([tf.shape(serialized_examples)[0]]) 
开发者ID:antoine77340,项目名称:Youtube-8M-WILLOW,代码行数:24,代码来源:readers.py

示例3: example_serving_input_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def example_serving_input_fn(default_batch_size=None):
    """Build the serving inputs.

    Args:
      default_batch_size (int): Batch size for the tf.placeholder shape.

    Returns:
      A tuple of dictionaries.
    """
    feature_spec = {}
    for feat in CONTINUOUS_COLS:
        feature_spec[feat] = tf.FixedLenFeature(shape=[], dtype=tf.int64)

    for feat, _ in CATEGORICAL_COLS:
        feature_spec[feat] = tf.FixedLenFeature(shape=[], dtype=tf.string)

    example_bytestring = tf.placeholder(
        shape=[default_batch_size],
        dtype=tf.string,
    )
    features = tf.parse_example(example_bytestring, feature_spec)
    return features, {'example': example_bytestring} 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:24,代码来源:model.py

示例4: example_serving_input_receiver_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def example_serving_input_receiver_fn():
  """Creating an ServingInputReceiver object for TFRecords data.

  Returns:
    ServingInputReceiver
  """

  # Note that the inputs are raw features, not transformed features.
  receiver_tensors = tf.placeholder(shape=[None], dtype=tf.string)

  features = tf.parse_example(
    receiver_tensors,
    features=get_feature_spec(is_serving=True)
  )

  for key in features:
    features[key] = tf.expand_dims(features[key], -1)

  return tf.estimator.export.ServingInputReceiver(
    features=process_features(features),
    receiver_tensors={'example_proto': receiver_tensors}
  ) 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:24,代码来源:inputs.py

示例5: example_evaluating_input_receiver_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def example_evaluating_input_receiver_fn():
  """Creating an EvalInputReceiver object for TFRecords data.

  Returns:
      EvalInputReceiver
  """

  tf_example = tf.placeholder(shape=[None], dtype=tf.string)
  features = tf.parse_example(
    tf_example,
    features=get_feature_spec(is_serving=False))

  for key in features:
    features[key] = tf.expand_dims(features[key], -1)

  return tfma.export.EvalInputReceiver(
    features=process_features(features),
    receiver_tensors={'examples': tf_example},
    labels=features[metadata.TARGET_NAME]) 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:21,代码来源:inputs.py

示例6: _decode_record

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def _decode_record(record, name_to_features):
	"""Decodes a record to a TensorFlow example.

	name_to_features = {
	            "input_ids":
	                    tf.FixedLenFeature([max_seq_length], tf.int64),
	            "input_mask":
	                    tf.FixedLenFeature([max_seq_length], tf.int64),
	            "segment_ids":
	                    tf.FixedLenFeature([max_seq_length], tf.int64),
	            "masked_lm_positions":
	                    tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
	            "masked_lm_ids":
	                    tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
	            "masked_lm_weights":
	                    tf.FixedLenFeature([max_predictions_per_seq], tf.float32),
	            "next_sentence_labels":
	                    tf.FixedLenFeature([1], tf.int64),
	    }

	"""
	example = tf.parse_example(record, name_to_features)
	return example 
开发者ID:yyht,项目名称:BERT,代码行数:25,代码来源:iterate_data.py

示例7: _decode_record

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def _decode_record(record, name_to_features):
        """Decodes a record to a TensorFlow example.

        name_to_features = {
                    "input_ids":
                            tf.FixedLenFeature([max_seq_length], tf.int64),
                    "input_mask":
                            tf.FixedLenFeature([max_seq_length], tf.int64),
                    "segment_ids":
                            tf.FixedLenFeature([max_seq_length], tf.int64),
                    "masked_lm_positions":
                            tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
                    "masked_lm_ids":
                            tf.FixedLenFeature([max_predictions_per_seq], tf.int64),
                    "masked_lm_weights":
                            tf.FixedLenFeature([max_predictions_per_seq], tf.float32),
                    "next_sentence_labels":
                            tf.FixedLenFeature([1], tf.int64),
            }

        """
        example = tf.parse_example(record, name_to_features)
        return example 
开发者ID:yyht,项目名称:BERT,代码行数:25,代码来源:feature_reader.py

示例8: prepare_reader

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def prepare_reader(self, filename_queue, batch_size=1024):

    reader = tf.TFRecordReader()
    _, serialized_examples = reader.read_up_to(filename_queue, batch_size)

    # set the mapping from the fields to data types in the proto
    num_features = len(self.feature_names)
    assert num_features > 0, "self.feature_names is empty!"
    assert len(self.feature_names) == len(self.feature_sizes), \
    "length of feature_names (={}) != length of feature_sizes (={})".format( \
    len(self.feature_names), len(self.feature_sizes))

    feature_map = {"video_id": tf.FixedLenFeature([], tf.string),
                   "labels": tf.VarLenFeature(tf.int64)}
    for feature_index in range(num_features):
      feature_map[self.feature_names[feature_index]] = tf.FixedLenFeature(
          [self.feature_sizes[feature_index]], tf.float32)

    features = tf.parse_example(serialized_examples, features=feature_map)
    labels = tf.sparse_to_indicator(features["labels"], self.num_classes)
    labels.set_shape([None, self.num_classes])
    concatenated_features = tf.concat([
        features[feature_name] for feature_name in self.feature_names], 1)

    return features["video_id"], concatenated_features, labels, tf.ones([tf.shape(serialized_examples)[0]]) 
开发者ID:wangheda,项目名称:youtube-8m,代码行数:27,代码来源:readers.py

示例9: batch_parse_tf_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def batch_parse_tf_example(batch_size, example_batch):
    '''
    Args:
        example_batch: a batch of tf.Example
    Returns:
        A tuple (feature_tensor, dict of output tensors)
    '''
    features = {
        'x': tf.FixedLenFeature([], tf.string),
        'pi': tf.FixedLenFeature([], tf.string),
        'outcome': tf.FixedLenFeature([], tf.float32),
    }
    parsed = tf.parse_example(example_batch, features)
    x = tf.decode_raw(parsed['x'], tf.uint8)
    x = tf.cast(x, tf.float32)
    x = tf.reshape(x, [batch_size, go.N, go.N,
                       features_lib.NEW_FEATURES_PLANES])
    pi = tf.decode_raw(parsed['pi'], tf.float32)
    pi = tf.reshape(pi, [batch_size, go.N * go.N + 1])
    outcome = parsed['outcome']
    outcome.set_shape([batch_size])
    return (x, {'pi_tensor': pi, 'value_tensor': outcome}) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:24,代码来源:preprocessing.py

示例10: serving_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def serving_fn():
  """Returns the ServingInputReceiver for the exported model.

  Returns:
    A ServingInputReceiver object which may be passed to
    `Estimator.export_savedmodel`. A model saved using this receiver may be used
    for running OMR.
  """
  examples = tf.placeholder(tf.string, shape=[None])
  patch_height, patch_width = read_patch_dimensions()
  parsed = tf.parse_example(examples, {
      'patch': tf.FixedLenFeature((patch_height, patch_width), tf.float32),
  })
  return tf.estimator.export.ServingInputReceiver(
      features={'patch': parsed['patch']},
      receiver_tensors=parsed['patch'],
      receiver_tensors_alternatives={
          'example': examples,
          'patch': parsed['patch']
      }) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:22,代码来源:glyph_patches.py

示例11: parse_example_batch

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def parse_example_batch(serialized):
  """Parses a batch of tf.Example protos.

  Args:
    serialized: A 1-D string Tensor; a batch of serialized tf.Example protos.
  Returns:
    encode: A SentenceBatch of encode sentences.
    decode_pre: A SentenceBatch of "previous" sentences to decode.
    decode_post: A SentenceBatch of "post" sentences to decode.
  """
  features = tf.parse_example(
    serialized,
    features={"features": tf.VarLenFeature(dtype=tf.int64)}
  )
  features = features["features"]

  def _sparse_to_batch(sparse):
    ids = tf.sparse_tensor_to_dense(sparse)  # Padding with zeroes.
    mask = tf.sparse_to_dense(sparse.indices, sparse.dense_shape,
                              tf.ones_like(sparse.values, dtype=tf.int32))
    return SentenceBatch(ids=ids, mask=mask)

  return _sparse_to_batch(features) 
开发者ID:lajanugen,项目名称:S2V,代码行数:25,代码来源:input_ops.py

示例12: prepare_serialized_examples

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def prepare_serialized_examples(self, serialized_examples):
    # set the mapping from the fields to data types in the proto
    num_features = len(self.feature_names)
    assert num_features > 0, "self.feature_names is empty!"
    assert len(self.feature_names) == len(self.feature_sizes), \
    "length of feature_names (={}) != length of feature_sizes (={})".format( \
    len(self.feature_names), len(self.feature_sizes))

    feature_map = {"id": tf.FixedLenFeature([], tf.string),
                   "labels": tf.VarLenFeature(tf.int64)}
    for feature_index in range(num_features):
      feature_map[self.feature_names[feature_index]] = tf.FixedLenFeature(
          [self.feature_sizes[feature_index]], tf.float32)

    features = tf.parse_example(serialized_examples, features=feature_map)
    labels = tf.sparse_to_indicator(features["labels"], self.num_classes)
    labels.set_shape([None, self.num_classes])
    concatenated_features = tf.concat([
        features[feature_name] for feature_name in self.feature_names], 1)

    return features["id"], concatenated_features, labels, tf.ones([tf.shape(serialized_examples)[0]]) 
开发者ID:miha-skalic,项目名称:youtube8mchallenge,代码行数:23,代码来源:readers.py

示例13: parse_batch_tf_example

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def parse_batch_tf_example(example_batch):
    features = {
        'x': tf.FixedLenFeature([], tf.string),
        'pi': tf.FixedLenFeature([], tf.string),
        'z': tf.FixedLenFeature([], tf.float32),
    }
    parsed_tensors = tf.parse_example(example_batch, features)

    # Get the board state
    x = tf.cast(tf.decode_raw(parsed_tensors['x'], tf.uint8), tf.float32)
    x = tf.reshape(x, [GLOBAL_PARAMETER_STORE.TRAIN_BATCH_SIZE, GOPARAMETERS.N,
                       GOPARAMETERS.N, FEATUREPARAMETERS.NUM_CHANNELS])

    # Get the policy target, which is the distribution of possible moves
    # Each target is a vector of length of board * length of board + 1
    distribution_of_moves = tf.decode_raw(parsed_tensors['pi'], tf.float32)
    distribution_of_moves = tf.reshape(distribution_of_moves,
                                       [GLOBAL_PARAMETER_STORE.TRAIN_BATCH_SIZE, GOPARAMETERS.N * GOPARAMETERS.N + 1])

    # Get the result of the game
    # The result is simply a scalar
    result_of_game = parsed_tensors['z']
    result_of_game.set_shape([GLOBAL_PARAMETER_STORE.TRAIN_BATCH_SIZE])

    return (x, {'pi_label': distribution_of_moves, 'z_label': result_of_game}) 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:27,代码来源:preprocessing.py

示例14: _extract_features_batch

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def _extract_features_batch(serialized_batch):
        """

        :param serialized_batch:
        :return:
        """
        features = tf.parse_example(
            serialized_batch,
            features={'images': tf.FixedLenFeature([], tf.string),
                      'imagepaths': tf.FixedLenFeature([], tf.string),
                      'labels': tf.VarLenFeature(tf.int64),
                      }
        )
        bs = features['images'].shape[0]
        images = tf.decode_raw(features['images'], tf.uint8)
        w, h = tuple(CFG.ARCH.INPUT_SIZE)
        images = tf.cast(x=images, dtype=tf.float32)
        images = tf.reshape(images, [bs, h, w, CFG.ARCH.INPUT_CHANNELS])

        labels = features['labels']
        labels = tf.cast(labels, tf.int32)

        imagepaths = features['imagepaths']

        return images, labels, imagepaths 
开发者ID:MaybeShewill-CV,项目名称:CRNN_Tensorflow,代码行数:27,代码来源:tf_io_pipline_fast_tools.py

示例15: example_serving_input_fn

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import parse_example [as 别名]
def example_serving_input_fn():
  """Build the serving inputs."""
  example_bytestring = tf.placeholder(
      shape=[None],
      dtype=tf.string,
  )
  feature_scalars = tf.parse_example(
      example_bytestring,
      tf.feature_column.make_parse_example_spec(INPUT_COLUMNS)
  )
  return tf.estimator.export.ServingInputReceiver(
      features,
      {'example_proto': example_bytestring}
  )

# [START serving-function] 
开发者ID:amygdala,项目名称:code-snippets,代码行数:18,代码来源:model.py


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