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


Python parsing_ops.VarLenFeature方法代码示例

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


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

示例1: _parse_example_spec

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def _parse_example_spec(self):
    """Returns a `tf.Example` parsing spec as dict.

    It is used for get_parsing_spec for `tf.parse_example`. Returned spec is a
    dict from keys ('string') to `VarLenFeature`, `FixedLenFeature`, and other
    supported objects. Please check documentation of ${tf.parse_example} for all
    supported spec objects.

    Let's say a Feature column depends on raw feature ('raw') and another
    `_FeatureColumn` (input_fc). One possible implementation of
    _parse_example_spec is as follows:

    ```python
    spec = {'raw': tf.FixedLenFeature(...)}
    spec.update(input_fc._parse_example_spec)
    return spec
    ```
    """
    pass 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:feature_column.py

示例2: _get_sparse_tensors

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def _get_sparse_tensors(self,
                          inputs,
                          weight_collections=None,
                          trainable=None):
    """Returns an IdWeightPair.

    `IdWeightPair` is a pair of `SparseTensor`s which represents ids and
    weights.

    `IdWeightPair.id_tensor` is typically a `batch_size` x `num_buckets`
    `SparseTensor` of `int64`. `IdWeightPair.weight_tensor` is either a
    `SparseTensor` of `float` or `None` to indicate all weights should be
    taken to be 1. If specified, `weight_tensor` must have exactly the same
    shape and indices as `sp_ids`. Expected `SparseTensor` is same as parsing
    output of a `VarLenFeature` which is a ragged matrix.

    Args:
      inputs: A `LazyBuilder` as a cache to get input tensors required to
        create `IdWeightPair`.
      weight_collections: List of graph collections to which variables (if any
        will be created) are added.
      trainable: If `True` also add variables to the graph collection
        `GraphKeys.TRAINABLE_VARIABLES` (see ${tf.get_variable}).
    """
    pass 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:feature_column.py

示例3: make_place_holder_tensors_for_base_features

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def make_place_holder_tensors_for_base_features(feature_columns):
  """Returns placeholder tensors for inference.

  Args:
    feature_columns: An iterable containing all the feature columns. All items
      should be instances of classes derived from _FeatureColumn.
  Returns:
    A dict mapping feature keys to SparseTensors (sparse columns) or
    placeholder Tensors (dense columns).
  """
  # Get dict mapping features to FixedLenFeature or VarLenFeature values.
  dict_for_parse_example = create_feature_spec_for_parsing(feature_columns)
  placeholders = {}
  for column_name, column_type in dict_for_parse_example.items():
    if isinstance(column_type, parsing_ops.VarLenFeature):
      # Sparse placeholder for sparse tensors.
      placeholders[column_name] = array_ops.sparse_placeholder(
          column_type.dtype, name="Placeholder_{}".format(column_name))
    else:
      # Simple placeholder for dense tensors.
      placeholders[column_name] = array_ops.placeholder(
          column_type.dtype,
          shape=(None, column_type.shape[0]),
          name="Placeholder_{}".format(column_name))
  return placeholders 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:feature_column.py

示例4: testDecodeExampleWithVarLenTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithVarLenTensor(self):
    np_array = np.array([[[1], [2], [3]], [[4], [5], [6]]])

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'labels': self._EncodedInt64Feature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {'labels': tfexample_decoder.Tensor('labels'),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array.flatten()) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:tfexample_decoder_test.py

示例5: testDecodeExampleWithVarLenTensorToDense

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithVarLenTensorToDense(self):
    np_array = np.array([[1, 2, 3], [4, 5, 6]])
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'labels': self._EncodedInt64Feature(np_array),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {
          'labels': tfexample_decoder.Tensor(
              'labels', shape=np_array.shape),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:24,代码来源:tfexample_decoder_test.py

示例6: testDecodeExampleWithSparseTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithSparseTensor(self):
    np_indices = np.array([[1], [2], [5]])
    np_values = np.array([0.1, 0.2, 0.6]).astype('f')
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'indices': self._EncodedInt64Feature(np_indices),
        'values': self._EncodedFloatFeature(np_values),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'indices': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'values': parsing_ops.VarLenFeature(dtype=dtypes.float32),
      }
      items_to_handlers = {'labels': tfexample_decoder.SparseTensor(),}
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels.indices, np_indices)
      self.assertAllEqual(labels.values, np_values)
      self.assertAllEqual(labels.dense_shape, np_values.shape) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:26,代码来源:tfexample_decoder_test.py

示例7: testDecodeExampleWithVarLenTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithVarLenTensor(self):
    np_array = np.array([[[1], [2], [3]], [[4], [5], [6]]])

    example = tf.train.Example(
        features=tf.train.Features(feature={
            'labels': self._EncodedInt64Feature(np_array),
        }))

    serialized_example = example.SerializeToString()

    with self.cached_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=tf.int64),
      }
      items_to_handlers = {
          'labels': tfexample_decoder.Tensor('labels'),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array.flatten()) 
开发者ID:google-research,项目名称:tf-slim,代码行数:25,代码来源:tfexample_decoder_test.py

示例8: testDecodeExampleWithVarLenTensorToDense

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithVarLenTensorToDense(self):
    np_array = np.array([[1, 2, 3], [4, 5, 6]])
    example = tf.train.Example(
        features=tf.train.Features(feature={
            'labels': self._EncodedInt64Feature(np_array),
        }))

    serialized_example = example.SerializeToString()

    with self.cached_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'labels': parsing_ops.VarLenFeature(dtype=tf.int64),
      }
      items_to_handlers = {
          'labels': tfexample_decoder.Tensor('labels', shape=np_array.shape),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels, np_array) 
开发者ID:google-research,项目名称:tf-slim,代码行数:24,代码来源:tfexample_decoder_test.py

示例9: _to_feature_spec

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def _to_feature_spec(tensor, default_value=None):
  if isinstance(tensor, sparse_tensor.SparseTensor):
    return parsing_ops.VarLenFeature(dtype=tensor.dtype)
  else:
    return parsing_ops.FixedLenFeature(shape=tensor.get_shape(),
                                       dtype=tensor.dtype,
                                       default_value=default_value) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:estimator_utils.py

示例10: config

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def config(self):
    return {self.column_name: parsing_ops.VarLenFeature(self.dtype)} 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:feature_column.py

示例11: testDecodeExampleShapeKeyTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleShapeKeyTensor(self):
    np_image = np.random.rand(2, 3, 1).astype('f')
    np_labels = np.array([[[1], [2], [3]], [[4], [5], [6]]])

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'image': self._EncodedFloatFeature(np_image),
        'image/shape': self._EncodedInt64Feature(np.array(np_image.shape)),
        'labels': self._EncodedInt64Feature(np_labels),
        'labels/shape': self._EncodedInt64Feature(np.array(np_labels.shape)),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'image': parsing_ops.VarLenFeature(dtype=dtypes.float32),
          'image/shape': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels/shape': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {
          'image':
              tfexample_decoder.Tensor(
                  'image', shape_keys='image/shape'),
          'labels':
              tfexample_decoder.Tensor(
                  'labels', shape_keys='labels/shape'),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_image, tf_labels] = decoder.decode(serialized_example,
                                             ['image', 'labels'])
      self.assertAllEqual(tf_image.eval(), np_image)
      self.assertAllEqual(tf_labels.eval(), np_labels) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:37,代码来源:tfexample_decoder_test.py

示例12: testDecodeExampleMultiShapeKeyTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleMultiShapeKeyTensor(self):
    np_image = np.random.rand(2, 3, 1).astype('f')
    np_labels = np.array([[[1], [2], [3]], [[4], [5], [6]]])
    height, width, depth = np_labels.shape

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'image': self._EncodedFloatFeature(np_image),
        'image/shape': self._EncodedInt64Feature(np.array(np_image.shape)),
        'labels': self._EncodedInt64Feature(np_labels),
        'labels/height': self._EncodedInt64Feature(np.array([height])),
        'labels/width': self._EncodedInt64Feature(np.array([width])),
        'labels/depth': self._EncodedInt64Feature(np.array([depth])),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'image': parsing_ops.VarLenFeature(dtype=dtypes.float32),
          'image/shape': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels/height': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels/width': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'labels/depth': parsing_ops.VarLenFeature(dtype=dtypes.int64),
      }
      items_to_handlers = {
          'image':
              tfexample_decoder.Tensor(
                  'image', shape_keys='image/shape'),
          'labels':
              tfexample_decoder.Tensor(
                  'labels',
                  shape_keys=['labels/height', 'labels/width', 'labels/depth']),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_image, tf_labels] = decoder.decode(serialized_example,
                                             ['image', 'labels'])
      self.assertAllEqual(tf_image.eval(), np_image)
      self.assertAllEqual(tf_labels.eval(), np_labels) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:43,代码来源:tfexample_decoder_test.py

示例13: testDecodeExampleWithSparseTensorWithGivenShape

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithSparseTensorWithGivenShape(self):
    np_indices = np.array([[1], [2], [5]])
    np_values = np.array([0.1, 0.2, 0.6]).astype('f')
    np_shape = np.array([6])
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'indices': self._EncodedInt64Feature(np_indices),
        'values': self._EncodedFloatFeature(np_values),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'indices': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'values': parsing_ops.VarLenFeature(dtype=dtypes.float32),
      }
      items_to_handlers = {
          'labels': tfexample_decoder.SparseTensor(shape=np_shape),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllEqual(labels.indices, np_indices)
      self.assertAllEqual(labels.values, np_values)
      self.assertAllEqual(labels.dense_shape, np_shape) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:29,代码来源:tfexample_decoder_test.py

示例14: testDecodeExampleWithSparseTensorToDense

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithSparseTensorToDense(self):
    np_indices = np.array([1, 2, 5])
    np_values = np.array([0.1, 0.2, 0.6]).astype('f')
    np_shape = np.array([6])
    np_dense = np.array([0.0, 0.1, 0.2, 0.0, 0.0, 0.6]).astype('f')
    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'indices': self._EncodedInt64Feature(np_indices),
        'values': self._EncodedFloatFeature(np_values),
    }))

    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])
      keys_to_features = {
          'indices': parsing_ops.VarLenFeature(dtype=dtypes.int64),
          'values': parsing_ops.VarLenFeature(dtype=dtypes.float32),
      }
      items_to_handlers = {
          'labels':
              tfexample_decoder.SparseTensor(
                  shape=np_shape, densify=True),
      }
      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_labels] = decoder.decode(serialized_example, ['labels'])
      labels = tf_labels.eval()
      self.assertAllClose(labels, np_dense) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:30,代码来源:tfexample_decoder_test.py

示例15: testDecodeExampleWithBoundingBox

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import VarLenFeature [as 别名]
def testDecodeExampleWithBoundingBox(self):
    num_bboxes = 10
    np_ymin = np.random.rand(num_bboxes, 1)
    np_xmin = np.random.rand(num_bboxes, 1)
    np_ymax = np.random.rand(num_bboxes, 1)
    np_xmax = np.random.rand(num_bboxes, 1)
    np_bboxes = np.hstack([np_ymin, np_xmin, np_ymax, np_xmax])

    example = example_pb2.Example(features=feature_pb2.Features(feature={
        'image/object/bbox/ymin': self._EncodedFloatFeature(np_ymin),
        'image/object/bbox/xmin': self._EncodedFloatFeature(np_xmin),
        'image/object/bbox/ymax': self._EncodedFloatFeature(np_ymax),
        'image/object/bbox/xmax': self._EncodedFloatFeature(np_xmax),
    }))
    serialized_example = example.SerializeToString()

    with self.test_session():
      serialized_example = array_ops.reshape(serialized_example, shape=[])

      keys_to_features = {
          'image/object/bbox/ymin': parsing_ops.VarLenFeature(dtypes.float32),
          'image/object/bbox/xmin': parsing_ops.VarLenFeature(dtypes.float32),
          'image/object/bbox/ymax': parsing_ops.VarLenFeature(dtypes.float32),
          'image/object/bbox/xmax': parsing_ops.VarLenFeature(dtypes.float32),
      }

      items_to_handlers = {
          'object/bbox':
              tfexample_decoder.BoundingBox(['ymin', 'xmin', 'ymax', 'xmax'],
                                            'image/object/bbox/'),
      }

      decoder = tfexample_decoder.TFExampleDecoder(keys_to_features,
                                                   items_to_handlers)
      [tf_bboxes] = decoder.decode(serialized_example, ['object/bbox'])
      bboxes = tf_bboxes.eval()

    self.assertAllClose(np_bboxes, bboxes) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:40,代码来源:tfexample_decoder_test.py


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