Skip to content

Commit 3f5dca4

Browse files
Johannes Ballécopybara-github
authored andcommitted
Docstring/namespace fixes.
PiperOrigin-RevId: 449469688 Change-Id: If188fa57655c93139637f1d051c83447875ffcbb
1 parent 55ba808 commit 3f5dca4

File tree

8 files changed

+68
-13
lines changed

8 files changed

+68
-13
lines changed

BUILD

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,29 @@ py_library(
1111
srcs = ["tensorflow_compression/__init__.py"],
1212
visibility = ["//visibility:public"],
1313
deps = [
14-
"//tensorflow_compression/python/datasets",
14+
"//tensorflow_compression/python/datasets:y4m_dataset",
1515
"//tensorflow_compression/python/distributions",
16+
"//tensorflow_compression/python/distributions:deep_factorized",
17+
"//tensorflow_compression/python/distributions:helpers",
18+
"//tensorflow_compression/python/distributions:round_adapters",
19+
"//tensorflow_compression/python/distributions:uniform_noise",
1620
"//tensorflow_compression/python/entropy_models",
21+
"//tensorflow_compression/python/entropy_models:continuous_batched",
22+
"//tensorflow_compression/python/entropy_models:continuous_indexed",
23+
"//tensorflow_compression/python/entropy_models:power_law",
24+
"//tensorflow_compression/python/entropy_models:universal",
1725
"//tensorflow_compression/python/layers",
26+
"//tensorflow_compression/python/layers:gdn",
27+
"//tensorflow_compression/python/layers:initializers",
28+
"//tensorflow_compression/python/layers:parameters",
29+
"//tensorflow_compression/python/layers:signal_conv",
30+
"//tensorflow_compression/python/layers:soft_round",
1831
"//tensorflow_compression/python/ops",
19-
"//tensorflow_compression/python/util",
32+
"//tensorflow_compression/python/ops:gen_ops",
33+
"//tensorflow_compression/python/ops:math_ops",
34+
"//tensorflow_compression/python/ops:padding_ops",
35+
"//tensorflow_compression/python/ops:round_ops",
36+
"//tensorflow_compression/python/util:packed_tensors",
2037
],
2138
)
2239

tensorflow_compression/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@
2020
from tensorflow_compression.python import ops
2121

2222
# pylint: disable=wildcard-import
23-
from tensorflow_compression.python.datasets import *
24-
from tensorflow_compression.python.distributions import *
25-
from tensorflow_compression.python.entropy_models import *
26-
from tensorflow_compression.python.layers import *
27-
from tensorflow_compression.python.ops import *
28-
from tensorflow_compression.python.util import *
23+
from tensorflow_compression.python.datasets.y4m_dataset import *
24+
from tensorflow_compression.python.distributions.deep_factorized import *
25+
from tensorflow_compression.python.distributions.helpers import *
26+
from tensorflow_compression.python.distributions.round_adapters import *
27+
from tensorflow_compression.python.distributions.uniform_noise import *
28+
from tensorflow_compression.python.entropy_models.continuous_batched import *
29+
from tensorflow_compression.python.entropy_models.continuous_indexed import *
30+
from tensorflow_compression.python.entropy_models.power_law import *
31+
from tensorflow_compression.python.entropy_models.universal import *
32+
from tensorflow_compression.python.layers.gdn import *
33+
from tensorflow_compression.python.layers.initializers import *
34+
from tensorflow_compression.python.layers.parameters import *
35+
from tensorflow_compression.python.layers.signal_conv import *
36+
from tensorflow_compression.python.layers.soft_round import *
37+
from tensorflow_compression.python.ops.gen_ops import *
38+
from tensorflow_compression.python.ops.math_ops import *
39+
from tensorflow_compression.python.ops.padding_ops import *
40+
from tensorflow_compression.python.ops.round_ops import *
41+
from tensorflow_compression.python.util.packed_tensors import *
2942
# pylint: enable=wildcard-import

tensorflow_compression/python/distributions/uniform_noise.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class NoisyMixtureSameFamily(tfp.distributions.MixtureSameFamily):
200200

201201
def __init__(self, mixture_distribution, components_distribution,
202202
name="NoisyMixtureSameFamily"):
203+
"""Initializer, taking the same arguments as `tfpd.MixtureSameFamily`."""
203204
super().__init__(
204205
mixture_distribution=mixture_distribution,
205206
components_distribution=UniformNoiseAdapter(components_distribution),
@@ -252,20 +253,30 @@ class NoisyNormal(UniformNoiseAdapter):
252253
"""Gaussian distribution with additive i.i.d. uniform noise."""
253254

254255
def __init__(self, name="NoisyNormal", **kwargs):
256+
"""Initializer, taking the same arguments as `tfpd.Normal`."""
255257
super().__init__(tfp.distributions.Normal(**kwargs), name=name)
256258

257259

258260
class NoisyLogistic(UniformNoiseAdapter):
259261
"""Logistic distribution with additive i.i.d. uniform noise."""
260262

261263
def __init__(self, name="NoisyLogistic", **kwargs):
264+
"""Initializer, taking the same arguments as `tfpd.Logistic`."""
262265
super().__init__(tfp.distributions.Logistic(**kwargs), name=name)
263266

264267

265268
class NoisyNormalMixture(NoisyMixtureSameFamily):
266269
"""Mixture of normal distributions with additive i.i.d. uniform noise."""
267270

268271
def __init__(self, loc, scale, weight, name="NoisyNormalMixture"):
272+
"""Initializer.
273+
274+
Args:
275+
loc: Location parameters of `tfpd.Normal` component distributions.
276+
scale: Scale parameters of `tfpd.Normal` component distributions.
277+
weight: `probs` parameter of `tfpd.Categorical` mixture distribution.
278+
name: A name for this distribution.
279+
"""
269280
super().__init__(
270281
mixture_distribution=tfp.distributions.Categorical(probs=weight),
271282
components_distribution=tfp.distributions.Normal(loc=loc, scale=scale),
@@ -277,6 +288,14 @@ class NoisyLogisticMixture(NoisyMixtureSameFamily):
277288
"""Mixture of logistic distributions with additive i.i.d. uniform noise."""
278289

279290
def __init__(self, loc, scale, weight, name="NoisyLogisticMixture"):
291+
"""Initializer.
292+
293+
Args:
294+
loc: Location parameters of `tfpd.Logistic` component distributions.
295+
scale: Scale parameters of `tfpd.Logistic` component distributions.
296+
weight: `probs` parameter of `tfpd.Categorical` mixture distribution.
297+
name: A name for this distribution.
298+
"""
280299
super().__init__(
281300
mixture_distribution=tfp.distributions.Categorical(probs=weight),
282301
components_distribution=tfp.distributions.Logistic(

tensorflow_compression/python/entropy_models/continuous_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ def prior(self):
110110

111111
@prior.deleter
112112
def prior(self):
113+
"""Prior distribution, used for deriving range coding tables."""
113114
self._prior = None
114115

115116
@property
116117
def cdf(self):
118+
"""The CDFs used by range coding."""
117119
self._check_compression()
118120
return tf.convert_to_tensor(self._cdf)
119121

120122
@property
121123
def cdf_offset(self):
124+
"""The CDF offsets used by range coding."""
122125
self._check_compression()
123126
return tf.convert_to_tensor(self._cdf_offset)
124127

tensorflow_compression/python/entropy_models/continuous_batched.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ def prior_shape_tensor(self):
265265

266266
@property
267267
def offset_heuristic(self):
268+
"""Whether to use heuristic to determine quantization offsets."""
268269
return self._offset_heuristic
269270

270271
@property
271272
def quantization_offset(self):
273+
"""The quantization offset used in `quantize` and `compress`."""
272274
if self._quantization_offset is not None:
273275
return tf.convert_to_tensor(self._quantization_offset)
274276
if self.offset_heuristic and not self.compression:

tensorflow_compression/python/entropy_models/continuous_indexed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ContinuousIndexedEntropyModel(continuous_base.ContinuousEntropyModelBase):
3939
A typical workflow looks like this:
4040
4141
- Train a model using an instance of this entropy model as a bottleneck,
42-
passing the bottleneck tensor through it. With training=True, the model
42+
passing the bottleneck tensor through it. With `training=True`, the model
4343
computes a differentiable upper bound on the number of bits needed to
4444
compress the bottleneck tensor.
4545
- For evaluation, get a closer estimate of the number of compressed bits

tensorflow_compression/python/entropy_models/power_law.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,15 @@ def __call__(self, bottleneck):
115115

116116
@tf.Module.with_name_scope
117117
def penalty(self, bottleneck):
118-
"""Computes cross-entropy penalty.
118+
"""Computes penalty encouraging compressibility.
119119
120120
Args:
121121
bottleneck: `tf.Tensor` containing the data to be compressed. Must have at
122122
least `self.coding_rank` dimensions.
123123
124124
Returns:
125-
Penalty, which has the same shape as `bottleneck` without the
126-
`self.coding_rank` innermost dimensions, and corresponds to a cross
127-
entropy.
125+
Penalty value, which has the same shape as `bottleneck` without the
126+
`self.coding_rank` innermost dimensions.
128127
"""
129128
bottleneck = tf.convert_to_tensor(bottleneck, dtype=self.bottleneck_dtype)
130129
penalty = tf.math.log((abs(bottleneck) + self.alpha) / self.alpha)

tensorflow_compression/python/layers/signal_conv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class _SignalConv(tf.keras.layers.Layer):
120120
inputs: |0 1 2 3 4 5 6 7 8|
121121
outputs: | 0 . 1 . 2 |
122122
```
123+
123124
```
124125
inputs: |0 1 2 3 4 5 6 7|
125126
outputs: | 0 . 1 . |
@@ -152,6 +153,7 @@ class _SignalConv(tf.keras.layers.Layer):
152153
inputs: |0 1 2 3 4 5 6 7 8|
153154
outputs: |0 . 1 . 2 . 3 . 4|
154155
```
156+
155157
```
156158
inputs: |0 1 2 3 4 5 6 7|
157159
outputs: |0 . 1 . 2 . 3 .|

0 commit comments

Comments
 (0)