Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R1.0.1 #161

Open
wants to merge 8 commits into
base: 0.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 96 additions & 80 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ Here's the basic plan: build a 32-bit version of [Protobuf](https://github.com/g

1. [Install basic dependencies](#1-install-basic-dependencies)
2. [Build Protobuf](#2-build-protobuf)
3. [Build gRPC](#3-build-grpc)
3. [Build Bazel](#4-build-bazel)
4. [Install USB Memory as Swap](#5-install-a-memory-drive-as-swap-for-compiling)
5. [Compiling TensorFlow](#6-compiling-tensorflow)
6. [Cleaning Up](#7-cleaning-up)
3. [Install USB Memory as Swap](#3-install-a-memory-drive-as-swap-for-compiling)
4. [Build Bazel](#4-build-bazel)
5. [Compiling TensorFlow](#5-compiling-tensorflow)
6. [Cleaning Up](#6-cleaning-up)
7. [References](#references)

## The Build
Expand All @@ -50,19 +49,21 @@ sudo apt-get install autoconf automake libtool maven
For Bazel:

```shell
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip openjdk-8-jdk
# Select the java-8-openjdk option for the update-alternatives command
sudo update-alternatives --config java
```

For TensorFlow:

```
# For Python 2.7
sudo apt-get install python-pip python-numpy swig python-dev
sudo pip install wheel
pip install --user wheel

# For Python 3.3+
sudo apt-get install python3-pip python3-numpy swig python3-dev
sudo pip3 install wheel
pip3 install --user wheel
```

To be able to take advantage of certain optimization flags:
Expand Down Expand Up @@ -92,7 +93,7 @@ Now move into the new `protobuf` directory, configure it, and `make` it. _Note:

```shell
cd protobuf
git checkout v3.0.0
git checkout v3.1.0
./autogen.sh
./configure
make -j 4
Expand All @@ -106,13 +107,74 @@ Great! You should now have `protoc` installed in `/usr/local/bin`, and should be
protoc --version
```

Now that we have the `protoc` compiler, we can start building Bazel. Let's move up a directory and do that.
Now that we have the `protoc` compiler, let's install a USB stick as additional swap memory.

```
cd ..
```

### 3. Build Bazel
### 3. Install a Memory Drive as Swap for Compiling

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.

First, put insert your USB drive, and find the `/dev/XXX` path for the device.

```shell
sudo blkid
```

As an example, my drive's path was `/dev/sda1`

Once you've found your device, unmount it by using the `umount` command.

```shell
sudo umount /dev/XXX
```

Then format your device to be swap:

```shell
sudo mkswap /dev/XXX
```

If the previous command outputted an alphanumeric UUID, copy that now. Otherwise, find the UUID by running `blkid` again. Copy the UUID associated with `/dev/XXX`

```shell
sudo blkid
```

Now edit your `/etc/fstab` file to register your swap file. (I'm a Vim guy, but Nano is installed by default)

```shell
sudo nano /etc/fstab
```

On a separate line, enter the following information. Replace the X's with the UUID (without quotes)

```bash
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw,pri=5 0 0
```

Save `/etc/fstab`, exit your text editor, and run the following command:

```shell
sudo swapon -a
```

If you get an error claiming it can't find your UUID, go back and edit `/etc/fstab`. Replace the `UUID=XXX..` bit with the original `/dev/XXX` information.

```shell
sudo nano /etc/fstab
```

```bash
# Replace the UUID with /dev/XXX
/dev/XXX none swap sw,pri=5 0 0
```

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.

### 4. Build Bazel

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`:

Expand Down Expand Up @@ -155,7 +217,7 @@ Finally, we have to add one thing to `tools/cpp/cc_configure.bzl` - open it up f
nano tools/cpp/cc_configure.bzl
```

Place the line `return "arm"` around line 141 (at the beginning of the `_get_cpu_value` function):
Place the line `return "arm"` around line 133 (at the beginning of the `_get_cpu_value` function):

```shell
...
Expand All @@ -179,7 +241,7 @@ sudo cp output/bazel /usr/local/bin/bazel
To make sure it's working properly, run `bazel` on the command line and verify it prints help text. Note: this may take 15-30 seconds to run, so be patient!

```shell
$ bazel
bazel

Usage: bazel <command> <options> ...

Expand Down Expand Up @@ -216,73 +278,12 @@ Move out of the `bazel` directory, and we'll move onto the next step.
cd ..
```

### 4. Install a Memory Drive as Swap for Compiling

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.

First, put insert your USB drive, and find the `/dev/XXX` path for the device.

```shell
sudo blkid
```

As an example, my drive's path was `/dev/sda1`

Once you've found your device, unmount it by using the `umount` command.

```shell
sudo umount /dev/XXX
```

Then format your device to be swap:

```shell
sudo mkswap /dev/XXX
```

If the previous command outputted an alphanumeric UUID, copy that now. Otherwise, find the UUID by running `blkid` again. Copy the UUID associated with `/dev/XXX`

```shell
sudo blkid
```

Now edit your `/etc/fstab` file to register your swap file. (I'm a Vim guy, but Nano is installed by default)

```shell
sudo nano /etc/fstab
```

On a separate line, enter the following information. Replace the X's with the UUID (without quotes)

```bash
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw,pri=5 0 0
```

Save `/etc/fstab`, exit your text editor, and run the following command:

```shell
sudo swapon -a
```

If you get an error claiming it can't find your UUID, go back and edit `/etc/fstab`. Replace the `UUID=XXX..` bit with the original `/dev/XXX` information.

```shell
sudo nano /etc/fstab
```

```bash
# Replace the UUID with /dev/XXX
/dev/XXX none swap sw,pri=5 0 0
```

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.

### 5. Compiling TensorFlow

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

```shell
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
cd tensorflow
```

Expand All @@ -297,7 +298,7 @@ grep -Rl 'lib64' | xargs sed -i 's/lib64/lib/g'
Next, we need to delete a particular line in `tensorflow/core/platform/platform.h`. Open up the file in your favorite text editor:

```shell
$ sudo nano tensorflow/core/platform/platform.h
sudo nano tensorflow/core/platform/platform.h
```

Now, scroll down toward the bottom and delete the following line containing `#define IS_MOBILE_PLATFORM` (around line 48):
Expand All @@ -311,10 +312,25 @@ Now, scroll down toward the bottom and delete the following line containing `#de

This keeps our Raspberry Pi device (which has an ARM CPU) from being recognized as a mobile device.

Finally, we have to adjust the protocol to access the Numeric JS library- for some reason the Cloudflare security certificates don't work properly over `https`. We'll need to fix this in the Bazel `WORKSPACE` file:

```shell
sudo nano WORKSPACE
```

Around line 283, change `https` to `http`:

```
http_file(
name = "numericjs_numeric_min_js",
url = "http://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js",
)
```

Now let's configure the build:

```shell
$ ./configure
./configure

Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
Expand All @@ -323,9 +339,9 @@ Do you wish to build TensorFlow with Hadoop File System support? [y/N] N
Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages]
Do you wish to build TensorFlow with OpenCL support? [y/N] N
Do you wish to build TensorFlow with GPU support? [y/N]
N```
```

_Note: if you want to build for Python 3, specify `/usr/bin/python3` for Python's location._
_Note: if you want to build for Python 3, specify `/usr/bin/python3` for Python's location and `/usr/local/lib/python3.4/dist-packages` for the Python library path._

Now we can use it to build TensorFlow! **Warning: This takes a really, really long time. Several hours.**

Expand All @@ -344,7 +360,7 @@ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
And then install it!

```shell
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.1-cp27-none-linux_armv7l.whl
pip install --user /tmp/tensorflow_pkg/tensorflow-1.0.1-cp27-none-linux_armv7l.whl
```

### 6. Cleaning Up
Expand Down
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Donate

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.
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 to compile each new version of TensorFlow, in addition to time spent responding to issues and pull requests.

## Intro

Expand All @@ -25,25 +25,37 @@ This is the easiest way to get TensorFlow onto your Raspberry Pi 3. Note that cu
First, install the dependencies for TensorFlow:

```shell
$ sudo apt-get update
sudo apt-get update

# For Python 2.7
$ sudo apt-get install python-pip python-dev
sudo apt-get install python-pip python-dev

# For Python 3.3+
$ sudo apt-get install python3-pip python3-dev
sudo apt-get install python3-pip python3-dev
```

Next, download the wheel file from this repository and install it:

```shell
# For Python 2.7
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-cp27-none-linux_armv7l.whl
$ sudo pip install tensorflow-0.12.1-cp27-none-linux_armv7l.whl
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.0.1/tensorflow-1.0.1-cp27-none-linux_armv7l.whl
pip install --user tensorflow-1.0.1-cp27-none-linux_armv7l.whl

# For Python 3.4
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.0.1/tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl
pip3 install --user tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl
```

Finally, we need to reinstall the `mock` library to keep it from throwing an error when we import TensorFlow:

```shell
# For Python 2.7
pip uninstall mock
pip install --user mock

# For Python 3.3+
$ wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-py3-none-any.whl
$ sudo pip3 install tensorflow-0.12.1-py3-none-any.whl
pip3 uninstall mock
pip3 install --user mock
```

And that should be it!
Expand All @@ -56,20 +68,22 @@ Instructions on setting up a Docker image to run on Raspberry Pi are being maint

_This section will attempt to maintain a list of remedies for problems that may occur while installing from `pip`_

#### "tensorflow-0.11-cp27-none-linux_armv7l.whl is not a supported wheel on this platform."
#### "tensorflow-1.0.1-cp27-none-linux_armv7l.whl is not a supported wheel on this platform."

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:

```
$ sudo pip2 install tensorflow-0.12.1-cp27-none-linux_armv7l.whl
sudo pip2 install tensorflow-1.0.1-cp27-none-linux_armv7l.whl
```

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:
Vice-versa for trying to install the Python 3 wheel. If you get the error "tensorflow-1.0.1-cp34-cp34m-any.whl is not a supported wheel on this platform.", try this command:

```
$ sudo pip3 install tensorflow-0.12.1-py3-none-any.whl
pip3 install --user tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl
```

**Note: the provided binaries are for Python 2.7 and 3.4 _only_. If you've installed Python 3.5/3.6 from source on your machine, you'll need to either explicitly install these wheels for 3.4, or you'll need to build TensorFlow [from source](GUIDE.md). Once there's an officially supported installation of Python 3.5+, this repo will start including wheels for those versions.**

## Building from Source

[_Step-by-step guide_](GUIDE.md)
Expand Down
Loading