PythonFunctionMap

class tfdatacompose.map.pythonfunctionmap.PythonFunctionMap(out_type: DType | Tuple[DType, ...])

Base class for mapping operations with arbitrary python code.

Wraps the Tensorflow Map operation on the dataset where the filter function is wrapped in py_function. The return type of the operation must be specified in advance for Tensorflow to build the computation graph. The filtering operation should be implemented in the map method. This operation should be used when your mapping can not be implemented in with Tensorflow operations. For example, if it needs to call an external library.

Parameters:

out_type – The return type of the operation

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

abstract map(*args) Any

Implement your transformation in this method. The method receives an element of the dataset as input and should return the transformed elements. You can change the arguments of this method to retrieve the inner element of tuples if your dataset elements are tuples. Example: map(self, x: int, y:int) -> int The implementation for the mapping can be arbitrary Python code.

Parameters:

args – the dataset element as a Tensor

Returns:

the transformed element.