Entropy Models¶
Entropy bottleneck and hyperprior models for learned compression.
Overview¶
Entropy models are a critical component of learned compression. They model the probability distribution of latent representations, enabling efficient entropy coding.
Entropy Bottleneck¶
The entropy bottleneck is used to compress the latent representation of an image. It learns a flexible density model of the latent distribution.
EntropyBottleneck
¶
Bases: EntropyModel
Entropy bottleneck layer, introduced by J. Balle, D. Minnen, S. Singh,
S. J. Hwang, N. Johnston, in "Variational image compression with a scale
hyperprior" <https://arxiv.org/abs/1802.01436>_.
This is a re-implementation of the entropy bottleneck layer in
tensorflow/compression. See the original paper and the tensorflow
documentation
<https://github.com/tensorflow/compression/blob/v1.3/docs/entropy_bottleneck.md>__
for an introduction.
Source code in tinify/entropy_models/entropy_models.py
forward
¶
Source code in tinify/entropy_models/entropy_models.py
compress
¶
Source code in tinify/entropy_models/entropy_models.py
decompress
¶
Source code in tinify/entropy_models/entropy_models.py
loss
¶
update
¶
Source code in tinify/entropy_models/entropy_models.py
Gaussian Conditional¶
GaussianConditional
¶
Bases: EntropyModel
Gaussian conditional layer, introduced by J. Balle, D. Minnen, S. Singh,
S. J. Hwang, N. Johnston, in "Variational image compression with a scale
hyperprior" <https://arxiv.org/abs/1802.01436>_.
This is a re-implementation of the Gaussian conditional layer in
tensorflow/compression. See the tensorflow documentation
<https://github.com/tensorflow/compression/blob/v1.3/docs/api_docs/python/tfc/GaussianConditional.md>__
for more information.
Source code in tinify/entropy_models/entropy_models.py
forward
¶
Source code in tinify/entropy_models/entropy_models.py
Entropy Model Base¶
EntropyModel
¶
Bases: Module
Entropy model base class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
likelihood_bound
|
float
|
minimum likelihood bound |
1e-09
|
entropy_coder
|
str
|
set the entropy coder to use, use default one if None |
None
|
entropy_coder_precision
|
int
|
set the entropy coder precision |
16
|
compress
¶
Compress input tensors to char strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Tensor
|
input tensors |
required |
indexes
|
Tensor
|
tensors CDF indexes |
required |
means
|
Tensor
|
optional tensor means |
None
|
decompress
¶
Decompress char strings to tensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strings
|
list[bytes]
|
compressed tensors |
required |
indexes
|
Tensor
|
tensors CDF indexes |
required |
dtype
|
dtype
|
type of dequantized output |
float
|
means
|
Tensor
|
optional tensor means |
None
|