Skip to content

Commit 787cbd1

Browse files
GooglerSung Jin Hwang
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 247508635 Change-Id: I3e0798513af39a8c906db3aff48a26166edf5857
1 parent 4a58820 commit 787cbd1

File tree

10 files changed

+366
-109
lines changed

10 files changed

+366
-109
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
*.pyc
33
*.so
44
*~
5+
6+
# Ignore bazel-* symlinks.
7+
/bazel-*

BUILD

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,33 @@ py_library(
55
srcs = [
66
"tensorflow_compression/__init__.py",
77
"tensorflow_compression/python/__init__.py",
8-
"tensorflow_compression/python/layers/__init__.py",
9-
"tensorflow_compression/python/layers/entropy_models.py",
10-
"tensorflow_compression/python/layers/gdn.py",
11-
"tensorflow_compression/python/layers/initializers.py",
12-
"tensorflow_compression/python/layers/parameterizers.py",
13-
"tensorflow_compression/python/layers/signal_conv.py",
14-
"tensorflow_compression/python/ops/__init__.py",
15-
"tensorflow_compression/python/ops/math_ops.py",
16-
"tensorflow_compression/python/ops/namespace_helper.py",
17-
"tensorflow_compression/python/ops/padding_ops.py",
18-
"tensorflow_compression/python/ops/range_coding_ops.py",
19-
"tensorflow_compression/python/ops/spectral_ops.py",
208
],
21-
data = [
22-
"//tensorflow_compression/cc:libtensorflow_compression.so",
9+
deps = [
10+
"//tensorflow_compression/python/layers",
11+
"//tensorflow_compression/python/ops",
2312
],
2413
visibility = ["//visibility:public"],
2514
)
2615

16+
filegroup(
17+
name = "pip_src",
18+
srcs = [
19+
"MANIFEST.in",
20+
"setup.py",
21+
"tensorflow_compression/python/all_test.py",
22+
],
23+
)
24+
2725
sh_binary(
2826
name = "build_pip_pkg",
2927
srcs = ["build_pip_pkg.sh"],
3028
data = [
3129
"LICENSE",
32-
"MANIFEST.in",
3330
"README.md",
34-
"setup.py",
31+
":pip_src",
3532
":tensorflow_compression",
33+
# The following targets are for Python test files.
34+
"//tensorflow_compression/python/layers:py_src",
35+
"//tensorflow_compression/python/ops:py_src",
3636
],
3737
)
38-
39-
py_test(
40-
name = "entropy_models_test",
41-
timeout = "long",
42-
srcs = ["tensorflow_compression/python/layers/entropy_models_test.py"],
43-
deps = [":tensorflow_compression"],
44-
)
45-
46-
py_test(
47-
name = "gdn_test",
48-
srcs = ["tensorflow_compression/python/layers/gdn_test.py"],
49-
deps = [":tensorflow_compression"],
50-
)
51-
52-
py_test(
53-
name = "parameterizers_test",
54-
srcs = ["tensorflow_compression/python/layers/parameterizers_test.py"],
55-
deps = [":tensorflow_compression"],
56-
)
57-
58-
py_test(
59-
name = "signal_conv_test",
60-
timeout = "long",
61-
srcs = ["tensorflow_compression/python/layers/signal_conv_test.py"],
62-
deps = [":tensorflow_compression"],
63-
)
64-
65-
py_test(
66-
name = "math_ops_test",
67-
srcs = ["tensorflow_compression/python/ops/math_ops_test.py"],
68-
deps = [":tensorflow_compression"],
69-
)
70-
71-
py_test(
72-
name = "padding_ops_test",
73-
srcs = ["tensorflow_compression/python/ops/padding_ops_test.py"],
74-
deps = [":tensorflow_compression"],
75-
)
76-
77-
py_test(
78-
name = "spectral_ops_test",
79-
srcs = ["tensorflow_compression/python/ops/spectral_ops_test.py"],
80-
deps = [":tensorflow_compression"],
81-
)
82-
83-
py_test(
84-
name = "range_coding_ops_test",
85-
srcs = ["tensorflow_compression/python/ops/range_coding_ops_test.py"],
86-
deps = [":tensorflow_compression"],
87-
)

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# TensorFlow Compression
2+
13
This project contains data compression ops and layers for TensorFlow. The
24
project website is at
35
[tensorflow.github.io/compression](https://tensorflow.github.io/compression).
@@ -20,9 +22,9 @@ For an introduction to lossy image compression with machine learning, take a
2022
look at @jonycgn's
2123
[talk on Learned Image Compression](https://www.youtube.com/watch?v=x_q7cZviXkY).
2224

23-
# Quick start
25+
## Quick start
2426

25-
## Installing release 1.1 (stable)
27+
### Installing release 1.1 (stable)
2628

2729
Install TensorFlow 1.13 using one of the methods described in the
2830
[TensorFlow installation instructions](https://www.tensorflow.org/install).
@@ -46,7 +48,7 @@ cd compression-1.1
4648
for i in tensorflow_compression/python/*/*_test.py; do python $i; done
4749
```
4850

49-
## Installing release 1.2b1 (beta)
51+
### Installing release 1.2b1 (beta)
5052

5153
Set up an environment in which you can install precompiled binary Python
5254
packages using the `pip` command. Refer to the
@@ -66,7 +68,7 @@ Desktop for Mac, and run the above command inside a container based on the
6668
[TensorFlow docker image](https://www.tensorflow.org/install/docker) for
6769
Python 2.7.***
6870

69-
## Using the library
71+
### Using the library
7072

7173
We recommend importing the library from your Python code as follows:
7274

@@ -75,7 +77,7 @@ import tensorflow as tf
7577
import tensorflow_compression as tfc
7678
```
7779

78-
## Using a pre-trained model to compress an image
80+
### Using a pre-trained model to compress an image
7981

8082
***Note: you need to have a release >1.1 installed for pre-trained model
8183
support.***
@@ -106,7 +108,7 @@ will decompress a TFCI file and write a PNG file. By default, an output file
106108
will be named like the input file, only with the appropriate file extension
107109
appended (any existing extensions will not be removed).
108110

109-
## Training your own model
111+
### Training your own model
110112

111113
The
112114
[examples directory](https://github.com/tensorflow/compression/tree/master/examples)
@@ -159,7 +161,7 @@ python bls2017.py [options] compress original.png compressed.bin
159161
python bls2017.py [options] decompress compressed.bin reconstruction.png
160162
```
161163

162-
# Help & documentation
164+
## Help & documentation
163165

164166
For usage questions and discussions, please head over to our
165167
[Google group](https://groups.google.com/forum/#!forum/tensorflow-compression).
@@ -174,7 +176,57 @@ There's also an introduction to our `EntropyBottleneck` class
174176
and a description of the range coding operators
175177
[here](https://tensorflow.github.io/compression/docs/range_coding.html).
176178

177-
# Authors
179+
## Building PIP package
180+
181+
This section describes steps to build PIP package.
182+
183+
Docker image `tensorflow/tensorflow:custom-op` is used for PIP package build.
184+
Note that this is different from `tensorflow/tensorflow:devel`. To be compatible
185+
with TensorFlow PIP package, the GCC version must match, but
186+
`tensorflow/tensorflow:devel` has a different GCC version installed.
187+
188+
Inside a Docker container, Git repo is cloned from GitHub, then run script
189+
`//:build_pip_pkg`.
190+
191+
```bash
192+
sudo docker run -v /tmp/tensorflow_compression:/tmp/tensorflow_compression \
193+
tensorflow/tensorflow:custom-op \
194+
bash -c "git clone https://github.com/tensorflow/compression.git
195+
/tensorflow_compression && cd /tensorflow_compression &&
196+
bazel run -c opt :build_pip_pkg"
197+
```
198+
199+
The wheel file is created inside `/tmp/tensorflow_compression`. Optimization
200+
flags can be passed via `--copt` to the `bazel run` command above. For example,
201+
`bazel` command above can be `bazel run -c opt --copt=-mavx :build_pip_pkg`.
202+
203+
### Testing PIP package
204+
205+
First install the built wheel file.
206+
207+
```bash
208+
pip install /tmp/tensorflow_compression/tensorflow_compression-*.whl
209+
```
210+
211+
And run tests. (Do not run the tests in the workspace directory where
212+
`WORKSPACE` of `tensorflow_compression` repo lives. In that case, Python
213+
interpreter attempts to import `tensorflow_compression` packages from the source
214+
tree rather than from the installed package system directory.)
215+
216+
```bash
217+
pushd /tmp
218+
python -m tensorflow_compression.python.all_test
219+
popd
220+
```
221+
222+
When done, uninstall the PIP package. The package name is
223+
`tensorflow-compression` with a hyphen(-).
224+
225+
```bash
226+
pip uninstall tensorflow-compression
227+
```
228+
229+
## Authors
178230

179231
Johannes Ballé (github: [jonycgn](https://github.com/jonycgn)), Sung Jin Hwang
180232
(github: [ssjhv](https://github.com/ssjhv)), and Nick Johnston (github:

WORKSPACE

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
local_repository(
2-
name = "tf_custom_op",
3-
# Change if tensorflow/custom-op repo is cloned into a different directory.
4-
path = "/custom-op",
5-
)
1+
workspace(name = "tensorflow_compression")
62

7-
load("//:workspace.bzl", "tf_compression_workspace")
8-
tf_compression_workspace()
3+
load("//:workspace.bzl", "tensorflow_compression_workspace")
4+
tensorflow_compression_workspace()

build_pip_pkg.sh

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,49 @@
1919
# ==============================================================================
2020

2121
set -e
22-
set -x
23-
24-
PIP_FILE_PREFIX="bazel-bin/build_pip_pkg.runfiles/__main__/"
2522

23+
# This script needs some improvements.
24+
# - Needs a flag to use 'python' or 'python3' to run setup.py.
25+
# - Needs a flag to control shared library file extension.
2626
function main() {
27-
DEST=${1}
28-
if [[ -z ${DEST} ]]; then
29-
DEST=/tmp
27+
if [ -z "${1}" ]; then
28+
DEST=/tmp/tensorflow_compression
29+
else
30+
DEST="${1}"
3031
fi
3132

32-
mkdir -p ${DEST}
33-
DEST=$(readlink -f "${DEST}")
34-
echo "=== destination directory: ${DEST}"
33+
mkdir -p "${DEST}"
34+
DEST="$(readlink -f "${DEST}")"
3535

3636
TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
37-
echo $(date) : "=== Using tmpdir: ${TMPDIR}"
37+
trap 'rm -rf "${TMPDIR}"' EXIT
3838

39-
echo "=== Copying files"
39+
echo $(date) : "=== Using tmpdir: ${TMPDIR}"
4040
PKGDIR="${TMPDIR}/tensorflow_compression"
41-
rsync -avm -L --exclude='*_test.py' --exclude='build_pip_pkg*' ${PIP_FILE_PREFIX} "${TMPDIR}"
42-
for FILENAME in "LICENSE" "README.md"
43-
do
44-
mv "${TMPDIR}/${FILENAME}" "${PKGDIR}"
45-
done
41+
42+
echo $(date) : "=== Copying files"
43+
rsync -amqL tensorflow_compression/ "${PKGDIR}/"
44+
cp MANIFEST.in setup.py "${TMPDIR}"
45+
cp LICENSE README.md "${PKGDIR}"
46+
47+
pushd ${TMPDIR} > /dev/null
48+
49+
# Check if shared library file is copied. If this fails, it is likely that
50+
# this script was run directly from the workspace directory. This should be
51+
# run inside bazel-bin/build_pip_pkg.runfiles/tensorflow_compression/, or
52+
# simply run using "bazel run".
53+
if [ ! -f tensorflow_compression/cc/libtensorflow_compression.so ]; then
54+
echo "libtensorflow_compression.so not found. Did you use \"bazel run?\""
55+
exit 1
56+
fi
4657

4758
echo $(date) : "=== Building wheel"
48-
pushd ${TMPDIR}
49-
python setup.py bdist_wheel > /dev/null
50-
cp dist/*.whl "${DEST}"
51-
popd
59+
python setup.py bdist_wheel
60+
61+
echo $(date) : "=== Copying wheel to /tmp/"
62+
rsync -a --info=name dist/*.whl "${DEST}"
63+
popd > /dev/null
5264

53-
rm -rf ${TMPDIR}
5465
echo $(date) : "=== Output wheel file is in: ${DEST}"
5566
}
5667

tensorflow_compression/cc/BUILD

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ cc_binary(
2525
# as, say "org_tensorflow" and replace the deps with
2626
# "@org_tensorflow//tensorflow/core:framework",
2727
# "@org_tensorflow//tensorflow/core:lib",
28-
"@local_config_tf//:libtensorflow_framework",
29-
"@local_config_tf//:tf_header_lib",
28+
"@tensorflow_pip//:libtensorflow_framework",
3029
],
3130
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2019 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Tests for tensorflow_compression/python.
16+
17+
This is a convenience file to be included in PIP package.
18+
No BUILD entry exists for this file on purpose.
19+
"""
20+
21+
from __future__ import absolute_import
22+
from __future__ import division
23+
from __future__ import print_function
24+
25+
import tensorflow as tf
26+
27+
# pylint: disable=wildcard-import
28+
from tensorflow_compression.python.layers.entropy_models_test import *
29+
from tensorflow_compression.python.layers.gdn_test import *
30+
from tensorflow_compression.python.layers.parameterizers_test import *
31+
from tensorflow_compression.python.layers.signal_conv_test import *
32+
33+
from tensorflow_compression.python.ops.math_ops_test import *
34+
from tensorflow_compression.python.ops.padding_ops_test import *
35+
from tensorflow_compression.python.ops.range_coding_ops_test import *
36+
from tensorflow_compression.python.ops.spectral_ops_test import *
37+
# pylint: enable=wildcard-import
38+
39+
40+
if __name__ == "__main__":
41+
tf.test.main()

0 commit comments

Comments
 (0)