<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L26-L114) |

Base decoder object.

    tfds.decode.Decoder()

[`tfds.decode.Decoder`](https://www.tensorflow.org/datasets/api_docs/python/tfds/decode/Decoder) allows for overriding the default decoding by
implementing a subclass, or skipping it entirely with
[`tfds.decode.SkipDecoding`](https://www.tensorflow.org/datasets/api_docs/python/tfds/decode/SkipDecoding).

Instead of subclassing, you can also create a `Decoder` from a function
with the [`tfds.decode.make_decoder`](https://www.tensorflow.org/datasets/api_docs/python/tfds/decode/make_decoder) decorator.

All decoders must derive from this base class. The implementation can
access the `self.feature` property which will correspond to the
`FeatureConnector` to which this decoder is applied.

To implement a decoder, the main method to override is `decode_example`,
which takes the serialized feature as input and returns the decoded feature.

If `decode_example` changes the output dtype, you must also override
the `dtype` property. This enables compatibility with
[`tfds.features.Sequence`](https://www.tensorflow.org/datasets/api_docs/python/tfds/features/Sequence).

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `dtype` | Returns the `dtype` after decoding. |
| `feature` | <br /> <br /> |

<br />

## Methods

### `decode_batch_example`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L100-L108)

    decode_batch_example(
        serialized_example
    )

See [`FeatureConnector.decode_batch_example`](https://www.tensorflow.org/datasets/api_docs/python/tfds/features/FeatureConnector#decode_batch_example) for details.

### `decode_example`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L75-L86)

    @abc.abstractmethod
    decode_example(
        serialized_example
    )

Decode the example feature field (eg: image).

<br />

<br />

<br />

| Args ||
|---|---|
| `serialized_example` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) as decoded, the dtype/shape should be identical to `feature.get_serialized_info()` |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `example` | Decoded example. |

<br />

### `decode_example_np`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L88-L98)

    decode_example_np(
        serialized_example
    )

Decode the example feature field for NumPy (eg: image).

<br />

<br />

<br />

| Args ||
|---|---|
| `serialized_example` | `np.array` as decoded, the dtype/shape should be identical to `feature.get_serialized_info()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `example` | Decoded example. Defaults to `decode_example`. |

<br />

### `decode_ragged_example`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L110-L114)

    decode_ragged_example(
        serialized_example
    )

See [`FeatureConnector.decode_ragged_example`](https://www.tensorflow.org/datasets/api_docs/python/tfds/features/FeatureConnector#decode_ragged_example) for details.

### `setup`

[View source](https://github.com/tensorflow/datasets/blob/v4.9.10/tensorflow_datasets/core/decode/base.py#L56-L67)

    setup(
        *, feature
    )

Transformation contructor.

The initialization of decode object is deferred because the objects only
know the builder/features on which it is used after it has been
constructed, the initialization is done in this function.

<br />

<br />

<br />

| Args ||
|---|---|
| `feature` | [`tfds.features.FeatureConnector`](https://www.tensorflow.org/datasets/api_docs/python/tfds/features/FeatureConnector), the feature to which is applied this transformation. |

<br />