tfc.distributions.quantization_offset
Stay organized with collections
Save and categorize content based on your preferences.
Computes distribution-dependent quantization offset.
tfc.distributions.quantization_offset(
distribution
)
For range coding of continuous random variables, the values need to be
quantized first. Typically, it is beneficial for compression performance to
align the centers of the quantization bins such that one of them coincides
with the mode of the distribution. With offset
being the mode of the
distribution, for instance, this can be achieved simply by computing:
x_hat = tf.round(x - offset) + offset
This method tries to determine the offset in a best-effort fashion, based on
which statistics the Distribution
implements. First, a method
self._quantization_offset()
is tried. If that isn't defined, it tries in
turn: self.mode()
, self.quantile(.5)
, then self.mean()
. If none of
these are implemented, it falls back on quantizing to integer values (i.e.,
an offset of zero).
Note the offset is always in the range [-.5, .5] as it is assumed to be
combined with a round quantizer.
Returns |
A tf.Tensor broadcastable to shape self.batch_shape , containing
the determined quantization offsets. No gradients are allowed to flow
through the return value.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tfc.distributions.quantization_offset\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/compression/blob/v2.14.1/tensorflow_compression/python/distributions/helpers.py#L104-L147) |\n\nComputes distribution-dependent quantization offset.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tfc.quantization_offset`](https://www.tensorflow.org/api_docs/python/tfc/distributions/quantization_offset)\n\n\u003cbr /\u003e\n\n tfc.distributions.quantization_offset(\n distribution\n )\n\nFor range coding of continuous random variables, the values need to be\nquantized first. Typically, it is beneficial for compression performance to\nalign the centers of the quantization bins such that one of them coincides\nwith the mode of the distribution. With `offset` being the mode of the\ndistribution, for instance, this can be achieved simply by computing: \n\n x_hat = tf.round(x - offset) + offset\n\nThis method tries to determine the offset in a best-effort fashion, based on\nwhich statistics the `Distribution` implements. First, a method\n`self._quantization_offset()` is tried. If that isn't defined, it tries in\nturn: `self.mode()`, `self.quantile(.5)`, then `self.mean()`. If none of\nthese are implemented, it falls back on quantizing to integer values (i.e.,\nan offset of zero).\n\nNote the offset is always in the range \\[-.5, .5\\] as it is assumed to be\ncombined with a round quantizer.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| `distribution` | A [`tfp.distributions.Distribution`](https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/Distribution) object. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) broadcastable to shape `self.batch_shape`, containing the determined quantization offsets. No gradients are allowed to flow through the return value. ||\n\n\u003cbr /\u003e"]]