Skip to content

Commit 2ebf87d

Browse files
committed
Update GUIDE, README
1 parent c55f6a3 commit 2ebf87d

File tree

2 files changed

+37
-154
lines changed

2 files changed

+37
-154
lines changed

GUIDE.md

+27-148
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ For Protobuf:
4747
sudo apt-get install autoconf automake libtool maven
4848
```
4949

50-
For gRPC:
51-
52-
```
53-
sudo apt-get install oracle-java7-jdk
54-
# Select the jdk-7-oracle option for the update-alternatives command
55-
sudo update-alternatives --config java
56-
```
57-
5850
For Bazel:
5951

6052
```shell
@@ -100,110 +92,39 @@ Now move into the new `protobuf` directory, configure it, and `make` it. _Note:
10092

10193
```shell
10294
cd protobuf
103-
git checkout v3.0.0-beta-3.3
95+
git checkout v3.0.0
10496
./autogen.sh
105-
./configure --prefix=/usr
97+
./configure
10698
make -j 4
10799
sudo make install
100+
sudo ldconfig
108101
```
109102

110-
Once it's made, we can move into the `java` directory and use Maven to build the project.
111-
112-
```shell
113-
cd java
114-
mvn package
115-
```
116-
117-
After following these steps, you'll have two spiffy new files: `/usr/bin/protoc` and `protobuf/java/core/target/protobuf-java-3.0.0-beta3.jar`
118-
119-
### 3. Build gRPC
120-
121-
Next, we need to build [gRPC-Java](https://github.com/grpc/grpc-java), the Java implementation of [gRPC](http://www.grpc.io/). Move out of the `protobuf/java` directory and clone gRPC's repository.
122-
123-
```shell
124-
cd ../..
125-
git clone https://github.com/grpc/grpc-java.git
126-
```
127-
128-
```shell
129-
cd grpc-java
130-
git checkout v0.14.1
131-
```
103+
Great! You should now have `protoc` installed in `/usr/local/bin`, and should be on your `PATH`. Check to make sure it's working correctly:
132104

133105
```shell
134-
cd compiler
135-
nano build.gradle
136-
```
137-
138-
Around line 47:
139-
140-
```
141-
gcc(Gcc) {
142-
target("linux_arm-v7") {
143-
cppCompiler.executable = "/usr/bin/gcc"
144-
}
145-
}
146-
```
147-
148-
Around line 60, add section for `'linux_arm-v7'`:
149-
150-
```
151-
...
152-
x86_64 {
153-
architecture "x86_64"
154-
}
155-
'linux_arm-v7' {
156-
architecture "arm32"
157-
operatingSystem "linux"
158-
}
159-
```
160-
161-
Around line 64, add `'arm32'` to list of architectures:
162-
163-
```
164-
...
165-
components {
166-
java_plugin(NativeExecutableSpec) {
167-
if (arch in ['x86_32', 'x86_64', 'arm32'])
168-
...
106+
protoc --version
169107
```
170108

171-
Around line 148, replace content inside of `protoc` section to hard code path to `protoc` binary:
109+
Now that we have the `protoc` compiler, we can start building Bazel. Let's move up a directory and do that.
172110

173111
```
174-
protoc {
175-
path = '/usr/bin/protoc'
176-
}
177-
```
178-
179-
Once all of that is taken care of, run this command to build gRPC:
180-
181-
```shell
182-
../gradlew java_pluginExecutable
112+
cd ..
183113
```
184114

185-
### 4. Build Bazel
115+
### 3. Build Bazel
186116

187-
First, move out of the `grpc-java/compiler` directory and clone Bazel's repository.
117+
To build [Bazel](https://github.com/bazelbuild/bazel), we're going to need to download a zip file containing a distribution archive. Let's do that now and extract it into a new directory called `bazel`:
188118

189119
```shell
190-
cd ../..
191-
git clone https://github.com/bazelbuild/bazel.git
120+
wget https://github.com/bazelbuild/bazel/releases/download/0.4.3/bazel-0.4.3-dist.zip
121+
unzip -d bazel bazel-0.4.3-dist.zip
192122
```
193123

194-
Next, go into the new `bazel` directory and immediately checkout version 0.3.1 of Bazel.
124+
Once it's done downloading and extracting, we can move into the directory to make a few changes:
195125

196126
```shell
197127
cd bazel
198-
git checkout 0.3.2
199-
```
200-
201-
After that, copy the generated Protobuf and gRPC files we created earlier into the Bazel project. Note the naming of the files in this step- it must be precise.
202-
203-
```shell
204-
sudo cp /usr/bin/protoc third_party/protobuf/protoc-linux-arm32.exe
205-
sudo cp ../protobuf/java/core/target/protobuf-java-3.0.0-beta-3.jar third_party/protobuf/protobuf-java-3.0.0-beta-1.jar
206-
sudo cp ../grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_32.exe
207128
```
208129

209130
Before building Bazel, we need to set the `javac` maximum heap size for this job, or else we'll get an OutOfMemoryError. To do this, we need to make a small addition to `bazel/scripts/bootstrap/compile.sh`. (Shout-out to @SangManLINUX for [pointing this out.](https://github.com/samjabrahams/tensorflow-on-raspberry-pi/issues/5#issuecomment-210965695).
@@ -212,36 +133,7 @@ Before building Bazel, we need to set the `javac` maximum heap size for this job
212133
nano scripts/bootstrap/compile.sh
213134
```
214135

215-
Around line 46, you'll find this code:
216-
217-
```shell
218-
if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
219-
PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_64.exe}
220-
GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_64.exe}
221-
else
222-
if [ "${MACHINE_IS_ARM}" = 'yes' ]; then
223-
PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-arm32.exe}
224-
else
225-
PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_32.exe}
226-
GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_32.exe}
227-
fi
228-
fi
229-
```
230-
231-
Change it to the following:
232-
233-
```shell
234-
if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
235-
PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-x86_64.exe}
236-
GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_64.exe}
237-
else
238-
PROTOC=${PROTOC:-third_party/protobuf/protoc-linux-arm32.exe}
239-
GRPC_JAVA_PLUGIN=${GRPC_JAVA_PLUGIN:-third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-linux-arm32.exe}
240-
fi
241-
```
242-
243-
244-
Move down to line 149, where you'll see the following block of code:
136+
Move down to line 137, where you'll see the following block of code:
245137

246138
```shell
247139
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
@@ -257,29 +149,13 @@ run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
257149
-encoding UTF-8 "@${paramfile}" -J-Xmx500M
258150
```
259151

260-
Next up, we need to adjust `third_party/protobuf/BUILD` - open it up in your text editor.
261-
262-
```
263-
nano third_party/protobuf/BUILD
264-
```
265-
266-
We need to add this last line around line 29:
267-
268-
```shell
269-
...
270-
"//third_party:freebsd": ["protoc-linux-x86_32.exe"],
271-
"//third_party:arm": ["protoc-linux-arm32.exe"],
272-
}),
273-
...
274-
```
275-
276152
Finally, we have to add one thing to `tools/cpp/cc_configure.bzl` - open it up for editing:
277153

278154
```shell
279155
nano tools/cpp/cc_configure.bzl
280156
```
281157

282-
And place this in around line 141 (at the beginning of the `_get_cpu_value` function):
158+
Place the line `return "arm"` around line 141 (at the beginning of the `_get_cpu_value` function):
283159

284160
```shell
285161
...
@@ -297,7 +173,6 @@ sudo ./compile.sh
297173
When the build finishes, you end up with a new binary, `output/bazel`. Copy that to your `/usr/local/bin` directory.
298174

299175
```shell
300-
sudo mkdir /usr/local/bin
301176
sudo cp output/bazel /usr/local/bin/bazel
302177
```
303178

@@ -341,7 +216,7 @@ Move out of the `bazel` directory, and we'll move onto the next step.
341216
cd ..
342217
```
343218

344-
### 5. Install a Memory Drive as Swap for Compiling
219+
### 4. Install a Memory Drive as Swap for Compiling
345220

346221
In order to succesfully build TensorFlow, your Raspberry Pi needs a little bit more memory to fall back on. Fortunately, this process is pretty straightforward. Grab a USB storage drive that has at least 1GB of memory. I used a flash drive I could live without that carried no important data. That said, we're only going to be using the drive as swap while we compile, so this process shouldn't do too much damage to a relatively new USB drive.
347222

@@ -402,7 +277,7 @@ sudo nano /etc/fstab
402277

403278
Alright! You've got swap! Don't throw out the `/dev/XXX` information yet- you'll need it to remove the device safely later on.
404279

405-
### 6. Compiling TensorFlow
280+
### 5. Compiling TensorFlow
406281

407282
First things first, clone the TensorFlow repository and move into the newly created directory.
408283

@@ -425,7 +300,7 @@ Next, we need to delete a particular line in `tensorflow/core/platform/platform.
425300
$ sudo nano tensorflow/core/platform/platform.h
426301
```
427302

428-
Now, scroll down toward the bottom and delete the following line containing `#define IS_MOBILE_PLATFORM`:
303+
Now, scroll down toward the bottom and delete the following line containing `#define IS_MOBILE_PLATFORM` (around line 48):
429304

430305
```cpp
431306
#elif defined(__arm__)
@@ -436,22 +311,26 @@ Now, scroll down toward the bottom and delete the following line containing `#de
436311
437312
This keeps our Raspberry Pi device (which has an ARM CPU) from being recognized as a mobile device.
438313
439-
Now let's configure Bazel:
314+
Now let's configure the build:
440315
441316
```shell
442317
$ ./configure
443318
444319
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python
445320
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
446321
Do you wish to build TensorFlow with GPU support? [y/N] N
447-
```
322+
Do you wish to build TensorFlow with Hadoop File System support? [y/N] N
323+
Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages]
324+
Do you wish to build TensorFlow with OpenCL support? [y/N] N
325+
Do you wish to build TensorFlow with GPU support? [y/N]
326+
N```
448327
449328
_Note: if you want to build for Python 3, specify `/usr/bin/python3` for Python's location._
450329
451330
Now we can use it to build TensorFlow! **Warning: This takes a really, really long time. Several hours.**
452331
453332
```shell
454-
bazel build -c opt --copt="-mfpu=neon-vfpv4" --copt="-funsafe-math-optimizations" --copt="-ftree-vectorize" --local_resources 1024,1.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package
333+
bazel build -c opt --copt="-mfpu=neon-vfpv4" --copt="-funsafe-math-optimizations" --copt="-ftree-vectorize" --copt="-fomit-frame-pointer" --local_resources 1024,1.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package
455334
```
456335

457336
_Note: I toyed around with telling Bazel to use all four cores in the Raspberry Pi, but that seemed to make compiling more prone to completely locking up. This process takes a long time regardless, so I'm sticking with the more reliable options here. If you want to be bold, try using `--local_resources 1024,2.0,1.0` or `--local_resources 1024,4.0,1.0`_
@@ -465,10 +344,10 @@ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
465344
And then install it!
466345
467346
```shell
468-
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.11-cp27-none-linux_armv7l.whl
347+
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.1-cp27-none-linux_armv7l.whl
469348
```
470349
471-
### 7. Cleaning Up
350+
### 6. Cleaning Up
472351
473352
There's one last bit of house-cleaning we need to do before we're done: remove the USB drive that we've been using as swap.
474353

@@ -490,7 +369,7 @@ Then reboot your Raspberry Pi.
490369

491370
## References
492371

493-
1. [Building TensorFlow for Jetson TK1](http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html)
372+
1. [Building TensorFlow for Jetson TK1](http://cudamusing.blogspot.com/2015/11/building-tensorflow-for-jetson-tk1.html) (an update to this post is available [here](http://cudamusing.blogspot.com/2016/06/tensorflow-08-on-jetson-tk1.html))
494373
2. [Turning a USB Drive into swap](http://askubuntu.com/questions/173676/how-to-make-a-usb-stick-swap-disk)
495374
3. [Safely removing USB swap space](http://askubuntu.com/questions/616437/is-it-safe-to-delete-a-swap-partition-on-a-usb-install)
496375

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Installing TensorFlow on Raspberry Pi 3 (and probably 2 as well)
22

3+
## Donate
4+
5+
If you find the binaries and instructions in this repository useful, [please consider donating to help keep this repository maintained](https://pledgie.com/campaigns/33260). It takes hours of work for each new version of TensorFlow, as well as responding to issues and pull requests.
6+
37
## Intro
48

59
_We did it!_ It took a lot of head-banging and several indirect passings-of-the-torch, but we finally got TensorFlow compiled and running properly on the Raspberry Pi! Hopefully this will enable more hardware-based machine learning projects, as well as making the distributed aspects of TensorFlow more accessible.
@@ -34,12 +38,12 @@ Next, download the wheel file from this repository and install it:
3438

3539
```shell
3640
# For Python 2.7
37-
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.11.0/tensorflow-0.11.0-cp27-none-linux_armv7l.whl
38-
$ sudo pip install tensorflow-0.11.0-cp27-none-linux_armv7l.whl
41+
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-cp27-none-linux_armv7l.whl
42+
$ sudo pip install tensorflow-0.12.1-cp27-none-linux_armv7l.whl
3943

4044
# For Python 3.3+
41-
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.11.0/tensorflow-0.11.0-py3-none-any.whl
42-
$ sudo pip3 install tensorflow-0.11.0-py3-none-any.whl
45+
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-py3-none-any.whl
46+
$ sudo pip3 install tensorflow-0.12.1-py3-none-any.whl
4347
```
4448

4549
And that should be it!
@@ -57,13 +61,13 @@ _This section will attempt to maintain a list of remedies for problems that may
5761
This wheel was built with Python 2.7, and can't be installed with a version of `pip` that uses Python 3. If you get the above message, try running the following command instead:
5862

5963
```
60-
$ sudo pip2 install tensorflow-0.11-cp27-none-linux_armv7l.whl
64+
$ sudo pip2 install tensorflow-0.12.1-cp27-none-linux_armv7l.whl
6165
```
6266

6367
Vice-versa for trying to install the Python 3 wheel. If you get the error "tensorflow-0.11-py3-none-any.whl is not a supported wheel on this platform.", try this command:
6468

6569
```
66-
$ sudo pip3 install tensorflow-0.11-py3-none-any.whl
70+
$ sudo pip3 install tensorflow-0.12.1-py3-none-any.whl
6771
```
6872

6973
## Building from Source

0 commit comments

Comments
 (0)