1
- # Introduction
1
+ # TensorFlow Compression
2
2
3
- This project contains data compression ops and layers for TensorFlow.
3
+ TensorFlow Compression (TFC) contains data compression tools for TensorFlow.
4
4
5
5
You can use this library to build your own ML models with end-to-end optimized
6
6
data compression built in. It's useful to find storage-efficient representations
@@ -31,58 +31,41 @@ question or answer more easily later.
31
31
32
32
Refer to [ the API
33
33
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.
37
35
38
36
## Installation
39
37
40
38
*** Note: Precompiled packages are currently only provided for Linux and
41
39
Darwin/Mac OS. To use these packages on Windows, consider using a [ TensorFlow
42
40
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.***
44
42
45
43
Set up an environment in which you can install precompiled binary Python
46
44
packages using the ` pip ` command. Refer to the
47
45
[ TensorFlow installation instructions] ( https://www.tensorflow.org/install/pip )
48
46
for more information on how to set up such a Python environment.
49
47
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
53
50
releases] ( https://github.com/tensorflow/compression/releases ) .
54
51
55
52
### pip
56
53
57
54
To install TF and TFC via ` pip ` , run the following command:
58
55
59
56
``` bash
60
- pip install tensorflow-gpu==1.15 tensorflow-compression==1.3
57
+ pip install tensorflow-gpu==2.4. * tensorflow-compression==2.0
61
58
```
62
59
63
- for the stable release, or
60
+ If you don't need GPU support, you can drop the ` -gpu ` part.
64
61
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:
80
63
81
64
``` bash
82
65
python -m tensorflow_compression.all_tests
83
66
```
84
67
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
86
69
similar in the last line.
87
70
88
71
### Docker
@@ -94,16 +77,8 @@ and then run the `pip install` command inside the Docker container, not on the
94
77
host. For instance, you can use a command line like this:
95
78
96
79
``` 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 &&
107
82
python -m tensorflow_compression.all_tests"
108
83
```
109
84
@@ -116,13 +91,13 @@ It seems that [Anaconda](https://www.anaconda.com/distribution/) ships its own
116
91
binary version of TensorFlow which is incompatible with our pip package. To
117
92
solve this, always install TensorFlow via ` pip ` rather than ` conda ` . For
118
93
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
120
95
support:
121
96
122
97
``` bash
123
98
conda create --name ENV_NAME python=3.6 cudatoolkit=10.0 cudnn
124
99
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
126
101
```
127
102
128
103
## Usage
@@ -166,33 +141,40 @@ appended (any existing extensions will not be removed).
166
141
167
142
The
168
143
[ 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:
170
147
171
148
> "End-to-end optimized image compression"<br />
172
149
> J. Ballé, V. Laparra, E. P. Simoncelli<br />
173
150
> https://arxiv.org/abs/1611.01704
174
151
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:
176
154
177
155
``` bash
178
156
python bls2017.py -h
179
157
```
180
158
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:
184
161
185
162
``` bash
186
- python bls2017.py --verbose train --train_glob= " images/*.png "
163
+ python bls2017.py -V train
187
164
```
188
165
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:
196
178
197
179
> "Efficient nonlinear transforms for lossy image compression"<br />
198
180
> J. Ballé<br />
@@ -203,12 +185,14 @@ Tensorboard instance in the background before starting the training, then point
203
185
your web browser to [ port 6006 on your machine] ( http://localhost:6006 ) :
204
186
205
187
``` bash
206
- tensorboard --logdir=. &
188
+ tensorboard --logdir=/tmp/train_bls2017 &
207
189
```
208
190
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.
212
196
213
197
``` bash
214
198
python bls2017.py [options] compress original.png compressed.tfci
@@ -218,7 +202,7 @@ python bls2017.py [options] decompress compressed.tfci reconstruction.png
218
202
## Building pip packages
219
203
220
204
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
222
206
which we don't provide precompiled binaries (currently only Linux and Darwin).
223
207
224
208
We use the custom-op Docker images (e.g.
@@ -231,7 +215,7 @@ instructions](https://github.com/tensorflow/custom-op).
231
215
232
216
Inside a Docker container from the image, the following steps need to be taken.
233
217
234
- 1 . Clone the ` tensorflow- compression ` repo from GitHub.
218
+ 1 . Clone the ` tensorflow/ compression ` repo from GitHub.
235
219
2 . Run ` :build_pip_pkg ` inside the cloned repo.
236
220
237
221
For example:
@@ -255,9 +239,9 @@ pip install /tmp/tensorflow_compression/tensorflow_compression-*.whl
255
239
```
256
240
257
241
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):
261
245
262
246
``` bash
263
247
pushd /tmp
0 commit comments