[ Web Proxy ]
URL:
Viewing: https://www.tensorflow.org/api_docs/python/tf/train/Example#FromString [Back]  [Original]

tf.train.Example  |  TensorFlow v2.16.1 Skip to main content
TensorFlow [TensorFlow]

tf.train.Example Stay organized with collections Save and categorize content based on your preferences.

An Example is a standard proto storing data for training and inference.

View aliases

Compat aliases for migration

See Migration guide for more details.

tf.compat.v1.train.Example

Used in the notebooks

Used in the guide Used in the tutorials

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

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

It contains a key-value store Example.features where each key (string) maps to a tf.train.Feature message which contains a fixed-type list. This flexible and compact format allows the storage of large amounts of typed data, but requires that the data shape and use be determined by the configuration files and parsers that are used to read and write this format (refer to tf.io.parse_example for details).

from google.protobuf import text_format
example = text_format.Parse('''
  features {
    feature {key: "my_feature"
             value {int64_list {value: [1, 2, 3, 4]} } }
  }''',
  tf.train.Example())

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

tf.io.parse_example(
    example.SerializeToString(),
    features = {'my_feature': tf.io.RaggedFeature(dtype=tf.int64)})
{'my_feature': <tf.Tensor: shape=(4,), dtype=float32,
                           numpy=array([1, 2, 3, 4], dtype=int64)>}

While the list of keys, and the contents of each key could be different for every Example, TensorFlow expects a fixed list of keys, each with a fixed tf.dtype. A conformant Example dataset obeys the following conventions:

features Features features

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.

Last updated 2024-04-26 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page