tf.keras.layers.Pipeline

Applies a series of layers to an input.

Inherits From: Layer, Operation

This class is useful to build a preprocessing pipeline, in particular an image data augmentation pipeline. Compared to a Sequential model, Pipeline features a few important differences:

  • It's not a Model, just a plain layer.
  • When the layers in the pipeline are compatible with tf.data, the pipeline will also remain tf.data compatible. That is to say, the pipeline will not attempt to convert its inputs to backend-native tensors when in a tf.data context (unlike a Sequential model).

Example:

from keras import layers
preprocessing_pipeline = layers.Pipeline([
    layers.AutoContrast(),
    layers.RandomZoom(0.2),
    layers.RandomRotation(0.2),
])

# `ds` is a tf.data.Dataset
preprocessed_ds = ds.map(
    preprocessing_pipeline,
    num_parallel_calls=4,
)

input Retrieves the input tensor(s) of a symbolic operation.

Only returns the tensor(s) corresponding to the first time the operation was called.

layers

output Retrieves the output tensor(s) of a layer.

Only returns the tensor(s) corresponding to the first time the operation was called.

Methods

from_config

View source

Creates an operation from its config.

This method is the reverse of get_config, capable of instantiating the same operation from the config dictionary.

if "dtype" in config and isinstance(config["dtype"], dict):
    policy = dtype_policies.deserialize(config["dtype"])

Args
config A Python dictionary, typically the output of get_config.

Returns
An operation instance.