Skip to content

Commit e5c0dcf

Browse files
Johannes Ballécopybara-github
authored andcommitted
Updates to TFC build system for TF2 release.
PiperOrigin-RevId: 345710289 Change-Id: I255dd43895c20a7792fa4eb6ae1e3a6eb8fc015a
1 parent cf96d1b commit e5c0dcf

File tree

10 files changed

+74
-63
lines changed

10 files changed

+74
-63
lines changed

README.md

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,60 @@
11
# Introduction
22

3-
This project contains data compression ops and layers for TensorFlow. The
4-
project website is at
5-
[tensorflow.github.io/compression](https://tensorflow.github.io/compression).
3+
This project contains data compression ops and layers for TensorFlow.
64

75
You can use this library to build your own ML models with end-to-end optimized
86
data compression built in. It's useful to find storage-efficient representations
9-
of your data (features, examples, images, etc.) while only sacrificing a tiny
7+
of your data (images, features, examples, etc.) while only sacrificing a tiny
108
fraction of model performance. It can compress any floating point tensor to a
119
much smaller sequence of bits.
1210

13-
Specifically, the
14-
[EntropyBottleneck class](https://tensorflow.github.io/compression/docs/entropy_bottleneck.html)
15-
in this library simplifies the process of designing rate–distortion optimized
16-
codes. During training, it acts like a likelihood model. Once training is
17-
completed, it encodes floating point tensors into optimal bit sequences by
18-
automating the design of probability tables and calling a range coder
19-
implementation behind the scenes.
11+
Specifically, the entropy model classes in this library simplify the process of
12+
designing rate–distortion optimized codes. During training, they act like
13+
likelihood models. Once training is completed, they encode floating point
14+
tensors into optimal bit sequences by automating the design of probability
15+
tables and calling a range coder implementation behind the scenes.
2016

21-
For an introduction to lossy image compression with machine learning, take a
22-
look at @jonycgn's
23-
[talk on Learned Image Compression](https://www.youtube.com/watch?v=x_q7cZviXkY).
17+
The main novelty of this method over traditional transform coding is the
18+
stochastic minimization of the rate-distortion Lagrangian, and using nonlinear
19+
transforms implemented by neural networks. For an introduction to this, consider
20+
our [paper on nonlinear transform coding](https://arxiv.org/abs/2007.03034), or
21+
watch @jonycgn's [talk on learned image
22+
compression](https://www.youtube.com/watch?v=x_q7cZviXkY).
2423

2524
## Documentation & getting help
2625

27-
For usage questions and discussions, please head over to our
28-
[Google group](https://groups.google.com/forum/#!forum/tensorflow-compression).
26+
Please post all questions or comments in our [Google
27+
group](https://groups.google.com/forum/#!forum/tensorflow-compression). Only
28+
file Github issues for actual bugs or feature requests. If you post to the group
29+
instead, you may get a faster answer, and you help other people find the
30+
question or answer more easily later.
2931

30-
Refer to
31-
[the API documentation](https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html)
32+
Refer to [the API
33+
documentation](https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html)
3234
for a complete description of the Keras layers and TensorFlow ops this package
3335
implements.
34-
35-
There's also an introduction to our `EntropyBottleneck` class
36-
[here](https://tensorflow.github.io/compression/docs/entropy_bottleneck.html),
37-
and a description of the range coding operators
38-
[here](https://tensorflow.github.io/compression/docs/range_coding.html).
36+
***Note: the API docs have not been updated for the current beta release yet.***
3937

4038
## Installation
4139

42-
***Note: Precompiled packages are currently only provided for Linux (Python 2.7,
43-
3.3-3.6) and Darwin/Mac OS (Python 2.7, 3.7). 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.***
40+
***Note: Precompiled packages are currently only provided for Linux and
41+
Darwin/Mac OS. To use these packages on Windows, consider using a [TensorFlow
42+
Docker image](https://www.tensorflow.org/install/docker) and installing
43+
tensorflow-compression using pip inside the Docker container.***
4744

4845
Set up an environment in which you can install precompiled binary Python
4946
packages using the `pip` command. Refer to the
5047
[TensorFlow installation instructions](https://www.tensorflow.org/install/pip)
5148
for more information on how to set up such a Python environment.
5249

53-
The current version of tensorflow-compression requires TensorFlow 1.15. For
54-
TensorFlow 1.14 or earlier, see our
55-
[previous releases](https://github.com/tensorflow/compression/releases). You can
50+
The current stable version of TFC (1.3) requires TensorFlow 1.15. The current
51+
beta release of TFC (2.0b1) is built for TensorFlow 2.3. For versions compatible
52+
with TensorFlow 1.14 or earlier, see our [previous
53+
releases](https://github.com/tensorflow/compression/releases). The following
54+
instructions are for the stable release. To install the beta, replace the
55+
version numbers with 2.0b1 and 2.3, respectively.
56+
57+
You can
5658
install TensorFlow from any source. To install it via `pip`, run the following
5759
command:
5860
```bash
@@ -67,7 +69,7 @@ for CPU-only.
6769
Then, run the following command to install the tensorflow-compression pip
6870
package:
6971
```bash
70-
pip install tensorflow-compression
72+
pip install tensorflow-compression==1.3
7173
```
7274

7375
To test that the installation works correctly, you can run the unit tests with
@@ -86,7 +88,7 @@ and then run the `pip install` command inside the Docker container, not on the
8688
host. For instance, you can use a command line like this:
8789
```bash
8890
docker run tensorflow/tensorflow:1.15.0-py3 bash -c \
89-
"pip install tensorflow-compression &&
91+
"pip install tensorflow-compression==1.3 &&
9092
python -m tensorflow_compression.python.all_test"
9193
```
9294
This will fetch the TensorFlow Docker image if it's not already cached, install
@@ -95,16 +97,15 @@ the pip package and then run the unit tests to confirm that it works.
9597
### Anaconda
9698

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

110111
## Usage
@@ -194,24 +195,24 @@ This section describes the necessary steps to build your own pip packages of
194195
tensorflow-compression. This may be necessary to install it on platforms for
195196
which we don't provide precompiled binaries (currently only Linux and Darwin).
196197

197-
We use the Docker image `tensorflow/tensorflow:custom-op-ubuntu16` for building
198-
pip packages for Linux. Note that this is different from
199-
`tensorflow/tensorflow:devel`. To be compatible with the TensorFlow pip package,
200-
the GCC version must match, but `tensorflow/tensorflow:devel` has a different
201-
GCC version installed.
198+
We use the custom-op Docker images (e.g.
199+
`tensorflow/tensorflow:nightly-custom-op-ubuntu16`) for building pip packages
200+
for Linux. Note that this is different from `tensorflow/tensorflow:devel`. To be
201+
compatible with the TensorFlow pip package, the GCC version must match, but
202+
`tensorflow/tensorflow:devel` has a different GCC version installed. For more
203+
information, refer to the [custom-op
204+
instructions](https://github.com/tensorflow/custom-op).
202205

203206
Inside a Docker container from the image, the following steps need to be taken.
204207

205-
1. Install the TensorFlow pip package.
206-
2. Clone the `tensorflow/compression` repo from GitHub.
207-
3. Run `:build_pip_pkg` inside the cloned repo.
208+
1. Clone the `tensorflow-compression` repo from GitHub.
209+
2. Run `:build_pip_pkg` inside the cloned repo.
208210

209211
For example:
210212
```bash
211213
sudo docker run -v /tmp/tensorflow_compression:/tmp/tensorflow_compression \
212-
tensorflow/tensorflow:custom-op-ubuntu16 bash -c \
213-
"pip install tensorflow==1.15 &&
214-
git clone https://github.com/tensorflow/compression.git
214+
tensorflow/tensorflow:nightly-custom-op-ubuntu16 bash -c \
215+
"git clone https://github.com/tensorflow/compression.git
215216
/tensorflow_compression &&
216217
cd /tensorflow_compression &&
217218
bazel run -c opt --copt=-mavx :build_pip_pkg"
@@ -228,7 +229,7 @@ pip install /tmp/tensorflow_compression/tensorflow_compression-*.whl
228229
Then run the unit tests (Do not run the tests in the workspace directory where
229230
`WORKSPACE` of `tensorflow_compression` repo lives. In that case, the Python
230231
interpreter would attempt to import `tensorflow_compression` packages from the
231-
source tree rather than from the installed package system directory):
232+
source tree, rather than from the installed package system directory):
232233
```bash
233234
pushd /tmp
234235
python -m tensorflow_compression.python.all_test
@@ -256,5 +257,6 @@ for more information.
256257
* Sung Jin Hwang (github: [ssjhv](https://github.com/ssjhv))
257258
* Nick Johnston (github: [nmjohn](https://github.com/nmjohn))
258259
* David Minnen (github: [minnend](https://github.com/minnend))
260+
* Eirikur Agustsson (github: [relational](https://github.com/relational))
259261

260262
Note that this is not an officially supported Google product.

build_pip_pkg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def main(srcdir):
6464
packages=setuptools.find_packages(),
6565
install_requires=[
6666
'scipy >= 1',
67+
'tensorflow_probability >= 0.9',
6768
],
6869
script_args=['sdist', 'bdist_wheel'],
6970
# Add in any packaged data.
@@ -77,11 +78,10 @@ def main(srcdir):
7778
'Intended Audience :: Education',
7879
'Intended Audience :: Science/Research',
7980
'License :: OSI Approved :: Apache Software License',
80-
'Programming Language :: Python :: 3.3',
81-
'Programming Language :: Python :: 3.4',
8281
'Programming Language :: Python :: 3.5',
8382
'Programming Language :: Python :: 3.6',
8483
'Programming Language :: Python :: 3.7',
84+
'Programming Language :: Python :: 3.8',
8585
'Topic :: Scientific/Engineering :: Mathematics',
8686
'Topic :: Software Development :: Libraries :: Python Modules',
8787
'Topic :: Software Development :: Libraries',

tensorflow_compression/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
try:
1818
import tensorflow as _tensorflow
1919
_tf_version = [int(v) for v in _tensorflow.version.VERSION.split(".")]
20-
assert _tf_version[0] == 2 and _tf_version[1] == 1
20+
assert _tf_version[0] == 2 and _tf_version[1] == 3
2121
except (ImportError, AssertionError):
2222
raise RuntimeError(
23-
"For tensorflow_compression, please install TensorFlow 2.1.")
23+
"For tensorflow_compression, please install TensorFlow 2.3.")
2424

2525
# pylint: disable=wildcard-import
2626
from tensorflow_compression.python.distributions.deep_factorized import *

tensorflow_compression/python/all_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
import tensorflow.compat.v1 as tf
2222

2323
# pylint: disable=wildcard-import
24+
from tensorflow_compression.python.distributions.deep_factorized_test import *
25+
from tensorflow_compression.python.distributions.helpers_test import *
26+
from tensorflow_compression.python.distributions.round_adapters_test import *
27+
from tensorflow_compression.python.distributions.uniform_noise_test import *
28+
29+
from tensorflow_compression.python.entropy_models.continuous_batched_test import *
30+
from tensorflow_compression.python.entropy_models.continuous_indexed_test import *
31+
from tensorflow_compression.python.entropy_models.universal_test import *
32+
2433
from tensorflow_compression.python.layers.entropy_models_test import *
2534
from tensorflow_compression.python.layers.gdn_test import *
2635
from tensorflow_compression.python.layers.parameterizers_test import *
@@ -30,7 +39,7 @@
3039
from tensorflow_compression.python.ops.math_ops_test import *
3140
from tensorflow_compression.python.ops.padding_ops_test import *
3241
from tensorflow_compression.python.ops.range_coding_ops_test import *
33-
from tensorflow_compression.python.ops.round_ops_test import *
42+
from tensorflow_compression.python.ops.soft_round_ops_test import *
3443
from tensorflow_compression.python.ops.spectral_ops_test import *
3544

3645
from tensorflow_compression.python.util.packed_tensors_test import *

tensorflow_compression/python/distributions/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = ["//:__subpackages__"],
2+
default_visibility = ["//visibility:public"],
33
)
44

55
licenses(["notice"]) # Apache 2.0

tensorflow_compression/python/entropy_models/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = ["//:__subpackages__"],
2+
default_visibility = ["//visibility:public"],
33
)
44

55
licenses(["notice"]) # Apache 2.0

tensorflow_compression/python/layers/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = ["//:__subpackages__"],
2+
default_visibility = ["//visibility:public"],
33
)
44

55
licenses(["notice"]) # Apache 2.0

tensorflow_compression/python/ops/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = [":__subpackages__"],
2+
default_visibility = ["//visibility:public"],
33
)
44

55
licenses(["notice"]) # Apache 2.0

tensorflow_compression/python/util/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package(
2-
default_visibility = ["//:__subpackages__"],
2+
default_visibility = ["//visibility:public"],
33
)
44

55
licenses(["notice"]) # Apache 2.0

workspace.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _tensorflow_pip_impl(ctx):
2222
"tensorflow?: %s" % include_path.stderr)
2323

2424
if "linux" in ctx.os.name:
25-
library_filename = "libtensorflow_framework.so.1"
25+
library_filename = "libtensorflow_framework.so.2"
2626
elif "mac" in ctx.os.name:
2727
library_filename = "libtensorflow_framework.dylib"
2828

0 commit comments

Comments
 (0)