Skip to content

Commit 819fc48

Browse files
author
Seungil You
committed
rebase
0 parents  commit 819fc48

File tree

145 files changed

+23058
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+23058
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
.ipynb_checkpoints
3+
node_modules
4+
/.bazelrc
5+
/bazel-*
6+
/bazel_pip
7+
/pip_test
8+
/_python_build
9+
*.pyc
10+
__pycache__
11+
*.swp
12+
.vscode/

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "tensorflow"]
2+
path = tensorflow
3+
url = https://github.com/tensorflow/tensorflow.git
4+
branch = r1.3

AUTHORS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This is the official list of TensorFlow Lattice authors for copyright purposes.
2+
# Names should be added to this file as:
3+
# Name or Organization <email address>
4+
# The email address is not required for organizations.
5+
Google Inc.

BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2017 The TensorFlow Lattice Authors.
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+
sh_binary(
16+
name = "pip_pkg",
17+
srcs = ["pip_pkg.sh"],
18+
data = [
19+
"MANIFEST.in",
20+
"setup.py",
21+
"//tensorflow_lattice",
22+
],
23+
)

CONTRIBUTING.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- Copyright 2017 The TensorFlow Lattice Authors.
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+
# How to Contribute
16+
17+
We'd love to accept your patches and contributions to this project. There are
18+
just a few small guidelines you need to follow.
19+
20+
## Contributor License Agreement
21+
22+
Contributions to this project must be accompanied by a Contributor License
23+
Agreement. You (or your employer) retain the copyright to your contribution,
24+
this simply gives us permission to use and redistribute your contributions as
25+
part of the project. Head over to <https://cla.developers.google.com/> to see
26+
your current agreements on file or to sign a new one.
27+
28+
You generally only need to submit a CLA once, so if you've already submitted one
29+
(even if it was for a different project), you probably don't need to do it
30+
again.
31+
32+
## Code reviews
33+
34+
All submissions, including submissions by project members, require review. We
35+
use GitHub pull requests for this purpose. Consult
36+
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
37+
information on using pull requests.

INSTALL.md

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<!-- Copyright 2017 The TensorFlow Lattice Authors.
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+
# TensorFlow Lattice installation
16+
17+
TensorFlow Lattice runs on Ubuntu and Mac OS X, and requires TensorFlow.
18+
19+
We highly recommend to read [TensorFlow installation
20+
instructions](https://www.tensorflow.org/install), especially [Installing
21+
TensorFlow on Ubuntu](https://www.tensorflow.org/install/install_linux) to
22+
understand virtualenv and pip, and [Installing TensorFlow from
23+
Sources](https://www.tensorflow.org/install/install_sources).
24+
25+
# Install the prebuilt pip package
26+
27+
## Activate virtualenv
28+
If using virtualenv, activate your virtualenv for the rest of the installation,
29+
otherwise skip this step:
30+
31+
``` shell
32+
~$ virtualenv --system-site-packages tensorflow-lattice # for Python 2.7
33+
~$ virtualenv --system-site-packages -p python3 tensorflow-lattice # for Python 3.n
34+
```
35+
36+
Here you can change `tensorflow-lattice` to another target directory you want to
37+
use.
38+
39+
```shell
40+
~$ source tensorflow-lattice/bin/activate # bash, sh, ksh, or zsh
41+
~$ source tensorflow-lattice/bin/activate.csh # csh or tcsh
42+
```
43+
44+
## Install pip packages.
45+
You can use pip install to install tensorflow-lattice pip package.
46+
47+
```shell
48+
(tensorflow-lattice)$ pip install --upgrade tensorflow-lattice # for Python 2.7
49+
(tensorflow-lattice)$ pip3 install --upgrade tensorflow-lattice # for Python 3.n
50+
(tensorflow-lattice)$ pip install --upgrade tensorflow-lattice-gpu # for Python 2.7 and GPU
51+
(tensorflow-lattice)$ pip3 install --upgrade tensorflow-lattice-gpu # for Python 3.n and GPU
52+
```
53+
Our custom operators do not have GPU kernels. The main difference
54+
between `tensorflow-lattice-gpu` and `tensorflow-lattice` pip package is that
55+
the former requires `tensorflow-gpu` pip package whereas the latter requires
56+
`tensorflow` pip package.
57+
58+
## Test TensorFlow and TensorFlow Lattice
59+
60+
Run the following python script to test TensorFlow Lattice.
61+
62+
```python
63+
import tensorflow as tf
64+
import tensorflow_lattice as tfl
65+
66+
x = tf.placeholder(tf.float32, shape=(None, 2))
67+
(y, _, _, _) = tfl.lattice_layer(x, lattice_sizes=(2, 2))
68+
69+
with tf.Session() as sess:
70+
sess.run(tf.global_variables_initializer())
71+
print(sess.run(y, feed_dict={x: [[0.0, 0.0]]}))
72+
```
73+
74+
Now you are ready to use *TensorFlow Lattice*, and you can stop here unless you
75+
want to build TensorFlow Lattice from the source.
76+
77+
# Build TensorFlow Lattice and TensorFlow pip package from the source.
78+
You can also build TensorFlow Lattice packages from the source.
79+
For this, you will need to compile all libraries using
80+
[Bazel](https://bazel.build) against TensorFlow headers.
81+
82+
83+
We will show how to build TensorFlow and TensorFlow Lattice pip package using
84+
Bazel, and install it to your virtualenv.
85+
86+
## Activate virtualenv
87+
88+
If using virtualenv, activate your virtualenv for the rest of the installation,
89+
otherwise skip this step:
90+
91+
```shell
92+
~$ source $VIRTUALENV_PATH/bin/activate # bash, sh, ksh, or zsh
93+
~$ source $VIRTUALENV_PATH/bin/activate.csh # csh or tcsh
94+
```
95+
96+
or if you are using virtualenv for the first time,
97+
98+
```shell
99+
~$ sudo apt-get install python-virtualenv
100+
~$ virtualenv --system-site-packages tensorflow-lattice
101+
~$ source ~/tensorflow-lattice/bin/activate # bash, sh, ksh, or zsh
102+
~$ source ~/tensorflow-lattice/bin/activate.csh # csh or tcsh
103+
```
104+
## Prepare TensorFlow envirnoment for Linux.
105+
106+
Please follow instructions in [Prepare environment for
107+
Linux](https://www.tensorflow.org/install/install_sources#prepare_environment_for_linux)
108+
to setup the environment for TensorFlow.
109+
110+
## Clone the TensorFlow Lattice repository.
111+
112+
Let us clone the TensorFlow Lattice repository, which contains TensorFlow as a
113+
submodule:
114+
115+
```shell
116+
(tensorflow-lattice)~$ git clone --recursive https://github.com/tensorflow/lattice.git
117+
```
118+
119+
## Configure TensorFlow and build TensorFlow pip package.
120+
121+
### Configure TensorFlow
122+
123+
We now need to configure TensorFlow options. See [Configure the
124+
installation](https://www.tensorflow.org/install/install_sources#configure_the_installation)
125+
for the details.
126+
127+
```shell
128+
(tensorflow-lattice)~$ cd lattice
129+
(tensorflow-lattice)~/lattice$ cd tensorflow
130+
(tensorflow-lattice)~/lattice/tensorflow$ ./configure
131+
```
132+
133+
### Build TensorFlow pip packaging script
134+
135+
We are ready to build the TensorFlow pip package. See [Build the pip
136+
package](https://www.tensorflow.org/install/install_sources#build_the_pip_package)
137+
for the details.
138+
139+
To build a pip package for TensorFlow with CPU-only support:
140+
141+
```shell
142+
(tensorflow-lattice)~/lattice/tensorflow$ bazel build \
143+
--config=opt \
144+
tensorflow/tools/pip_package:build_pip_package
145+
```
146+
147+
To build a pip package for TensorFlow with GPU support:
148+
149+
```shell
150+
(tensorflow-lattice)~/lattice/tensorflow$ bazel build \
151+
--config=cuda \
152+
tensorflow/tools/pip_package:build_pip_package
153+
```
154+
155+
### Install TensorFlow pip package
156+
157+
```shell
158+
(tensorflow-lattice)~/lattice/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
159+
(tensorflow-lattice)~/lattice/tensorflow$ pip install /tmp/tensorflow_pkg/*.whl
160+
```
161+
162+
### Build TensorFlow Lattice pip packaging script
163+
164+
To build a pip package for TensorFlow with CPU-only support:
165+
166+
```shell
167+
(tensorflow-lattice)~/$ cd ~/lattice
168+
(tensorflow-lattice)~/lattice$ bazel build \
169+
--config=opt :pip_pkg
170+
```
171+
172+
### Install TensorFlow Lattice pip package
173+
174+
```shell
175+
(tensorflow-lattice)~/lattice$ bazel-bin/pip_pkg /tmp/tensorflow_lattice_pkg
176+
(tensorflow-lattice)~/lattice$ pip install /tmp/tensorflow_lattice_pkg/*.whl
177+
```
178+
179+
### Test TensorFlow and TensorFlow Lattice
180+
```shell
181+
(tensorflow-lattice)~/lattice$ cd examples
182+
(tensorflow-lattice)~/lattice/examples$ python test.py
183+
```
184+
185+
test.py is a simple python script.
186+
187+
```python
188+
import tensorflow as tf
189+
import tensorflow_lattice as tfl
190+
191+
x = tf.placeholder(tf.float32, shape=(None, 2))
192+
(y, _, _, _) = tfl.lattice_layer(x, lattice_sizes=(2, 2))
193+
194+
with tf.Session() as sess:
195+
sess.run(tf.global_variables_initializer())
196+
print(sess.run(y, feed_dict={x: [[0.0, 0.0]]}))
197+
```

0 commit comments

Comments
 (0)