[tf.data] Dataset.output_{types,shapes,classes} -> Dataset._element_structure.
This change adds a new abstract property called `tf.data.Dataset._element_structure`, to represent the potentially nested structure of dataset elements, and updates all `Dataset` subclasses to implement this property in preference to the existing `output_types`, `output_shapes`, and `output_classes` properties. These latter "legacy structure" properties remain, but will be removed from the API in TensorFlow 2.0, and only retained in 1.X compatibility mode.
To avoid breaking users who have extended `tf.data.Dataset`, a temporary implementation of `DatasetV1._element_structure` is provided using `structure.convert_legacy_structure()` to convert the existing legacy structure properties into a `Structure`.
To update other `Dataset` implementations to implement the new API:
1. Compute the `Structure` for your dataset.
(a) If you have built a legacy structure with `output_types`, `output_shapes`, and `output_classes`, you can set `self._element_structure = structure.convert_legacy_structure(output_types, output_shapes, output_classes)`.
(b) Alternatively, it may be easier to construct a `structure.TensorStructure`, `structure.SparseTensorStructure`, and/or `structure.NestedStructure` directly. See some of the modifications in this change for examples.
2. Implement the `element_structure` property, and delete the legacy structure properties from your implementation:
@property
def _element_structure(self):
return self._element_structure
3. (Optional.) Update your implementation to use the `_element_structure` property of the input dataset(s) rather than the legacy structure properties, which will be removed in a subsequent change.
PiperOrigin-RevId: 224246206
Loading
Please sign in to comment