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
55You can use this library to build your own ML models with end-to-end optimized
66data compression built in. It's useful to find storage-efficient representations
@@ -31,58 +31,41 @@ question or answer more easily later.
3131
3232Refer to [ the API
3333documentation] ( 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
4139Darwin/Mac OS. To use these packages on Windows, consider using a [ TensorFlow
4240Docker 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
4543Set up an environment in which you can install precompiled binary Python
4644packages using the ` pip ` command. Refer to the
4745[ TensorFlow installation instructions] ( https://www.tensorflow.org/install/pip )
4846for 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
5350releases] ( https://github.com/tensorflow/compression/releases ) .
5451
5552### pip
5653
5754To 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
8265python -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
8669similar 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
9477host. 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
11691binary version of TensorFlow which is incompatible with our pip package. To
11792solve this, always install TensorFlow via ` pip ` rather than ` conda ` . For
11893example, 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
12095support:
12196
12297``` bash
12398conda create --name ENV_NAME python=3.6 cudatoolkit=10.0 cudnn
12499conda 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
167142The
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
178156python 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
203185your 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
214198python 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
220204This 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
222206which we don't provide precompiled binaries (currently only Linux and Darwin).
223207
224208We use the custom-op Docker images (e.g.
@@ -231,7 +215,7 @@ instructions](https://github.com/tensorflow/custom-op).
231215
232216Inside 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.
2352192 . Run ` :build_pip_pkg ` inside the cloned repo.
236220
237221For example:
@@ -255,9 +239,9 @@ pip install /tmp/tensorflow_compression/tensorflow_compression-*.whl
255239```
256240
257241Then 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
263247pushd /tmp
0 commit comments