Skip to content

Installation

Grigori Fursin edited this page Aug 30, 2018 · 8 revisions

Here we describe how to customize builds of TensorFlow via Collective Knowledge workflow framework

Table of Contents

Building from sources

Prerequisites: Ubuntu

  • Python 2.x:
$ sudo apt-get install python-dev python-pip python-setuptools python-opencv git
$ sudo pip --upgrade install pip
$ sudo pip install protobuf easydict joblib image 
$ sudo pip install ck
  • Python 3.x:
$ sudo apt-get install python3-dev python3-pip python3-setuptools
$ sudo pip3 --upgrade install pip
$ sudo pip3 install wheel protobuf easydict joblib image
$ sudo pip3 install ck
  • Java:
$ sudo apt install openjdk-8-jdk-headless
    • NB:** Installation fails with `openjdk-9-jdk-headless` (cf. this.
  • CUDA, cuDNN (GPU version only)
If you want to use the GPU, please install CUDA toolkit >= v7.0 and cuDNN >= v2. If you want to use the GPU and pip, please install CUDA toolkit >= v8.0 and cuDNN >= v5.

- Check if you have a CUDA-enabled GPU.

- Download and install CUDA.

- Download and install cuDNN (requires registration).

- More detailed instructions.

Preparing CK-TensorFlow repo (any OS)

You can install CK-TensorFlow repository as follows:

$ ck pull repo:ck-tensorflow

Installing TensorFlow on your host (Linux, Windows) via CK

You should now be ready to install the CPU version of CK-TensorFlow (CK will automatically download and install Bazel and JDK if they are not already installed):

$ ck install package:lib-tensorflow-cpu

You can also install the CUDA version of TensorFlow (which when installed via CK can co-exist with the CPU version):

$ ck install package:lib-tensorflow-cuda

Finally, you can try to install the OpenCL version of TensorFlow (which requires ComputeCPP; unfortunately, at the time of this writing we were not able to run it):

$ ck install package:lib-tensorflow-opencl

Preparing TensorFlow for Android devices

  • for ARM64-based platforms (should be connected to your host via adb):
$ ck install package:lib-tensorflow-cpu-make --target_os=android21-arm64
$ ck compile program:tensorflow-classification-cpu --target_os=android21-arm64
$ ck run program:tensorflow-classification-cpu --target_os=android21-arm64
  • for ARM32-based platforms:
$ ck install package:lib-tensorflow-cpu-make --target_os=android21-arm-v7a
$ ck compile program:tensorflow-classification-cpu --target_os=android21-arm-v7a --env.OPTFLAGS="-O2 -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
$ ck run program:tensorflow-classification-cpu --target_os=android21-arm-v7a

Note, that you can build and run TensorFlow on older Android 4.2+ devices - just substitute "android21-arm-v7a" with "android19-arm-v7a" above.

Above method is used to prepare CK-based crowd-scenarios for our Android app to crowdsource deep learning optimization!

Preparing TensorFlow via CK for constrained devices (Raspberry Pi, odroid)

You can install tensorflow for devices with constrained resources using Makefile via CK as follows (particularly if GCC fails with a memory corruption error):

$ ck install package:lib-tensorflow-cpu-make --env.OPTFLAGS="-O2"

or

$ ck install package:lib-tensorflow-cpu-make --env.OPTFLAGS="-O1"

You can then compile and run C++ classification example as follows:

$ ck compile program:tensorflow-classification-cpu
$ ck run program:tensorflow-classification-cpu

Troubleshooting

TensorFlow installation may occasionally fail due to failing to download some dependencies from GitHub. Restart package installation several times until Bazel downloads all necessary files.

Sometimes, after installation, TensorFlow crashes with undefined "syntax". It is usually related to outdated default protobuf (you need version >=3.0.0a4). To fix this problem upgrade protobuf via

 $ sudo pip install protobuf --upgrade
  or
 $ sudo pip3 install protobuf --upgrade

It may also fail with the following message "can't combine user with prefix, exec_prefix/home, or install_(plat)base". The following fix may help:

 $ sudo pip install --upgrade pip"

If you are installing TF on Raspberry Pi and encountered build errors in which the compiler is being killed, it is likely that the compiler is running out of memory (especially if you are on Raspberry Pi 1, 2 or Zero, which have less than 1GB of RAM), this can often be rectified by increasing the swapfile size on the Pi by editing the file /etc/dphys-swapfile and changing the line CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024, then running:

 sudo vim /etc/dphys-swapfile

 sudo /etc/init.d/dphys-swapfile stop
 sudo /etc/init.d/dphys-swapfile start