tf.train.Example
Stay organized with collections
Save and categorize content based on your preferences.
An Example
is a mostly-normalized data format for storing data for training and inference.
It contains a key-value store features
where each key (string) maps to a
tf.train.Feature
message. 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.
In TensorFlow, Example
s are read in row-major
format, so any configuration that describes data with rank-2 or above
should keep this in mind. For example, to store an M x N
matrix of bytes,
the tf.train.BytesList
must contain M*N bytes, with M
rows of N
contiguous values
each. That is, the BytesList
value must store the matrix as:
.... row 0 .... // .... row 1 .... // ........... // ... row M-1 ....
An Example
for a movie recommendation application:
features {
feature {
key: "age"
value { float_list {
value: 29.0
} }
}
feature {
key: "movie"
value { bytes_list {
value: "The Shawshank Redemption"
value: "Fight Club"
} }
}
feature {
key: "movie_ratings"
value { float_list {
value: 9.0
value: 9.7
} }
}
feature {
key: "suggestion"
value { bytes_list {
value: "Inception"
} }
}
Note:that this feature exists to be used as a label in training.
# E.g., if training a logistic regression model to predict purchase
# probability in our learning tool we would set the label feature to
# "suggestion_purchased".
feature {
key: "suggestion_purchased"
value { float_list {
value: 1.0
} }
}
# Similar to "suggestion_purchased" above this feature exists to be used
# as a label in training.
# E.g., if training a linear regression model to predict purchase
# price in our learning tool we would set the label feature to
# "purchase_price".
feature {
key: "purchase_price"
value { float_list {
value: 9.99
} }
}
}
A conformant Example
dataset obeys the following conventions:
- If a Feature
K
exists in one example with data type T
, it must be of
type T
in all other examples when present. It may be omitted.
- The number of instances of Feature
K
list data may vary across examples,
depending on the requirements of the model.
- If a Feature
K
doesn't exist in an example, a K
-specific default will be
used, if configured.
- If a Feature
K
exists in an example but contains no items, the intent
is considered to be an empty tensor and no default will be used.
Attributes |
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 2021-05-14 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 2021-05-14 UTC."],[],[],null,["# tf.train.Example\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/train/Example) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/core/example/example.proto) |\n\nAn `Example` is a mostly-normalized data format for storing data for training and inference.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.train.Example`](https://www.tensorflow.org/api_docs/python/tf/train/Example)\n\n\u003cbr /\u003e\n\nIt contains a key-value store `features` where each key (string) maps to a\n[`tf.train.Feature`](../../tf/train/Feature) message. This flexible and compact format allows the\nstorage of large amounts of typed data, but requires that the data shape\nand use be determined by the configuration files and parsers that are used to\nread and write this format.\n\nIn TensorFlow, `Example`s are read in row-major\nformat, so any configuration that describes data with rank-2 or above\nshould keep this in mind. For example, to store an `M x N` matrix of bytes,\nthe [`tf.train.BytesList`](../../tf/train/BytesList) must contain M\\*N bytes, with `M` rows of `N` contiguous values\neach. That is, the `BytesList` value must store the matrix as:\n\n`.... row 0 .... // .... row 1 .... // ........... // ... row M-1 ....`\n\nAn `Example` for a movie recommendation application: \n\n features {\n feature {\n key: \"age\"\n value { float_list {\n value: 29.0\n } }\n }\n feature {\n key: \"movie\"\n value { bytes_list {\n value: \"The Shawshank Redemption\"\n value: \"Fight Club\"\n } }\n }\n feature {\n key: \"movie_ratings\"\n value { float_list {\n value: 9.0\n value: 9.7\n } }\n }\n feature {\n key: \"suggestion\"\n value { bytes_list {\n value: \"Inception\"\n } }\n }\n Note:that this feature exists to be used as a label in training.\n # E.g., if training a logistic regression model to predict purchase\n # probability in our learning tool we would set the label feature to\n # \"suggestion_purchased\".\n feature {\n key: \"suggestion_purchased\"\n value { float_list {\n value: 1.0\n } }\n }\n # Similar to \"suggestion_purchased\" above this feature exists to be used\n # as a label in training.\n # E.g., if training a linear regression model to predict purchase\n # price in our learning tool we would set the label feature to\n # \"purchase_price\".\n feature {\n key: \"purchase_price\"\n value { float_list {\n value: 9.99\n } }\n }\n }\n\nA conformant `Example` dataset obeys the following conventions:\n\n- If a Feature `K` exists in one example with data type `T`, it must be of type `T` in all other examples when present. It may be omitted.\n- The number of instances of Feature `K` list data may vary across examples, depending on the requirements of the model.\n- If a Feature `K` doesn't exist in an example, a `K`-specific default will be used, if configured.\n- If a Feature `K` exists in an example but contains no items, the intent is considered to be an empty tensor and no default will be used.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|------------|---------------------|\n| `features` | `Features features` |\n\n\u003cbr /\u003e"]]