Skip to content

Commit bbe51f0

Browse files
Johannes Ballécopybara-github
authored andcommitted
Prepares for 2.0 release.
- Updates README. - Updates API documentation. - Updates Github pages theme. - Updates build script. - Temporarily inherits Parameter class from Layer rather than Module to work around Keras bug that fails to track variables from Modules nested in Layers. This should be fixed in the next TF release. PiperOrigin-RevId: 361276847 Change-Id: I0b83509083f08da414fe7e6cfc370ad94f72db70
1 parent 783eab8 commit bbe51f0

File tree

95 files changed

+41520
-10143
lines changed

Some content is hidden

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

95 files changed

+41520
-10143
lines changed

BUILD

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,17 @@ py_library(
2929
],
3030
)
3131

32-
filegroup(
33-
name = "pip_src",
34-
srcs = [
35-
"MANIFEST.in",
36-
"tensorflow_compression/all_tests.py",
37-
],
38-
)
39-
4032
py_binary(
4133
name = "build_pip_pkg",
4234
srcs = ["build_pip_pkg.py"],
4335
data = [
4436
"LICENSE",
4537
"README.md",
46-
":pip_src",
38+
"MANIFEST.in",
39+
"requirements.txt",
40+
"tensorflow_compression/all_tests.py",
4741
":tensorflow_compression",
48-
# The following targets are for Python test files.
42+
# The following targets are for Python unit tests.
4943
"//tensorflow_compression/python/distributions:py_src",
5044
"//tensorflow_compression/python/entropy_models:py_src",
5145
"//tensorflow_compression/python/layers:py_src",

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
global-include LICENSE
2-
global-include NOTICE
32
global-include *.md
43
recursive-include tensorflow_compression/cc/ *.so

README.md

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Introduction
1+
# TensorFlow Compression
22

3-
This project contains data compression ops and layers for TensorFlow.
3+
TensorFlow Compression (TFC) contains data compression tools for TensorFlow.
44

55
You can use this library to build your own ML models with end-to-end optimized
66
data compression built in. It's useful to find storage-efficient representations
@@ -31,58 +31,41 @@ question or answer more easily later.
3131

3232
Refer to [the API
3333
documentation](https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html)
34-
for a complete description of the Keras layers and TensorFlow ops this package
35-
implements.
36-
***Note: the API docs have not been updated for the current beta release yet.***
34+
for a complete description of the classes and functions this package implements.
3735

3836
## Installation
3937

4038
***Note: Precompiled packages are currently only provided for Linux and
4139
Darwin/Mac OS. To use these packages on Windows, consider using a [TensorFlow
4240
Docker image](https://www.tensorflow.org/install/docker) and installing
43-
tensorflow-compression using pip inside the Docker container.***
41+
TensorFlow Compression using pip inside the Docker container.***
4442

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

50-
The current stable version of TFC (1.3) requires TensorFlow 1.15. The current
51-
beta release of TFC (2.0b2) is built for TensorFlow 2.4. For versions compatible
52-
with TensorFlow 1.14 or earlier, see our [previous
48+
The current version of TFC (v2.0) requires TensorFlow v2.4. For versions
49+
compatible with TensorFlow v1, see our [previous
5350
releases](https://github.com/tensorflow/compression/releases).
5451

5552
### pip
5653

5754
To install TF and TFC via `pip`, run the following command:
5855

5956
```bash
60-
pip install tensorflow-gpu==1.15 tensorflow-compression==1.3
57+
pip install tensorflow-gpu==2.4.* tensorflow-compression==2.0
6158
```
6259

63-
for the stable release, or
60+
If you don't need GPU support, you can drop the `-gpu` part.
6461

65-
```bash
66-
pip install tensorflow-gpu==2.4 tensorflow-probability==0.12.1 tensorflow-compression==2.0b2
67-
```
68-
69-
for the beta release. If you don't need GPU support, you can drop the `-gpu`
70-
part.
71-
72-
To test that the installation works correctly, you can run the unit tests with
73-
(respectively):
74-
75-
```bash
76-
python -m tensorflow_compression.python.all_test
77-
```
78-
79-
or
62+
To test that the installation works correctly, you can run the unit tests with:
8063

8164
```bash
8265
python -m tensorflow_compression.all_tests
8366
```
8467

85-
Once the command finishes, you should see a message ```OK (skipped=12)``` or
68+
Once the command finishes, you should see a message ```OK (skipped=29)``` or
8669
similar in the last line.
8770

8871
### Docker
@@ -94,16 +77,8 @@ and then run the `pip install` command inside the Docker container, not on the
9477
host. For instance, you can use a command line like this:
9578

9679
```bash
97-
docker run tensorflow/tensorflow:1.15.0-py3 bash -c \
98-
"pip install tensorflow-compression==1.3 &&
99-
python -m tensorflow_compression.python.all_test"
100-
```
101-
102-
or (for the beta version):
103-
104-
```bash
105-
docker run tensorflow/tensorflow:2.4.0 bash -c \
106-
"pip install tensorflow-probability==0.12.1 tensorflow-compression==2.0b2 &&
80+
docker run tensorflow/tensorflow:2.4.1 bash -c \
81+
"pip install tensorflow-compression==2.0 &&
10782
python -m tensorflow_compression.all_tests"
10883
```
10984

@@ -116,13 +91,13 @@ It seems that [Anaconda](https://www.anaconda.com/distribution/) ships its own
11691
binary version of TensorFlow which is incompatible with our pip package. To
11792
solve this, always install TensorFlow via `pip` rather than `conda`. For
11893
example, this creates an Anaconda environment with Python 3.6 and CUDA
119-
libraries, and then installs TensorFlow and tensorflow-compression with GPU
94+
libraries, and then installs TensorFlow and TensorFlow Compression with GPU
12095
support:
12196

12297
```bash
12398
conda create --name ENV_NAME python=3.6 cudatoolkit=10.0 cudnn
12499
conda activate ENV_NAME
125-
pip install tensorflow-gpu==1.15 tensorflow-compression==1.3
100+
pip install tensorflow-gpu==2.4.* tensorflow-compression==2.0
126101
```
127102

128103
## Usage
@@ -166,33 +141,40 @@ appended (any existing extensions will not be removed).
166141

167142
The
168143
[models directory](https://github.com/tensorflow/compression/tree/master/models)
169-
contains an implementation of the image compression model described in:
144+
contains several implementations of published image compression models to enable
145+
easy experimentation. The instructions below talk about a re-implementation of
146+
the model published in:
170147

171148
> "End-to-end optimized image compression"<br />
172149
> J. Ballé, V. Laparra, E. P. Simoncelli<br />
173150
> https://arxiv.org/abs/1611.01704
174151
175-
To see a list of options, download the file `bls2017.py` and run:
152+
Note that the models directory is not contained in the pip package. The models
153+
are meant to be downloaded individually. Download the file `bls2017.py` and run:
176154

177155
```bash
178156
python bls2017.py -h
179157
```
180158

181-
To train the model, you need to supply it with a dataset of RGB training images.
182-
They should be provided in PNG format. Training can be as simple as the
183-
following command:
159+
This will list the available command line options for the implementation.
160+
Training can be as simple as the following command:
184161

185162
```bash
186-
python bls2017.py --verbose train --train_glob="images/*.png"
163+
python bls2017.py -V train
187164
```
188165

189-
This will use the default settings. The most important parameter is `--lambda`,
190-
which controls the trade-off between bitrate and distortion that the model will
191-
be optimized for. The number of channels per layer is important, too: models
192-
tuned for higher bitrates (or, equivalently, lower distortion) tend to require
193-
transforms with a greater approximation capacity (i.e. more channels), so to
194-
optimize performance, you want to make sure that the number of channels is large
195-
enough (or larger). This is described in more detail in:
166+
This will use the default settings. Note that unless a custom training dataset
167+
is provided via `--train_glob`, the
168+
[CLIC dataset](https://www.tensorflow.org/datasets/catalog/clic) will be
169+
downloaded using TensorFlow Datasets.
170+
171+
The most important training parameter is `--lambda`, which controls the
172+
trade-off between bitrate and distortion that the model will be optimized for.
173+
The number of channels per layer is important, too: models tuned for higher
174+
bitrates (or, equivalently, lower distortion) tend to require transforms with a
175+
greater approximation capacity (i.e. more channels), so to optimize performance,
176+
you want to make sure that the number of channels is large enough (or larger).
177+
This is described in more detail in:
196178

197179
> "Efficient nonlinear transforms for lossy image compression"<br />
198180
> J. Ballé<br />
@@ -203,12 +185,14 @@ Tensorboard instance in the background before starting the training, then point
203185
your web browser to [port 6006 on your machine](http://localhost:6006):
204186

205187
```bash
206-
tensorboard --logdir=. &
188+
tensorboard --logdir=/tmp/train_bls2017 &
207189
```
208190

209-
When training has finished, the Python script can be used to compress and
210-
decompress images as follows. The same model checkpoint must be accessible to
211-
both commands.
191+
When training has finished, the Python script saves the trained model to the
192+
directory specified with `--model_path` (by default, `bls2017` in the current
193+
directory) in TensorFlow's `SavedModel` format. The script can then be used to
194+
compress and decompress images as follows. The same saved model must be
195+
accessible to both commands.
212196

213197
```bash
214198
python bls2017.py [options] compress original.png compressed.tfci
@@ -218,7 +202,7 @@ python bls2017.py [options] decompress compressed.tfci reconstruction.png
218202
## Building pip packages
219203

220204
This section describes the necessary steps to build your own pip packages of
221-
tensorflow-compression. This may be necessary to install it on platforms for
205+
TensorFlow Compression. This may be necessary to install it on platforms for
222206
which we don't provide precompiled binaries (currently only Linux and Darwin).
223207

224208
We use the custom-op Docker images (e.g.
@@ -231,7 +215,7 @@ instructions](https://github.com/tensorflow/custom-op).
231215

232216
Inside a Docker container from the image, the following steps need to be taken.
233217

234-
1. Clone the `tensorflow-compression` repo from GitHub.
218+
1. Clone the `tensorflow/compression` repo from GitHub.
235219
2. Run `:build_pip_pkg` inside the cloned repo.
236220

237221
For example:
@@ -255,9 +239,9 @@ pip install /tmp/tensorflow_compression/tensorflow_compression-*.whl
255239
```
256240

257241
Then run the unit tests (Do not run the tests in the workspace directory where
258-
`WORKSPACE` of `tensorflow_compression` repo lives. In that case, the Python
259-
interpreter would attempt to import `tensorflow_compression` packages from the
260-
source tree, rather than from the installed package system directory):
242+
the `WORKSPACE` file lives. In that case, the Python interpreter would attempt
243+
to import `tensorflow_compression` packages from the source tree, rather than
244+
from the installed package system directory):
261245

262246
```bash
263247
pushd /tmp

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
theme: jekyll-theme-hacker
2-
title: tensorflow-compression
1+
theme: jekyll-theme-primer
2+
title: TensorFlow Compression
33
show_downloads: false

build_pip_pkg.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import shutil
2121
import sys
2222
import tempfile
23-
2423
import setuptools
2524

2625
# Version string is intentionally set to non-numeric value, so that non-release
2726
# built packages are different from release packages. During builds for formal
2827
# releases, we should temporarily change this value to pip release version.
29-
__version__ = 'custom-build-from-source'
28+
__version__ = "custom-build-from-source"
3029

3130

3231
class BinaryDistribution(setuptools.Distribution):
@@ -40,72 +39,72 @@ def main(srcdir):
4039
tempdir = tempfile.mkdtemp()
4140
atexit.register(shutil.rmtree, tempdir)
4241

43-
pkgdir = os.path.join(tempdir, 'tensorflow_compression')
44-
shutil.copytree(os.path.join(srcdir, 'tensorflow_compression'), pkgdir)
45-
shutil.copy2(os.path.join(srcdir, 'MANIFEST.in'), tempdir)
46-
shutil.copy2(os.path.join(srcdir, 'LICENSE'), pkgdir)
47-
shutil.copy2(os.path.join(srcdir, 'README.md'), pkgdir)
42+
pkgdir = os.path.join(tempdir, "tensorflow_compression")
43+
shutil.copytree(os.path.join(srcdir, "tensorflow_compression"), pkgdir)
44+
shutil.copy2(os.path.join(srcdir, "MANIFEST.in"), tempdir)
45+
shutil.copy2(os.path.join(srcdir, "LICENSE"), pkgdir)
46+
shutil.copy2(os.path.join(srcdir, "README.md"), pkgdir)
4847

4948
if not os.path.exists(
50-
os.path.join(pkgdir, 'cc/libtensorflow_compression.so')):
51-
raise RuntimeError('libtensorflow_compression.so not found. '
52-
'Did you \'bazel run?\'')
49+
os.path.join(pkgdir, "cc/libtensorflow_compression.so")):
50+
raise RuntimeError("libtensorflow_compression.so not found. "
51+
"Did you 'bazel run?'")
52+
53+
with open(os.path.join(srcdir, "requirements.txt"), "r") as f:
54+
install_requires = f.readlines()
5355

54-
print('=== Building wheel')
56+
print("=== Building wheel")
5557
atexit.register(os.chdir, os.getcwd())
5658
os.chdir(tempdir)
5759
setuptools.setup(
58-
name='tensorflow-compression',
60+
name="tensorflow_compression",
5961
version=__version__,
60-
description='Data compression in TensorFlow',
61-
url='https://tensorflow.github.io/compression/',
62-
author='Google LLC',
62+
description="Data compression in TensorFlow",
63+
url="https://tensorflow.github.io/compression/",
64+
author="Google LLC",
6365
# Contained modules and scripts.
6466
packages=setuptools.find_packages(),
65-
install_requires=[
66-
'scipy >= 1',
67-
'tensorflow_probability >= 0.12.1',
68-
],
69-
script_args=['sdist', 'bdist_wheel'],
67+
install_requires=install_requires,
68+
script_args=["sdist", "bdist_wheel"],
7069
# Add in any packaged data.
7170
include_package_data=True,
7271
zip_safe=False,
7372
distclass=BinaryDistribution,
7473
# PyPI package information.
7574
classifiers=[
76-
'Development Status :: 5 - Production/Stable',
77-
'Intended Audience :: Developers',
78-
'Intended Audience :: Education',
79-
'Intended Audience :: Science/Research',
80-
'License :: OSI Approved :: Apache Software License',
81-
'Programming Language :: Python :: 3',
82-
'Programming Language :: Python :: 3.6',
83-
'Programming Language :: Python :: 3.7',
84-
'Programming Language :: Python :: 3.8',
85-
'Topic :: Scientific/Engineering :: Mathematics',
86-
'Topic :: Software Development :: Libraries :: Python Modules',
87-
'Topic :: Software Development :: Libraries',
75+
"Development Status :: 5 - Production/Stable",
76+
"Intended Audience :: Developers",
77+
"Intended Audience :: Education",
78+
"Intended Audience :: Science/Research",
79+
"License :: OSI Approved :: Apache Software License",
80+
"Programming Language :: Python :: 3",
81+
"Programming Language :: Python :: 3.6",
82+
"Programming Language :: Python :: 3.7",
83+
"Programming Language :: Python :: 3.8",
84+
"Topic :: Scientific/Engineering :: Mathematics",
85+
"Topic :: Software Development :: Libraries :: Python Modules",
86+
"Topic :: Software Development :: Libraries",
8887
],
8988
project_urls={
90-
'Documentation':
91-
'https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html',
92-
'Discussion':
93-
'https://groups.google.com/forum/#!forum/tensorflow-compression',
94-
'Source': 'https://github.com/tensorflow/compression',
95-
'Tracker': 'https://github.com/tensorflow/compression/issues',
89+
"Documentation":
90+
"https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html",
91+
"Discussion":
92+
"https://groups.google.com/forum/#!forum/tensorflow-compression",
93+
"Source": "https://github.com/tensorflow/compression",
94+
"Tracker": "https://github.com/tensorflow/compression/issues",
9695
},
97-
license='Apache 2.0',
98-
keywords=('compression data-compression tensorflow machine-learning '
99-
'python deep-learning deep-neural-networks neural-network ml')
96+
license="Apache 2.0",
97+
keywords=("compression data-compression tensorflow machine-learning "
98+
"python deep-learning deep-neural-networks neural-network ml")
10099
)
101100

102-
destdir = '/tmp/tensorflow_compression'
103-
print('=== Copying wheel to ' + destdir)
101+
destdir = "/tmp/tensorflow_compression"
102+
print("=== Copying wheel to " + destdir)
104103
if not os.path.exists(destdir): os.mkdir(destdir)
105-
for path in glob.glob(os.path.join(tempdir, 'dist', '*.whl')):
106-
print('Copying into ' + os.path.join(destdir, os.path.basename(path)))
104+
for path in glob.glob(os.path.join(tempdir, "dist", "*.whl")):
105+
print("Copying into " + os.path.join(destdir, os.path.basename(path)))
107106
shutil.copy(path, destdir)
108107

109108

110-
if __name__ == '__main__':
111-
main(sys.argv[1] if len(sys.argv) > 1 else '')
109+
if __name__ == "__main__":
110+
main(sys.argv[1] if len(sys.argv) > 1 else "")

0 commit comments

Comments
 (0)