Skip to content

Commit f7fa935

Browse files
author
Johannes Ballé
committed
Add some more detail to the description of the example model.
1 parent 164bc19 commit f7fa935

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ This project contains data compression ops and layers for TensorFlow. The
22
project website is at
33
[tensorflow.github.io/compression](https://tensorflow.github.io/compression).
44

5-
What does this library do, you ask?
6-
7-
In a nutshell, you can use it to build your own ML models with optimized lossy
5+
You can use this library to build your own ML models with optimized lossy
86
data compression built in. It's useful to find storage-efficient representations
97
of your data (features, examples, images, 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

11+
Specifically, the
12+
[EntropyBottleneck class](https://tensorflow.github.io/compression/docs/entropy_bottleneck.html)
13+
in this library simplifies the process of designing rate–distortion optimized
14+
codes. During training, it acts like a likelihood model. Once training is
15+
completed, it encodes floating point tensors into optimal bit sequences by
16+
automating the design of probability tables and calling a range coder
17+
implementation behind the scenes.
18+
1319
For an introduction to lossy data compression with machine learning, take a look
1420
at @jonycgn's
1521
[talk on Learned Image Compression](https://www.youtube.com/watch?v=x_q7cZviXkY).
@@ -58,13 +64,41 @@ in:
5864
To see a list of options, change to the directory and run:
5965

6066
```bash
67+
cd examples
6168
python bls2017.py -h
6269
```
6370

6471
To train the model, you need to supply it with a dataset of RGB training images.
65-
They should be provided in PNG format and must all have the same shape.
66-
Following training, the Python script can be used to compress and decompress
67-
images as follows:
72+
They should be provided in PNG format. Training can be as simple as the
73+
following command:
74+
75+
```bash
76+
python bls2017.py -v --train_glob=images/*.png train
77+
```
78+
79+
This will use the default settings. The most important parameter is `--lambda`,
80+
which controls the trade-off between bitrate and distortion that the model will
81+
be optimized for. The number of channels per layer is important, too: models
82+
tuned for higher bitrates (or, equivalently, lower distortion) tend to require
83+
transforms with a greater approximation capacity (i.e. more channels), so to
84+
optimize performance, you want to make sure that the number of channels is large
85+
enough (or larger). This is described in more detail in:
86+
87+
> "Efficient nonlinear transforms for lossy image compression"<br />
88+
> J. Ballé<br />
89+
> https://arxiv.org/abs/1802.00847
90+
91+
If you wish, you can monitor progress with Tensorboard. To do this, create a
92+
Tensorboard instance in the background before starting the training, then point
93+
your web browser to [port 6006 on your machine](http://localhost:6006):
94+
95+
```bash
96+
tensorboard --logdir=. &
97+
```
98+
99+
When training has finished, the Python script can be used to compress and
100+
decompress images as follows. The same model checkpoint must be accessible to
101+
both commands.
68102

69103
```bash
70104
python bls2017.py [options] compress original.png compressed.bin

0 commit comments

Comments
 (0)