Installing TensorFlow

Instructions adapted from here, I chose the virtualenv: https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html#optional-install-cuda-gpus-on-linux

# Ubuntu/Linux 64-bit
$ sudo apt-get install python-pip python-dev python-virtualenv

$ virtualenv --system-site-packages ~/tensorflow

Activate the environment:

$ source ~/tensorflow/bin/activate  # If using bash
$ source ~/tensorflow/bin/activate.csh  # If using csh
(tensorflow)$  # Your prompt should change
$ sudo apt-get install  git
$ sudo apt-get install python-numpy python-dev python-wheel

cd ~/tensorflow

 git clone https://github.com/tensorflow/tensorflow
sudo apt-get update

To build TensorFlow, you’ll need to install Bazel

Install Bazel

Follow instructions here to install the dependencies for bazel. Then download the latest stable bazel version using the installer for your system and run the installer as mentioned there:

$ chmod +x PATH_TO_INSTALL.SH
$ ./PATH_TO_INSTALL.SH --user

Remember to replace PATH_TO_INSTALL.SH with the location where you downloaded the installer.

Finally, follow the instructions in that script to place bazel into your binary path.

1. Install JDK 8

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

Note: You might need to sudo apt-get install software-properties-common if you don’t have the add-apt-repositorycommand. See here.

2. Add Bazel distribution URI as a package source (one time setup)

$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -

3. Update and install Bazel

$ sudo apt-get update && sudo apt-get install bazel

Once installed, you can upgrade to newer version of Bazel with:

$ sudo apt-get upgrade bazel

Are these next steps necessary ? (Bael seems to have been insatalled above)

Get the bazel installer from here:  https://github.com/bazelbuild/bazel/releases/download/0.4.1/bazel-0.4.1-installer-linux-x86_64.sh

$ chmod +x PATH_TO_INSTALL.SH
$ ./PATH_TO_INSTALL.SH --user

Remember to replace PATH_TO_INSTALL.SH with the location where you downloaded the installer.

Finally, follow the instructions in that script to place bazel into your binary path.

Bazel is now installed!

Make sure you have “/home/taufiq/bin” in your path. You can also activate bash
completion by adding the following line to your ~/.bashrc:
source /home/taufiq/.bazel/bin/bazel-complete.bash

Then:

$ cd 
$ source .bashrc

Check by running bazel to get the usage:

$ bazel

Configure TensorFlow

$ cd tensorflow/tensorflow/    #since ite a virtualenv
~/tensorflow/tensorflow$ ./configure
~/tensorflow/tensorflow ~/tensorflow/tensorflow
Please specify the location of python. [Default is /home/taufiq/tensorflow/bin/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N]
No Hadoop File System support will be enabled for TensorFlow
Found possible Python library paths:
/home/taufiq/tensorflow/lib/python2.7/site-packages
Please input the desired Python library path to use. Default is [/home/taufiq/tensorflow/lib/python2.7/site-packages]Using python library path: /home/taufiq/tensorflow/lib/python2.7/site-packages
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] Y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 7.5
Please specify the location where CUDA 7.5 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5
Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: “3.5,5.2”]: 3.5,5.2,6.1       (replace 6.1 with your compute capability)
…….
INFO: Starting clean (this may take a while). Consider using –expunge_async if the clean takes more than several minutes.
…….
INFO: Downloading from http://github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 0B

Build TensorFlow

# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

# The name of the .whl file will depend on your platform.
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.0rc0-py2-none-any.whl


If you have a version of CUDA which does not support your hardware:
nvcc fatal : Unsupported gpu architecture 'compute_61'

To print version of TF:
python -c 'import tensorflow as tf; print(tf.__version__)'
0.12.0-rc0

 

Leave a comment