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


Python v1.VarLenFeature方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def __init__(self, include_mask=False, regenerate_source_id=False):
    self._include_mask = include_mask
    self._regenerate_source_id = regenerate_source_id
    self._keys_to_features = {
        'image/encoded': tf.FixedLenFeature((), tf.string),
        'image/source_id': tf.FixedLenFeature((), tf.string, ''),
        'image/height': tf.FixedLenFeature((), tf.int64, -1),
        'image/width': tf.FixedLenFeature((), tf.int64, -1),
        'image/object/bbox/xmin': tf.VarLenFeature(tf.float32),
        'image/object/bbox/xmax': tf.VarLenFeature(tf.float32),
        'image/object/bbox/ymin': tf.VarLenFeature(tf.float32),
        'image/object/bbox/ymax': tf.VarLenFeature(tf.float32),
        'image/object/class/label': tf.VarLenFeature(tf.int64),
        'image/object/area': tf.VarLenFeature(tf.float32),
        'image/object/is_crowd': tf.VarLenFeature(tf.int64),
    }
    if include_mask:
      self._keys_to_features.update({
          'image/object/mask':
              tf.VarLenFeature(tf.string),
      }) 
開發者ID:JunweiLiang,項目名稱:Object_Detection_Tracking,代碼行數:23,代碼來源:tf_example_decoder.py

示例2: test_pad_or_clip_tensor_to_spec_shape

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def test_pad_or_clip_tensor_to_spec_shape(self, input_data, expected_output):
    varlen_spec = utils.ExtendedTensorSpec(
        shape=(3,), dtype=tf.int64, name='varlen', varlen_default_value=3.0)
    tmp_dir = self.create_tempdir().full_path
    file_path_padded_to_size_two = os.path.join(tmp_dir, 'size_two.tfrecord')
    self._write_test_examples(input_data, file_path_padded_to_size_two)
    dataset = tf.data.TFRecordDataset(
        filenames=tf.constant([file_path_padded_to_size_two]))
    dataset = dataset.batch(len(input_data), drop_remainder=True)

    def parse_fn(example):
      return tf.parse_example(example, {'varlen': tf.VarLenFeature(tf.int64)})

    dataset = dataset.map(parse_fn)
    sparse_tensors = dataset.make_one_shot_iterator().get_next()['varlen']
    default_value = tf.cast(
        tf.constant(varlen_spec.varlen_default_value), dtype=varlen_spec.dtype)
    tensor = utils.pad_or_clip_tensor_to_spec_shape(
        tf.sparse.to_dense(sparse_tensors, default_value), varlen_spec)
    with self.session() as sess:
      np_tensor = sess.run(tensor)
      self.assertAllEqual(np_tensor, np.array(expected_output)) 
開發者ID:google-research,項目名稱:tensor2robot,代碼行數:24,代碼來源:tensorspec_utils_test.py

示例3: _get_feature

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def _get_feature(tensor_spec,
                 decode_images = True):
  """Get FixedLenfeature or FixedLenSequenceFeature for a tensor spec."""
  varlen_default_value = getattr(tensor_spec, 'varlen_default_value', None)
  if getattr(tensor_spec, 'is_sequence', False):
    cls = tf.FixedLenSequenceFeature
  elif varlen_default_value is not None:
    cls = tf.VarLenFeature
  else:
    cls = tf.FixedLenFeature
  if decode_images and is_encoded_image_spec(tensor_spec):
    if varlen_default_value is not None:
      # Contains a variable length list of images.
      return cls(tf.string)
    elif len(tensor_spec.shape) > 3:
      # Contains a fixed length list of images.
      return cls((tensor_spec.shape[0]), tf.string)
    else:
      return cls((), tf.string)
  elif varlen_default_value is not None:
    return cls(tensor_spec.dtype)
  else:
    return cls(tensor_spec.shape, tensor_spec.dtype) 
開發者ID:google-research,項目名稱:tensor2robot,代碼行數:25,代碼來源:tensorspec_utils.py

示例4: parse_and_preprocess

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def parse_and_preprocess(self, value, batch_position):
    """Parse an TFRecord."""
    del batch_position
    assert self.supports_datasets()
    context_features = {
        'labels': tf.VarLenFeature(dtype=tf.int64),
        'input_length': tf.FixedLenFeature([], dtype=tf.int64),
        'label_length': tf.FixedLenFeature([], dtype=tf.int64),
    }
    sequence_features = {
        'features': tf.FixedLenSequenceFeature([161], dtype=tf.float32)
    }
    context_parsed, sequence_parsed = tf.parse_single_sequence_example(
        serialized=value,
        context_features=context_features,
        sequence_features=sequence_features,
    )

    return [
        # Input
        tf.expand_dims(sequence_parsed['features'], axis=2),
        # Label
        tf.cast(
            tf.reshape(
                tf.sparse_tensor_to_dense(context_parsed['labels']), [-1]),
            dtype=tf.int32),
        # Input length
        tf.cast(
            tf.reshape(context_parsed['input_length'], [1]),
            dtype=tf.int32),
        # Label length
        tf.cast(
            tf.reshape(context_parsed['label_length'], [1]),
            dtype=tf.int32),
    ] 
開發者ID:tensorflow,項目名稱:benchmarks,代碼行數:37,代碼來源:preprocessing.py

示例5: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "inputs": tf.VarLenFeature(tf.int64),
        "targets": tf.VarLenFeature(tf.int64),
        "floats": tf.VarLenFeature(tf.float32),
    }
    data_items_to_decoders = None
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:10,代碼來源:data_reader_test.py

示例6: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    label_key = "image/unpadded_label"
    data_fields, data_items_to_decoders = (
        super(ImageFSNS, self).example_reading_spec())
    data_fields[label_key] = tf.VarLenFeature(tf.int64)
    data_items_to_decoders["targets"] = contrib.slim().tfexample_decoder.Tensor(
        label_key)
    return data_fields, data_items_to_decoders 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:10,代碼來源:fsns.py

示例7: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {"dist_targets": tf.VarLenFeature(tf.int64)}

    if self.has_inputs:
      data_fields["inputs"] = tf.VarLenFeature(tf.int64)

    # hack: ignoring true targets and putting dist_targets in targets
    data_items_to_decoders = {
        "inputs": contrib.slim().tfexample_decoder.Tensor("inputs"),
        "targets": contrib.slim().tfexample_decoder.Tensor("dist_targets"),
    }

    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:15,代碼來源:translate.py

示例8: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "inputs": tf.VarLenFeature(tf.int64),
        "targets": tf.VarLenFeature(tf.int64),
        "section_boundaries": tf.VarLenFeature(tf.int64),
    }
    data_items_to_decoders = None
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:10,代碼來源:wikisum.py

示例9: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "inputs": tf.VarLenFeature(tf.int64),
        "audio/sample_count": tf.FixedLenFeature((), tf.int64),
        "audio/sample_width": tf.FixedLenFeature((), tf.int64),
        "targets": tf.VarLenFeature(tf.int64),
    }
    return data_fields, None 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:10,代碼來源:problem_hparams.py

示例10: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "inputs": tf.VarLenFeature(tf.float32),
        "targets": tf.VarLenFeature(tf.float32),
    }
    data_items_to_decoders = None
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:9,代碼來源:timeseries.py

示例11: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    label_key = "image/class/label"
    data_fields, data_items_to_decoders = (
        super(Image2TextProblem, self).example_reading_spec())
    data_fields[label_key] = tf.VarLenFeature(tf.int64)
    data_items_to_decoders["targets"] = contrib.slim().tfexample_decoder.Tensor(
        label_key)
    return data_fields, data_items_to_decoders 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:10,代碼來源:image_utils.py

示例12: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    """Define how data is serialized to file and read back.

    Returns:
      data_fields: A dictionary mapping data names to its feature type.
      data_items_to_decoders: A dictionary mapping data names to TF Example
         decoders, to be used when reading back TF examples from disk.
    """
    data_fields = {
        "inputs": tf.VarLenFeature(tf.int64),
        "targets": tf.VarLenFeature(tf.int64)
    }
    data_items_to_decoders = None
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:16,代碼來源:problem.py

示例13: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "waveforms": tf.VarLenFeature(tf.float32),
        "targets": tf.VarLenFeature(tf.int64),
    }

    data_items_to_decoders = None

    return data_fields, data_items_to_decoders 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:11,代碼來源:speech_recognition.py

示例14: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields, data_items_to_decoders = (super(QuestionAndContext2TextProblem,
                                                 self)
                                           .example_reading_spec())
    data_fields["context"] = tf.VarLenFeature(tf.int64)
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:8,代碼來源:text_problems.py

示例15: example_reading_spec

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import VarLenFeature [as 別名]
def example_reading_spec(self):
    data_fields = {
        "inputs": tf.VarLenFeature(tf.int64),
        "targets": tf.VarLenFeature(tf.float32),
    }
    data_items_to_decoders = None
    return (data_fields, data_items_to_decoders) 
開發者ID:tensorflow,項目名稱:tensor2tensor,代碼行數:9,代碼來源:gene_expression.py


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