<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L32-L144) |

Builder class for preparing tf.train.Example.

    tfm.core.tf_example_builder.TfExampleBuilder() -> None

Read API doc at <https://www.tensorflow.org/api_docs/python/tf/train/Example>

<br />

<br />

<br />

| ## Example usage ||
|---|---|
| <br /> >>> example_builder = TfExampleBuilder() >>> example = ( example_builder.add_bytes_feature('feature_a', 'foobarbaz') .add_ints_feature('feature_b', [1, 2, 3]) .example) <br /> ||

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `example` | Returns a copy of the generated tf.train.Example proto. |
| `serialized_example` | Returns a serialized string of the generated tf.train.Example proto. |

<br />

## Methods

### `add_bytes_feature`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L100-L114)

    add_bytes_feature(
        key: str, value: BytesValueType
    ) -> TfExampleBuilder

Adds byte(s) or string(s) with `key` to the example.

<br />

<br />

<br />

| Args ||
|---|---|
| `key` | String key of the feature. |
| `value` | The byte(s) or string(s) to be added to the example. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The builder object for subsequent method calls. ||

<br />

### `add_feature`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L86-L98)

    add_feature(
        key: str, feature: tf.train.Feature
    ) -> TfExampleBuilder

Adds predefined `feature` with `key` to the example.

<br />

<br />

<br />

| Args ||
|---|---|
| `key` | String key of the feature. |
| `feature` | The feature to be added to the example. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The builder object for subsequent method calls. ||

<br />

### `add_feature_dict`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L69-L84)

    add_feature_dict(
        feature_dict: Mapping[str, tf.train.Feature]
    ) -> TfExampleBuilder

Adds the predefined `feature_dict` to the example.

> [!NOTE]
> **Note:** Please prefer to using feature-type-specific methods.

<br />

<br />

<br />

| Args ||
|---|---|
| `feature_dict` | A dictionary from tf.Example feature key to tf.train.Feature. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The builder object for subsequent method calls. ||

<br />

### `add_floats_feature`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L131-L144)

    add_floats_feature(
        key: str, value: Union[float, Sequence[float]]
    ) -> TfExampleBuilder

Adds float(s) with `key` to the example.

<br />

<br />

<br />

| Args ||
|---|---|
| `key` | String key of the feature. |
| `value` | The float(s) to be added to the example. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The builder object for subsequent method calls. ||

<br />

### `add_ints_feature`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L116-L129)

    add_ints_feature(
        key: str, value: Union[int, Sequence[int]]
    ) -> TfExampleBuilder

Adds integer(s) with `key` to the example.

<br />

<br />

<br />

| Args ||
|---|---|
| `key` | String key of the feature. |
| `value` | The integer(s) to be added to the example. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The builder object for subsequent method calls. ||

<br />

### `reset`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L63-L66)

    reset() -> TfExampleBuilder

Resets the example to an empty proto.

### `set`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/tf_example_builder.py#L58-L61)

    set(
        example: tf.train.Example
    ) -> TfExampleBuilder

Sets the example.