NumpyLambdaMap

class tfdatacompose.lambdamap.numpylambdamap.NumpyLambdaMap(out_type: DType | Tuple[DType, ...], map: Callable[[...], Tensor | Tuple[Tensor, ...]], stateful: bool = False)

Base class for inline mapping operations that require numpy arrays.

Wraps the Tensorflow Map operation on the dataset where the filter function is wrapped in numpy_function. The return type of the operation must be specified in advance for Tensorflow to build the computation graph. Transformations should be implemented in the map constructor parameter. For short operations, this class can be used to avoid subclassing NumpyMap. This operation is useful if your mapping can not be implemented in with Tensorflow operations, for instance, if it needs to call an external library.

Parameters:
  • out_type – The return type of the operation

  • map – lambda function implementing the transformation.

  • stateful – Whether the operation is stateless. Tensorflow can enable some optimizations on stateless functions to improve performance.

apply(dataset: DatasetV1) DatasetV1

Applies the operation on the given dataset and returns the new dataset.

Parameters:

datasetTensorflow Dataset The dataset to change

Returns:

Tensorflow Dataset The changed dataset