<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/layers/util.py#L268-L289) |

Serializes function for Keras.

    tfp.layers.util.serialize_function(
        func
    )

(De)serializing Python functions from/to bytecode is unsafe. Therefore we
return the function's type as an anonymous function ('lambda') or named
function in the Python environment ('function'). In the latter case, this lets
us use the Python scope to obtain the function rather than reload it from
bytecode. (Note that both cases are brittle!)

This serialization mimicks the implementation in `tf_keras.layers.Lambda`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `func` | Python function to serialize. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| (serial, function_type): Serialized object, which is a tuple of its bytecode (if function is anonymous) or name (if function is named), and its function type. ||

<br />