1
- # TensorFlow Compression
1
+ # Introduction
2
2
3
3
This project contains data compression ops and layers for TensorFlow. The
4
4
project website is at
@@ -37,54 +37,44 @@ There's also an introduction to our `EntropyBottleneck` class
37
37
and a description of the range coding operators
38
38
[ here] ( https://tensorflow.github.io/compression/docs/range_coding.html ) .
39
39
40
- ## Quick start
40
+ ## Installation
41
41
42
- ### Installing release 1.1 (stable)
43
-
44
- Install TensorFlow 1.13 using one of the methods described in the
45
- [ TensorFlow installation instructions] ( https://www.tensorflow.org/install ) .
46
-
47
- Download the ZIP file for
48
- [ release v1.1] ( https://github.com/tensorflow/compression/releases/tag/v1.1 )
49
- and unpack it. Then include its root directory in your ` PYTHONPATH `
50
- environment variable:
51
-
52
- ``` bash
53
- cd < target directory>
54
- wget https://github.com/tensorflow/compression/archive/v1.1.zip
55
- unzip v1.1.zip
56
- export PYTHONPATH=" $PWD /compression-1.1:$PYTHONPATH "
57
- ```
58
-
59
- To make sure the library imports succeed, try running the unit tests:
60
-
61
- ``` bash
62
- cd compression-1.1
63
- for i in tensorflow_compression/python/* /* _test.py; do python $i ; done
64
- ```
65
-
66
- ### Installing release 1.2b2 (beta)
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.***
67
46
68
47
Set up an environment in which you can install precompiled binary Python
69
48
packages using the ` pip ` command. Refer to the
70
49
[ TensorFlow installation instructions] ( https://www.tensorflow.org/install/pip )
71
50
for more information on how to set up such a Python environment.
72
51
73
- Install TensorFlow 1.14 or above with or without GPU support:
52
+ The current version of tensorflow-compression requires TensorFlow 1.14 or
53
+ above. You can install TensorFlow from any source. To install it via ` pip ` , run
54
+ the following command:
74
55
``` bash
75
- pip install tensorflow
56
+ pip install tensorflow-gpu
76
57
```
77
- or
58
+ for GPU support, or
78
59
``` bash
79
- pip install tensorflow-gpu
60
+ pip install tensorflow
80
61
```
62
+ for CPU-only.
81
63
82
- Then, run the following command to install the binary PIP package:
64
+ Then, run the following command to install the tensorflow-compression ` pip `
65
+ package:
83
66
``` bash
84
67
pip install tensorflow-compression
85
68
```
86
69
87
- ### Using the library
70
+ To test that the installation works correctly, you can run the unit tests with
71
+ ``` bash
72
+ python -m tensorflow_compression.python.all_test
73
+ ```
74
+ Once the command finishes, you should see a message ``` OK (skipped=11) ``` or
75
+ similar in the last line.
76
+
77
+ ## Usage
88
78
89
79
We recommend importing the library from your Python code as follows:
90
80
@@ -95,31 +85,23 @@ import tensorflow_compression as tfc
95
85
96
86
### Using a pre-trained model to compress an image
97
87
98
- *** Note: you need to have a release >1.1 installed for pre-trained model
99
- support.***
100
-
101
88
In the
102
89
[ examples directory] ( https://github.com/tensorflow/compression/tree/master/examples ) ,
103
90
you'll find a python script ` tfci.py ` . Download the file and run:
104
-
105
91
``` bash
106
92
python tfci.py -h
107
93
```
108
94
109
95
This will give you a list of options. Briefly, the command
110
-
111
96
``` bash
112
97
python tfci.py compress < model> < PNG file>
113
98
```
114
-
115
99
will compress an image using a pre-trained model and write a file ending in
116
100
` .tfci ` . Execute ` python tfci.py models ` to give you a list of supported
117
101
pre-trained models. The command
118
-
119
102
``` bash
120
103
python tfci.py decompress < TFCI file>
121
104
```
122
-
123
105
will decompress a TFCI file and write a PNG file. By default, an output file
124
106
will be named like the input file, only with the appropriate file extension
125
107
appended (any existing extensions will not be removed).
@@ -135,15 +117,13 @@ contains an implementation of the image compression model described in:
135
117
> https://arxiv.org/abs/1611.01704
136
118
137
119
To see a list of options, download the file ` bls2017.py ` and run:
138
-
139
120
``` bash
140
121
python bls2017.py -h
141
122
```
142
123
143
124
To train the model, you need to supply it with a dataset of RGB training images.
144
125
They should be provided in PNG format. Training can be as simple as the
145
126
following command:
146
-
147
127
``` bash
148
128
python bls2017.py -v --train_glob=" images/*.png" train
149
129
```
@@ -163,34 +143,34 @@ enough (or larger). This is described in more detail in:
163
143
If you wish, you can monitor progress with Tensorboard. To do this, create a
164
144
Tensorboard instance in the background before starting the training, then point
165
145
your web browser to [ port 6006 on your machine] ( http://localhost:6006 ) :
166
-
167
146
``` bash
168
147
tensorboard --logdir=. &
169
148
```
170
149
171
150
When training has finished, the Python script can be used to compress and
172
151
decompress images as follows. The same model checkpoint must be accessible to
173
152
both commands.
174
-
175
153
``` bash
176
154
python bls2017.py [options] compress original.png compressed.bin
177
155
python bls2017.py [options] decompress compressed.bin reconstruction.png
178
156
```
179
157
180
- ## Building PIP packages
158
+ ## Building ` pip ` packages
181
159
182
- This section describes steps to build PIP packages.
160
+ This section describes the necessary steps to build your own ` pip ` packages of
161
+ tensorflow-compression. This may be necessary to install it on platforms for
162
+ which we don't provide precompiled binaries (currently only Linux and Darwin).
183
163
184
- We use the Docker image ` tensorflow/tensorflow:nightly-custom-op ` for building
185
- PIP packages. Note that this is different from ` tensorflow/tensorflow:devel ` . To
186
- be compatible with the TensorFlow PIP package, the GCC version must match, but
187
- ` tensorflow/tensorflow:devel ` has a different GCC version installed.
164
+ We use the Docker image ` tensorflow/tensorflow:nightly-custom-op ` for building
165
+ ` pip ` packages. Note that this is different from ` tensorflow/tensorflow:devel ` .
166
+ To be compatible with the TensorFlow ` pip ` package, the GCC version must match,
167
+ but ` tensorflow/tensorflow:devel ` has a different GCC version installed.
188
168
189
- Inside a Docker container from the image, the following steps need to be done .
169
+ Inside a Docker container from the image, the following steps need to be taken .
190
170
191
- 1 . Install TensorFlow PIP package.
192
- 2 . Clone ` tensorflow- compression ` repo from GitHub.
193
- 3 . Run ` :build_pip_pkg ` inside the cloned repo.
171
+ 1 . Install TensorFlow ` pip ` package.
172
+ 2 . Clone the ` tensorflow/ compression ` repo from GitHub.
173
+ 3 . Run ` :build_pip_pkg ` inside the cloned repo:
194
174
195
175
``` bash
196
176
sudo docker run -v /tmp/tensorflow_compression:/tmp/tensorflow_compression \
@@ -204,28 +184,22 @@ sudo docker run -v /tmp/tensorflow_compression:/tmp/tensorflow_compression \
204
184
The wheel file is created inside ` /tmp/tensorflow_compression ` . Optimization
205
185
flags can be passed via ` --copt ` to the ` bazel run ` command above.
206
186
207
- ### Testing PIP package
208
-
209
- First install the built wheel file.
210
-
187
+ To test the created package, first install the resulting wheel file:
211
188
``` bash
212
189
pip install /tmp/tensorflow_compression/tensorflow_compression-* .whl
213
190
```
214
191
215
- And run tests. (Do not run the tests in the workspace directory where
192
+ Then run the unit tests (Do not run the tests in the workspace directory where
216
193
` WORKSPACE ` of ` tensorflow_compression ` repo lives. In that case, the Python
217
- interpreter attempts to import ` tensorflow_compression ` packages from the source
218
- tree rather than from the installed package system directory.)
219
-
194
+ interpreter would attempt to import ` tensorflow_compression ` packages from the
195
+ source tree rather than from the installed package system directory):
220
196
``` bash
221
197
pushd /tmp
222
198
python -m tensorflow_compression.python.all_test
223
199
popd
224
200
```
225
201
226
- When done, uninstall the PIP package. The package name is
227
- ` tensorflow-compression ` with a hyphen(-).
228
-
202
+ When done, you can uninstall the ` pip ` package again:
229
203
``` bash
230
204
pip uninstall tensorflow-compression
231
205
```
0 commit comments