TF 2.0 is out! Get hands-on practice at TF World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

tfds.decode.Decoder

View source

Class Decoder

Base decoder object.

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.

__init__

View source

__init__()

Properties

dtype

Returns the dtype after decoding.

Methods

decode_example

View source

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.

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.

Args: