tfds.decode.Decoder
Stay organized with collections
Save and categorize content based on your preferences.
Base decoder object.
tfds.decode.Decoder()
tfds.decode.Decoder
allows for overriding the default decoding by
implementing a subclass, or skipping it entirely with
tfds.decode.SkipDecoding
.
Instead of subclassing, you can also create a Decoder
from a function
with the 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
.
Attributes |
dtype
|
Returns the dtype after decoding.
|
feature
|
|
Methods
decode_batch_example
View source
decode_batch_example(
serialized_example
)
See FeatureConnector.decode_batch_example
for details.
decode_example
View source
@abc.abstractmethod
decode_example(
serialized_example
)
Decode the example feature field (eg: image).
Args |
serialized_example
|
tf.Tensor as decoded, the dtype/shape should be
identical to feature.get_serialized_info()
|
Returns |
example
|
Decoded example.
|
decode_ragged_example
View source
decode_ragged_example(
serialized_example
)
See FeatureConnector.decode_ragged_example
for details.
setup
View source
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.
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.
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."],[],[],null,["# tfds.decode.Decoder\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/datasets/blob/v4.9.3/tensorflow_datasets/core/decode/base.py#L25-L101) |\n\nBase decoder object. \n\n tfds.decode.Decoder()\n\n[`tfds.decode.Decoder`](../../tfds/decode/Decoder) allows for overriding the default decoding by\nimplementing a subclass, or skipping it entirely with\n[`tfds.decode.SkipDecoding`](../../tfds/decode/SkipDecoding).\n\nInstead of subclassing, you can also create a `Decoder` from a function\nwith the [`tfds.decode.make_decoder`](../../tfds/decode/make_decoder) decorator.\n\nAll decoders must derive from this base class. The implementation can\naccess the `self.feature` property which will correspond to the\n`FeatureConnector` to which this decoder is applied.\n\nTo implement a decoder, the main method to override is `decode_example`,\nwhich takes the serialized feature as input and returns the decoded feature.\n\nIf `decode_example` changes the output dtype, you must also override\nthe `dtype` property. This enables compatibility with\n[`tfds.features.Sequence`](../../tfds/features/Sequence).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------|-------------------------------------|\n| `dtype` | Returns the `dtype` after decoding. |\n| `feature` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `decode_batch_example`\n\n[View source](https://github.com/tensorflow/datasets/blob/v4.9.3/tensorflow_datasets/core/decode/base.py#L87-L95) \n\n decode_batch_example(\n serialized_example\n )\n\nSee [`FeatureConnector.decode_batch_example`](../../tfds/features/FeatureConnector#decode_batch_example) for details.\n\n### `decode_example`\n\n[View source](https://github.com/tensorflow/datasets/blob/v4.9.3/tensorflow_datasets/core/decode/base.py#L74-L85) \n\n @abc.abstractmethod\n decode_example(\n serialized_example\n )\n\nDecode the example feature field (eg: image).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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()` |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|------------------|\n| `example` | Decoded example. |\n\n\u003cbr /\u003e\n\n### `decode_ragged_example`\n\n[View source](https://github.com/tensorflow/datasets/blob/v4.9.3/tensorflow_datasets/core/decode/base.py#L97-L101) \n\n decode_ragged_example(\n serialized_example\n )\n\nSee [`FeatureConnector.decode_ragged_example`](../../tfds/features/FeatureConnector#decode_ragged_example) for details.\n\n### `setup`\n\n[View source](https://github.com/tensorflow/datasets/blob/v4.9.3/tensorflow_datasets/core/decode/base.py#L55-L66) \n\n setup(\n *, feature\n )\n\nTransformation contructor.\n\nThe initialization of decode object is deferred because the objects only\nknow the builder/features on which it is used after it has been\nconstructed, the initialization is done in this function.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|--------------------------------------------------------------------------------------------------------------------------------|\n| `feature` | [`tfds.features.FeatureConnector`](../../tfds/features/FeatureConnector), the feature to which is applied this transformation. |\n\n\u003cbr /\u003e"]]