tfr.keras.pipeline.AbstractDatasetBuilder

Interface for datasets and signatures.

The AbstractDatasetBuilder class is an abstract class to serve data in tfr.keras. A DatasetBuilder will be passed to an instance of AbstractPipeline and called to serve the training and validation datasets and to define the serving signatures for saved models to treat the corresponding format of data.

To be implemented by subclasses:

  • build_train_dataset(): Contains the logic to build a tf.data.Dataset for training.
  • build_valid_dataset(): Contains the logic to build a tf.data.Dataset for validation.
  • build_signatures(): Contains the logic to build a dict of signatures that formulate the model in functions that render the input data with given format.

Example subclass implementation:

class NullDatasetBuilder(AbstractDatasetBuilder):

  def __init__(self, train_dataset, valid_dataset, signatures=None):
    self._train_dataset = train_dataset
    self._valid_dataset = valid_dataset
    self._signatures = signatures

  def build_train_dataset(self, *arg, **kwargs) -> tf.data.Dataset:
    return self._train_dataset

  def build_valid_dataset(self, *arg, **kwargs) -> tf.data.Dataset:
    return self._valid_dataset

  def build_signatures(self, *arg, **kwargs) -> Any:
    return self._signatures

Methods

build_signatures

View source

Returns the signatures to export a SavedModel.

Example usage:

dataset_builder = NullDatasetBuilder(train_data, valid_data)
signatures = dataset_builder.build_signatures()

Args
*arg arguments that might be used to build signatures.
**kwargs keyword arguments that might be used to build signatures.

Returns
None or a dict of concrete functions.

build_train_dataset

View source

Returns the training dataset.

Example usage:

dataset_builder = NullDatasetBuilder(train_data, valid_data)
train_dataset = dataset_builder.build_train_dataset()

Args
*arg arguments that might be used to build training dataset.
**kwargs keyword arguments that might be used to build training dataset.

Returns
A tf.data.Dataset.

build_valid_dataset

View source

Returns the validation dataset.

Example usage:

dataset_builder = NullDatasetBuilder(train_data, valid_data)
valid_dataset = dataset_builder.build_valid_dataset()

Args
*arg arguments that might be used to build validation dataset.
**kwargs keyword arguments that might be used to build validation dataset.

Returns
A tf.data.Dataset.