<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/experimental/nn/util/__init__.py) |

Utilitity functions for building neural networks.

## Classes

[`class CallOnce`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/CallOnce): Function object which memoizes the result of `create_value_fn()`.

[`class RandomVariable`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/RandomVariable): `RandomVariable` supports random variable semantics for TFP distributions.

## Functions

[`batchify_op(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/batchify_op): Reshape `op` input `x` to be a vec of `op_min_input_ndims`-rank tensors.

[`display_imgs(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/display_imgs): Display images as a grid.

[`expand_dims(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/expand_dims): Like [`tf.expand_dims`](https://www.tensorflow.org/api_docs/python/tf/expand_dims) but accepts a vector of axes to expand.

[`flatten_rightmost(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/flatten_rightmost): Flatten rightmost dims.

[`halflife_decay(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/halflife_decay): Interpolates `initial` to `final` using halflife (exponential) decay.

[`im2row(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/im2row): Rearrange image blocks into rows.

[`im2row_index(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/im2row_index): Computes indexes into a flattened image for building `im2row`.

[`make_convolution_fn(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_convolution_fn): Like [`tf.nn.conv2d`](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d) except applies batch of kernels to batch of `x`.

[`make_convolution_transpose_fn_with_dilation(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_convolution_transpose_fn_with_dilation): Like [`tf.nn.conv2d`](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d) except applies batch of kernels to batch of `x`.

[`make_convolution_transpose_fn_with_subkernels(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_convolution_transpose_fn_with_subkernels): Like [`tf.nn.conv2d`](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d) except applies batch of kernels to batch of `x`.

[`make_convolution_transpose_fn_with_subkernels_matrix(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_convolution_transpose_fn_with_subkernels_matrix): Like [`tf.nn.conv2d`](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d) except applies batch of kernels to batch of `x`.

[`make_fit_op(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_fit_op): One training step.

[`make_kernel_bias(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_kernel_bias): Creates kernel and bias as [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)s.

[`make_kernel_bias_posterior_mvn_diag(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_kernel_bias_posterior_mvn_diag): Create learnable posterior for Variational layers with kernel and bias.

[`make_kernel_bias_prior_spike_and_slab(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/make_kernel_bias_prior_spike_and_slab): Create prior for Variational layers with kernel and bias.

[`prepare_conv_args(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/prepare_conv_args): Sanitizes use provided input.

[`prepare_tuple_argument(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/prepare_tuple_argument): Helper which processes `Tensor`s to tuples in standard form.

[`tfcompile(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/tfcompile): Centralizes TF compilation related options.

[`trace(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/trace): Returns a function which prints info related to input.

[`tune_dataset(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/tune_dataset): Sets generally recommended parameters for a [`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset).

[`variables_load(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/variables_load): Assigns values to structure of [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)s from `filename`.

[`variables_save(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/variables_save): Saves structure of [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)s to `filename`.

[`variables_summary(...)`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/nn/util/variables_summary): Returns a list of summarizing `str`s.