Spec-Zone.ru › TensorFlow

tf.train.Features

Used in tf.train.Example protos. Contains the mapping from keys to Feature.

View aliases

Compat aliases for migration

See Migration guide for more details.

tf.compat.v1.train.Features

Used in the notebooks

Used in the tutorials
  • TFRecord and tf.train.Example
  • Graph regularization for sentiment classification using synthesized graphs
  • Graph-based Neural Structured Learning in TFX
  • Instance Segmentation with Model Garden
  • Semantic Segmentation with Model Garden

An Example proto is a representation of the following python type:

Dict[str,
     Union[List[bytes],
           List[int64],
           List[float]]]

This proto implements the Dict.

int_feature = tf.train.Feature(
    int64_list=tf.train.Int64List(value=[1, 2, 3, 4]))
float_feature = tf.train.Feature(
    float_list=tf.train.FloatList(value=[1., 2., 3., 4.]))
bytes_feature = tf.train.Feature(
    bytes_list=tf.train.BytesList(value=[b"abc", b"1234"]))

example = tf.train.Example(
    features=tf.train.Features(feature={
        'my_ints': int_feature,
        'my_floats': float_feature,
        'my_bytes': bytes_feature,
    }))

Use tf.io.parse_example to extract tensors from a serialized Example proto:

tf.io.parse_example(
    example.SerializeToString(),
    features = {
        'my_ints': tf.io.RaggedFeature(dtype=tf.int64),
        'my_floats': tf.io.RaggedFeature(dtype=tf.float32),
        'my_bytes': tf.io.RaggedFeature(dtype=tf.string)})
{'my_bytes': <tf.Tensor: shape=(2,), dtype=string,
                         numpy=array([b'abc', b'1234'], dtype=object)>,
 'my_floats': <tf.Tensor: shape=(4,), dtype=float32,
                          numpy=array([1., 2., 3., 4.], dtype=float32)>,
 'my_ints': <tf.Tensor: shape=(4,), dtype=int64,
                        numpy=array([1, 2, 3, 4])>}
Attributes
feature repeated FeatureEntry feature

Child Classes

class FeatureEntry

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/train/Features

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API