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


Python parsing_ops.FixedLenFeature方法代码示例

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


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

示例1: _parse_example_spec

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [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: make_place_holder_tensors_for_base_features

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [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

示例3: DecodeExample

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def DecodeExample(self, serialized_example, item_handler, image_format):
    """Decodes the given serialized example with the specified item handler.

    Args:
      serialized_example: a serialized TF example string.
      item_handler: the item handler used to decode the image.
      image_format: the image format being decoded.

    Returns:
      the decoded image found in the serialized Example.
    """
    serialized_example = array_ops.reshape(serialized_example, shape=[])
    decoder = tfexample_decoder.TFExampleDecoder(
        keys_to_features={
            'image/encoded':
                parsing_ops.FixedLenFeature(
                    (), dtypes.string, default_value=''),
            'image/format':
                parsing_ops.FixedLenFeature(
                    (), dtypes.string, default_value=image_format),
        },
        items_to_handlers={'image': item_handler})
    [tf_image] = decoder.decode(serialized_example, ['image'])
    return tf_image 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:26,代码来源:tfexample_decoder_test.py

示例4: testDecodeExampleWithFloatTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithFloatTensor(self):
    np_array = np.random.rand(2, 3, 1).astype('f')

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

    serialized_example = example.SerializeToString()

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

示例5: testDecodeExampleWithInt64Tensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithInt64Tensor(self):
    np_array = np.random.randint(1, 10, size=(2, 3, 1))

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

    serialized_example = example.SerializeToString()

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

示例6: testDecodeExampleWithFixLenTensorWithShape

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithFixLenTensorWithShape(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.FixedLenFeature(
                  np_array.shape, 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,代码行数:27,代码来源:tfexample_decoder_test.py

示例7: DecodeExample

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def DecodeExample(self, serialized_example, item_handler, image_format):
    """Decodes the given serialized example with the specified item handler.

    Args:
      serialized_example: a serialized TF example string.
      item_handler: the item handler used to decode the image.
      image_format: the image format being decoded.

    Returns:
      the decoded image found in the serialized Example.
    """
    serialized_example = array_ops.reshape(serialized_example, shape=[])
    decoder = tfexample_decoder.TFExampleDecoder(
        keys_to_features={
            'image/encoded':
                parsing_ops.FixedLenFeature((), tf.string, default_value=''),
            'image/format':
                parsing_ops.FixedLenFeature((),
                                            tf.string,
                                            default_value=image_format),
        },
        items_to_handlers={'image': item_handler})
    [tf_image] = decoder.decode(serialized_example, ['image'])
    return tf_image 
开发者ID:google-research,项目名称:tf-slim,代码行数:26,代码来源:tfexample_decoder_test.py

示例8: testDecodeExampleWithFloatTensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithFloatTensor(self):
    np_array = np.random.rand(2, 3, 1).astype('f')

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

    serialized_example = example.SerializeToString()

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

示例9: testDecodeExampleWithInt64Tensor

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithInt64Tensor(self):
    np_array = np.random.randint(1, 10, size=(2, 3, 1))

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

    serialized_example = example.SerializeToString()

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

示例10: testDecodeExampleWithFixLenTensorWithShape

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def testDecodeExampleWithFixLenTensorWithShape(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.FixedLenFeature(np_array.shape, 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,代码行数:25,代码来源:tfexample_decoder_test.py

示例11: __init__

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def __init__(self, keys_to_features, items_to_handlers):
    """Constructs the decoder.

    Args:
      keys_to_features: a dictionary from TF-Example keys to either
        tf.VarLenFeature or tf.FixedLenFeature instances. See tensorflow's
        parsing_ops.py.
      items_to_handlers: a dictionary from items (strings) to ItemHandler
        instances. Note that the ItemHandler's are provided the keys that they
        use to return the final item Tensors.
    """
    self._keys_to_features = keys_to_features
    self._items_to_handlers = items_to_handlers 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:tfexample_decoder.py

示例12: decode

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def decode(self, serialized_example, items=None):
    """Decodes the given serialized TF-example.

    Args:
      serialized_example: a serialized TF-example 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.
    """
    example = parsing_ops.parse_single_example(serialized_example,
                                               self._keys_to_features)

    # Reshape non-sparse elements just once:
    for k in self._keys_to_features:
      v = self._keys_to_features[k]
      if isinstance(v, parsing_ops.FixedLenFeature):
        example[k] = array_ops.reshape(example[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: example[key] for key in handler.keys}
      outputs.append(handler.tensors_to_item(keys_to_tensors))
    return outputs 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:32,代码来源:tfexample_decoder.py

示例13: _to_feature_spec

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [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

示例14: _get_default_value

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def _get_default_value(feature_spec):
  if isinstance(feature_spec, parsing_ops.FixedLenFeature):
    return feature_spec.default_value
  else:
    return _dtype_to_nan(feature_spec.dtype) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:tensorflow_dataframe.py

示例15: get_feature_spec

# 需要导入模块: from tensorflow.python.ops import parsing_ops [as 别名]
# 或者: from tensorflow.python.ops.parsing_ops import FixedLenFeature [as 别名]
def get_feature_spec(self):
    dtype = self.dtype
    # Convert, because example parser only supports float32, int64 and string.
    if dtype == dtypes.int32:
      dtype = dtypes.int64
    if dtype == dtypes.float64:
      dtype = dtypes.float32
    if self.is_sparse:
      return parsing_ops.VarLenFeature(dtype=dtype)
    return parsing_ops.FixedLenFeature(shape=self.shape[1:], dtype=dtype) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:tensor_signature.py


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