Skip to content

Commit a543a0a

Browse files
Johannes Ball?copybara-github
authored andcommitted
Final adjustments for 1.2.
This contains the following changes: - Improved installation instructions. - Moved documentation from class attributes to initializer arguments. - Imports TensorFlow from `tensorflow.compat.v1` to suppress warnings. - Examples now use PackedTensors class shipped with library. - Updated API docs. PiperOrigin-RevId: 263625422 Change-Id: I06f699b50f44c70a028d335d09e1b68842ebdb7f
1 parent 9061520 commit a543a0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1134
-1368
lines changed

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ and a description of the range coding operators
3939

4040
## Installation
4141

42-
***Note: Precompiled packages are currently only provided for Linux and Darwin
43-
(Mac OS). To use these packages on Windows, consider using a [TensorFlow
44-
Docker image](https://www.tensorflow.org/install/docker) and installing
45-
tensorflow-compression using pip inside the Docker container.***
42+
***Note: Precompiled packages are currently only provided for Linux (Python 2.7,
43+
3.7) and Darwin/Mac OS (Python 2.7, 3.3-3.6). To use these packages on Windows,
44+
consider using a
45+
[TensorFlow Docker image](https://www.tensorflow.org/install/docker) and
46+
installing tensorflow-compression using pip inside the Docker container.***
4647

4748
Set up an environment in which you can install precompiled binary Python
4849
packages using the `pip` command. Refer to the
@@ -61,7 +62,7 @@ pip install tensorflow
6162
```
6263
for CPU-only.
6364

64-
Then, run the following command to install the tensorflow-compression `pip`
65+
Then, run the following command to install the tensorflow-compression pip
6566
package:
6667
```bash
6768
pip install tensorflow-compression
@@ -74,8 +75,10 @@ python -m tensorflow_compression.python.all_test
7475
Once the command finishes, you should see a message ```OK (skipped=11)``` or
7576
similar in the last line.
7677

78+
### Docker
79+
7780
To use a Docker container (e.g. on Windows), be sure to install Docker
78-
(e.g., [Docker Desktop](https://www.docker.com/products/docker-desktop),
81+
(e.g., [Docker Desktop](https://www.docker.com/products/docker-desktop)),
7982
use a [TensorFlow Docker image](https://www.tensorflow.org/install/docker),
8083
and then run the `pip install` command inside the Docker container, not on the
8184
host. For instance, you can use a command line like this:
@@ -84,9 +87,24 @@ docker run tensorflow/tensorflow:latest-py3 bash -c \
8487
"pip install tensorflow-compression &&
8588
python -m tensorflow_compression.python.all_test"
8689
```
87-
This will fetch the latest TensorFlow Docker image, install the `pip` package
90+
This will fetch the latest TensorFlow Docker image, install the pip package
8891
and then run the unit tests to confirm that it works.
8992

93+
### Anaconda
94+
95+
It seems that [Anaconda](https://www.anaconda.com/distribution/) ships its own
96+
binary version of TensorFlow which is incompatible with our pip package. It
97+
also installs Python 3.7 by default, which we currently don't support on Linux.
98+
To solve this, make sure to use Python 3.6 on Linux, and always install
99+
TensorFlow via `pip` rather than `conda`. For example, this creates an Anaconda
100+
environment with Python 3.6 and CUDA libraries, and then installs TensorFlow
101+
and tensorflow-compression with GPU support:
102+
```bash
103+
conda create --name ENV_NAME python=3.6 cudatoolkit=10.0 cudnn
104+
conda activate ENV_NAME
105+
pip install tensorflow-gpu tensorflow-compression
106+
```
107+
90108
## Usage
91109

92110
We recommend importing the library from your Python code as follows:
@@ -168,20 +186,20 @@ python bls2017.py [options] compress original.png compressed.tfci
168186
python bls2017.py [options] decompress compressed.tfci reconstruction.png
169187
```
170188

171-
## Building `pip` packages
189+
## Building pip packages
172190

173-
This section describes the necessary steps to build your own `pip` packages of
191+
This section describes the necessary steps to build your own pip packages of
174192
tensorflow-compression. This may be necessary to install it on platforms for
175193
which we don't provide precompiled binaries (currently only Linux and Darwin).
176194

177195
We use the Docker image `tensorflow/tensorflow:nightly-custom-op` for building
178-
`pip` packages. Note that this is different from `tensorflow/tensorflow:devel`.
179-
To be compatible with the TensorFlow `pip` package, the GCC version must match,
196+
pip packages. Note that this is different from `tensorflow/tensorflow:devel`.
197+
To be compatible with the TensorFlow pip package, the GCC version must match,
180198
but `tensorflow/tensorflow:devel` has a different GCC version installed.
181199

182200
Inside a Docker container from the image, the following steps need to be taken.
183201

184-
1. Install TensorFlow `pip` package.
202+
1. Install TensorFlow pip package.
185203
2. Clone the `tensorflow/compression` repo from GitHub.
186204
3. Run `:build_pip_pkg` inside the cloned repo:
187205

@@ -190,7 +208,7 @@ sudo docker run -v /tmp/tensorflow_compression:/tmp/tensorflow_compression \
190208
tensorflow/tensorflow:nightly-custom-op bash -c \
191209
"pip install tensorflow &&
192210
git clone https://github.com/tensorflow/compression.git
193-
/tensorflow_compression &&
211+
/tensorflow_compression &&
194212
cd /tensorflow_compression &&
195213
bazel run -c opt --copt=-mavx :build_pip_pkg"
196214
```
@@ -213,7 +231,7 @@ python -m tensorflow_compression.python.all_test
213231
popd
214232
```
215233

216-
When done, you can uninstall the `pip` package again:
234+
When done, you can uninstall the pip package again:
217235
```bash
218236
pip uninstall tensorflow-compression
219237
```

build_pip_pkg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main(srcdir):
7676
distclass=BinaryDistribution,
7777
# PyPI package information.
7878
classifiers=[
79-
'Development Status :: 4 - Beta',
79+
'Development Status :: 5 - Production/Stable',
8080
'Intended Audience :: Developers',
8181
'Intended Audience :: Education',
8282
'Intended Audience :: Science/Research',

docs/api_docs/python/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# All symbols in TensorFlow/compression
22

3+
## Primary symbols
34
* <a href="./tfc.md"><code>tfc</code></a>
45
* <a href="./tfc/EntropyBottleneck.md"><code>tfc.EntropyBottleneck</code></a>
56
* <a href="./tfc/EntropyModel.md"><code>tfc.EntropyModel</code></a>
@@ -9,6 +10,7 @@
910
* <a href="./tfc/LaplacianConditional.md"><code>tfc.LaplacianConditional</code></a>
1011
* <a href="./tfc/LogisticConditional.md"><code>tfc.LogisticConditional</code></a>
1112
* <a href="./tfc/NonnegativeParameterizer.md"><code>tfc.NonnegativeParameterizer</code></a>
13+
* <a href="./tfc/PackedTensors.md"><code>tfc.PackedTensors</code></a>
1214
* <a href="./tfc/Parameterizer.md"><code>tfc.Parameterizer</code></a>
1315
* <a href="./tfc/RDFTParameterizer.md"><code>tfc.RDFTParameterizer</code></a>
1416
* <a href="./tfc/SignalConv1D.md"><code>tfc.SignalConv1D</code></a>
@@ -55,6 +57,9 @@
5557
* <a href="./tfc/unbounded_index_range_encode.md"><code>tfc.python.ops.range_coding_ops.unbounded_index_range_encode</code></a>
5658
* <a href="./tfc/python/ops/spectral_ops.md"><code>tfc.python.ops.spectral_ops</code></a>
5759
* <a href="./tfc/irdft_matrix.md"><code>tfc.python.ops.spectral_ops.irdft_matrix</code></a>
60+
* <a href="./tfc/python/util.md"><code>tfc.python.util</code></a>
61+
* <a href="./tfc/python/util/packed_tensors.md"><code>tfc.python.util.packed_tensors</code></a>
62+
* <a href="./tfc/PackedTensors.md"><code>tfc.python.util.packed_tensors.PackedTensors</code></a>
5863
* <a href="./tfc/range_decode.md"><code>tfc.range_decode</code></a>
5964
* <a href="./tfc/range_encode.md"><code>tfc.range_encode</code></a>
6065
* <a href="./tfc/same_padding_for_kernel.md"><code>tfc.same_padding_for_kernel</code></a>

docs/api_docs/python/tfc.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55

66
# Module: tfc
77

8-
Data compression tools.
98

9+
<table class="tfo-notebook-buttons tfo-api" align="left">
10+
11+
<td>
12+
<a target="_blank" href="https://github.com/tensorflow/compression/tree/master/tensorflow_compression/__init__.py">
13+
<img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" />
14+
View source on GitHub
15+
</a>
16+
</td></table>
1017

1118

1219

13-
<table class="tfo-github-link" align="left">
14-
<a target="_blank" href="https://github.com/tensorflow/compression/tree/master/tensorflow_compression/__init__.py">
15-
<img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" />
16-
View source on GitHub
17-
</a>
18-
</table>
20+
Data compression tools.
1921

2022
<!-- Placeholder for "Used in" -->
2123

@@ -42,6 +44,8 @@ Data compression tools.
4244

4345
[`class NonnegativeParameterizer`](./tfc/NonnegativeParameterizer.md): Object encapsulating nonnegative parameterization as needed for GDN.
4446

47+
[`class PackedTensors`](./tfc/PackedTensors.md): Packed representation of compressed tensors.
48+
4549
[`class Parameterizer`](./tfc/Parameterizer.md): Parameterization object (abstract base class).
4650

4751
[`class RDFTParameterizer`](./tfc/RDFTParameterizer.md): Object encapsulating RDFT reparameterization.
@@ -54,7 +58,7 @@ Data compression tools.
5458

5559
[`class StaticParameterizer`](./tfc/StaticParameterizer.md): A parameterizer that returns a non-variable.
5660

57-
[`class SymmetricConditional`](./tfc/SymmetricConditional.md): Symmetric conditional entropy model.
61+
[`class SymmetricConditional`](./tfc/SymmetricConditional.md): Symmetric conditional entropy model (base class).
5862

5963
## Functions
6064

docs/api_docs/python/tfc/EntropyBottleneck.md

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@
5555

5656
# tfc.EntropyBottleneck
5757

58+
59+
<table class="tfo-notebook-buttons tfo-api" align="left">
60+
61+
<td>
62+
<a target="_blank" href="https://github.com/tensorflow/compression/tree/master/tensorflow_compression/python/layers/entropy_models.py">
63+
<img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" />
64+
View source on GitHub
65+
</a>
66+
</td></table>
67+
68+
69+
5870
## Class `EntropyBottleneck`
5971

6072
Entropy bottleneck layer.
@@ -63,19 +75,9 @@ Inherits From: [`EntropyModel`](../tfc/EntropyModel.md)
6375

6476
### Aliases:
6577

66-
* Class `tfc.EntropyBottleneck`
6778
* Class `tfc.python.layers.entropy_models.EntropyBottleneck`
6879

6980

70-
71-
72-
<table class="tfo-github-link" align="left">
73-
<a target="_blank" href="https://github.com/tensorflow/compression/tree/master/tensorflow_compression/python/layers/entropy_models.py">
74-
<img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" />
75-
View source on GitHub
76-
</a>
77-
</table>
78-
7981
<!-- Placeholder for "Used in" -->
8082

8183
This layer models the entropy of the tensor passing through it. During
@@ -117,64 +119,6 @@ which are only significant for compression and decompression. To use the
117119
compression feature, the auxiliary loss must be minimized during or after
118120
training. After that, the update op must be executed at least once.
119121

120-
#### Arguments:
121-
122-
123-
* <b>`init_scale`</b>: Float. A scaling factor determining the initial width of the
124-
probability densities. This should be chosen big enough so that the
125-
range of values of the layer inputs roughly falls within the interval
126-
[`-init_scale`, `init_scale`] at the beginning of training.
127-
* <b>`filters`</b>: An iterable of ints, giving the number of filters at each layer of
128-
the density model. Generally, the more filters and layers, the more
129-
expressive is the density model in terms of modeling more complicated
130-
distributions of the layer inputs. For details, refer to the paper
131-
referenced above. The default is `[3, 3, 3]`, which should be sufficient
132-
for most practical purposes.
133-
* <b>`tail_mass`</b>: Float, between 0 and 1. The bottleneck layer automatically
134-
determines the range of input values based on their frequency of
135-
occurrence. Values occurring in the tails of the distributions will not be
136-
encoded with range coding, but using a Golomb-like code. `tail_mass`
137-
determines the amount of probability mass in the tails which will be
138-
Golomb-coded. For example, the default value of `2 ** -8` means that on
139-
average, one 256th of all values will use the Golomb code.
140-
* <b>`likelihood_bound`</b>: Float. If positive, the returned likelihood values are
141-
ensured to be greater than or equal to this value. This prevents very
142-
large gradients with a typical entropy loss (defaults to 1e-9).
143-
* <b>`range_coder_precision`</b>: Integer, between 1 and 16. The precision of the range
144-
coder used for compression and decompression. This trades off computation
145-
speed with compression efficiency, where 16 is the slowest but most
146-
efficient setting. Choosing lower values may increase the average
147-
codelength slightly compared to the estimated entropies.
148-
* <b>`data_format`</b>: Either `'channels_first'` or `'channels_last'` (default).
149-
* <b>`trainable`</b>: Boolean. Whether the layer should be trained.
150-
* <b>`name`</b>: String. The name of the layer.
151-
* <b>`dtype`</b>: `DType` of the layer's inputs, parameters, returned likelihoods, and
152-
outputs during training. Default of `None` means to use the type of the
153-
first input.
154-
155-
Read-only properties:
156-
init_scale: See above.
157-
filters: See above.
158-
tail_mass: See above.
159-
likelihood_bound: See above.
160-
range_coder_precision: See above.
161-
data_format: See above.
162-
name: String. See above.
163-
dtype: See above.
164-
trainable_variables: List of trainable variables.
165-
non_trainable_variables: List of non-trainable variables.
166-
variables: List of all variables of this layer, trainable and non-trainable.
167-
updates: List of update ops of this layer.
168-
losses: List of losses added by this layer. Always contains exactly one
169-
auxiliary loss, which must be added to the training loss.
170-
171-
#### Mutable properties:
172-
173-
174-
* <b>`trainable`</b>: Boolean. Whether the layer should be trained.
175-
* <b>`input_spec`</b>: Optional `InputSpec` object specifying the constraints on inputs
176-
that can be accepted by the layer.
177-
178122
<h2 id="__init__"><code>__init__</code></h2>
179123

180124
<a target="_blank" href="https://github.com/tensorflow/compression/tree/master/tensorflow_compression/python/layers/entropy_models.py">View source</a>
@@ -188,8 +132,24 @@ __init__(
188132
)
189133
```
190134

135+
Initializer.
191136

192137

138+
#### Arguments:
139+
140+
141+
* <b>`init_scale`</b>: Float. A scaling factor determining the initial width of the
142+
probability densities. This should be chosen big enough so that the
143+
range of values of the layer inputs roughly falls within the interval
144+
[`-init_scale`, `init_scale`] at the beginning of training.
145+
* <b>`filters`</b>: An iterable of ints, giving the number of filters at each layer
146+
of the density model. Generally, the more filters and layers, the more
147+
expressive is the density model in terms of modeling more complicated
148+
distributions of the layer inputs. For details, refer to the paper
149+
referenced above. The default is `[3, 3, 3]`, which should be sufficient
150+
for most practical purposes.
151+
* <b>`data_format`</b>: Either `'channels_first'` or `'channels_last'` (default).
152+
* <b>`**kwargs`</b>: Other keyword arguments passed to superclass (`EntropyModel`).
193153

194154

195155

0 commit comments

Comments
 (0)