Applies a python function to some Tensors given by the argument list. The
number of arguments should match the number of inputs to the function.
This function is for using inside a preprocessing_fn. It is a wrapper around
tf.py_func. A function added this way can run in Transform, and during
training when the graph is imported using the transform_raw_features method
of the TFTransformOutput class. However if the resulting training graph is
serialized and deserialized, then the tf.py_func op will not work and will
cause an error. This means that TensorFlow Serving will not be able to serve
this graph.
The underlying reason for this limited support is that tf.py_func ops were
not designed to be serialized since they contain a reference to arbitrary
Python functions. This function pickles those functions and including them in
the graph, and transform_raw_features similarly unpickles the functions.
But unpickling requires a Python environment, so there it's not possible to
provide support in non-Python languages for loading such ops. Therefore
loading these ops in libraries such as TensorFlow Serving is not supported.
Args
func
A Python function, which accepts a list of NumPy ndarray objects
having element types that match the corresponding tf.Tensor objects
in *args, and returns a list of ndarray objects (or a single
ndarray) having element types that match the corresponding values
in Tout.
Tout
A list or tuple of tensorflow data types or a single tensorflow data
type if there is only one, indicating what func returns.
stateful
(Boolean.) If True, the function should be considered stateful.
If a function is stateless, when given the same input it will return the
same output and have no observable side effects. Optimizations such as
common subexpression elimination are only performed on stateless
operations.
name
A name for the operation (optional).
*args
The list of Tensors to apply the arguments to.
Returns
A Tensor representing the application of the function.
[null,null,["Last updated 2024-11-01 UTC."],[],[],null,["# tft.apply_pyfunc\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/transform/blob/v1.16.0/tensorflow_transform/py_func/api.py#L20-L63) |\n\nApplies a python function to some `Tensor`s. \n\n tft.apply_pyfunc(\n func, Tout, stateful=True, name=None, *args\n )\n\nApplies a python function to some `Tensor`s given by the argument list. The\nnumber of arguments should match the number of inputs to the function.\n\nThis function is for using inside a preprocessing_fn. It is a wrapper around\n`tf.py_func`. A function added this way can run in Transform, and during\ntraining when the graph is imported using the `transform_raw_features` method\nof the `TFTransformOutput` class. However if the resulting training graph is\nserialized and deserialized, then the `tf.py_func` op will not work and will\ncause an error. This means that TensorFlow Serving will not be able to serve\nthis graph.\n\nThe underlying reason for this limited support is that `tf.py_func` ops were\nnot designed to be serialized since they contain a reference to arbitrary\nPython functions. This function pickles those functions and including them in\nthe graph, and `transform_raw_features` similarly unpickles the functions.\nBut unpickling requires a Python environment, so there it's not possible to\nprovide support in non-Python languages for loading such ops. Therefore\nloading these ops in libraries such as TensorFlow Serving is not supported.\n| **Note:** This API can only be used when TF2 is disabled or `tft_beam.Context.force_tf_compat_v1=True`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `func` | A Python function, which accepts a list of NumPy `ndarray` objects having element types that match the corresponding [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) objects in `*args`, and returns a list of `ndarray` objects (or a single `ndarray`) having element types that match the corresponding values in `Tout`. |\n| `Tout` | A list or tuple of tensorflow data types or a single tensorflow data type if there is only one, indicating what `func` returns. |\n| `stateful` | (Boolean.) If True, the function should be considered stateful. If a function is stateless, when given the same input it will return the same output and have no observable side effects. Optimizations such as common subexpression elimination are only performed on stateless operations. |\n| `name` | A name for the operation (optional). |\n| `*args` | The list of `Tensor`s to apply the arguments to. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` representing the application of the function. ||\n\n\u003cbr /\u003e"]]