Skip to content

tf setup

Tobias Kind edited this page Jan 21, 2018 · 37 revisions

Installing tensorflow looks relatively straightforward (easy), similar to "how to build your own space shuttle". The TensorFlow tutorial website provides detailed setup instructions. TensorFlow can use CPU and GPU (graphic card streaming processors). But wait a minute! Where is Windows, where is OpenCL support? Well, after much feedback from the community starting 2015, both missing support topics landed on the TF roadmap and much has been done since. As of 2017 Windows is now supported and OpenCL is in the making. TF is also included in the exceptional Keras high-level neural network and machine learning API.


WINDOWS installation

Tensorflow is now available under Windows even with CUDA support. Currently TF requires python version 3.5 under Windows. See more here TF Windows. That was not always the case. TensorFlow was originally not available under Windows. There were only virtual machine options. Or this docker hack. Well its not rally a hack it just installs a docker linux VM and proceeds from there. The problem with using VMs is that no CUDA or OPENCL driver is available (yet) that can pass native GPU instructions through the VM layer. That means tensorflow with GPU option will compile, but will not be able to use the GPU in an virtual machine (VM).

Recommended installation of native tensorflow using NVIDIA CUDA under Windows:

  1. Follow instructions using pip/Ananconda here

Recommended installation of tensorflow in a VM under WINDOWS:

  1. Download the free VirtualBox or use VMWare

  2. Then download the UBUNTU ISO disk and

  3. Proceed to use the Linux installation options.


TensorFlow with Docker installation Ubuntu LTE

Many packages can fail, will fail. TF is no exception, with a large number of dependencies and libraries it surely will fail. Using docker visualization is probably the safest way to play around with TF. Docker should work under all OS. I use Ubuntu for brevity, but CentOS or El Capitan should work too.

  1. Install docker (OS and version dependent and quite complicated)
    http://docs.docker.com/engine/installation/ubuntulinux/

  2. Install the full tensorflow docker image

sudo docker run -it b.gcr.io/tensorflow/tensorflow-full
ubuntu@ubuntu-virtual-machine:~$ sudo docker run -it b.gcr.io/tensorflow/tensorflow-full
Unable to find image 'b.gcr.io/tensorflow/tensorflow-full:latest' locally
latest: Pulling from tensorflow/tensorflow-full
c2360ebde114: Pull complete 
7ec3c49697a3: Pull complete 
786647746054: Pull complete 
99290d26b5eb: Pull complete 
2d5f8fd5f439: Pull complete 
024084c8fcec: Pull complete 
d1cea0cd4f37: Pull complete 
1041a88b5eae: Pull complete 
8143b28e5a79: Pull complete 
760322cf243f: Pull complete 
3c42ba122558: Pull complete 
88fc44323a9a: Pull complete 
edc3d721078b: Pull complete 
Digest: sha256:82c4f725adad2196877dfe70d849024ec6e3940081a05a0555cee99c9b213b2d
Status: Downloaded newer image for b.gcr.io/tensorflow/tensorflow-full:latest
root@b09faa80dc37:~# 

Alltough the image can be started and ready, the mandelbrot example can not be run, hence the docker image failed. Next steps would be the commands below to built everything (source). The tensorflow-full requires a complete built first command is from the tf documentation the second one from an error fix.

git clone https://github.com/tensorflow/tensorflow
sudo docker build -t $USER/tensorflow-full -f tensorflow/tensorflow/tools/docker/Dockerfile.cpu .

or if code building fails use --recurse-submodules

$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
$ sudo docker build -t $USER/tensorflow-full -f tensorflow/tensorflow/tools/docker/Dockerfile.cpu .

After the TensorFlow docker image of is installed you can check the size in /var/lib/docker. It will be probably around 2 Gbyte and ten instances/folders of TF are covered (no idea why). Also depending on random changes in UBUNTU you may have to modify the storage driver (source).

sudo nano /var/lib/docker
# Force OverlayFS for storage driver
DOCKER_OPTS="$DOCKER_OPTS -s overlay"

TensorFlow LINUX and UBUNTU installation // CPU only

This installation setup works for UBUNTU. I tried CentOS but failed with yum, not sure why. Anyway, UBUNTU works fine. It is important to use the older Python 2.7 or 3.3+ but not Python 3.4 or others. Also if the PIP package manager is not installed yet it needs to be downloaded and installed. The installation requires root or sudo.

# Google tensorflow installation for UBUNTU 13 
# requires python 2.7
 
# Make directory tensorflow
mkdir tensorflow

# Change to directory tensorflow
cd tensorflow

# Download and save https://bootstrap.pypa.io/get-pip.py
wget https://bootstrap.pypa.io/get-pip.py

# call python version 2.7 (important) and install get-pip.py using sudo (root access)
sudo python2.7 get-pip.py

# now install the latest tensorflow, make sure to update the version numbers
sudo python2.7 -m pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

# call python (make sure its 2.7 for tensorflow v 0.5)
python

Then you can copy/paste your first tensorflow program into python:

# Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
# [GCC 4.8.1] on linux2
# >>>

# Hello World in TensorFlow
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print sess.run(hello)
# END

TensorFlow and Anaconda Python in Ubuntu

The native 2.7 Python version misses many packages, a number of packages are also required by tensorflow, otherwise errors occour. Using the Anaconda Python distribution over 300 additional packages are installed. Source

1) Download anaconda Python 2.7 from https://www.continuum.io/downloads
2) bash Anaconda2-2.4.0-Linux-x86_64.sh
# answer yes to license and yes to adding anaconda to the .bashrc configuration file
3) conda install -c https://conda.anaconda.org/jjhelmus tensorflow
# be aware that future tensorflow updates are not captured with that (yet)
4) call python and test hello-tensorflow.py

Also be aware that the tensorflow package is now part of anaconda packages and libraries and potentially other directories such as /anaconda2/pkgs/tensorflow-0.5.0-py27_2/lib/python2.7/site-packages/tensorflow/. Some of the tensorflow binaries were directly copied to /anaconda2/bin

ubuntu14@ubuntu14-VirtualBox:~/anaconda2/bin$ ls -l ten*
-rwxr-xr-x 1 tensorboard
-rwxr-xr-x 1 tensorflow_model_cifar10_eval
-rwxr-xr-x 1 tensorflow_model_cifar10_multi_gpu_train
-rwxr-xr-x 1 tensorflow_model_cifar10_train
-rwxr-xr-x 1 tensorflow_model_mnist_convolutional

TensorFlow and Python virtualenv Ubuntu

The virtualenv is a package to create virtual python environments. This package will solve some issues with TensorFlow, such as missing image display in tensorboard, but not all issues.


# Install pyton virtual environment
sudo apt-get install python-pip python-dev python-virtualenv
virtualenv --system-site-packages ~/tensorflow
cd ~/tensorflow

# Now create pyhton virtual environment 
source bin/activate

# Now install tensorflow itself CPU only 
# This will install tensorflow to ~/tensorflow/lib/python2.7/site-packages/tensorflow/
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

# install additional libraries (outside libs maybe used)
pip install scipy[all]
pip install ipython[all]

# call an example program
wget https://raw.githubusercontent.com/tobigithub/tensorflow-deep-learning/master/examples/hello-tensorflow.py
python hello-tensorflow.py

# Deactivate the virtualenv
deactivate  

MacOSX installation

That works, I have seen it.

# Only CPU-version is available at the moment.
$ pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

CentOS installation

Read here: http://www.cnblogs.com/ahauzyy/p/4957520.html


Other issues

Currently (Nov 2015) tensorflow depends on Python 2.7 and Bazel (make environment from Google) and pip (python package manager tool) and CUDA (NVIDIA GPU library). That means platforms that utilized Python 3.1 or OSs that have no binaries for Bazel or computers with AMD GPUs are doomed. In principle.

As of August 2016 TensorFlow also supports Python 3.3. The installation procedures can be found here: [https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html]

Also some of the required python packages are not installed by default or by the setups mentioned above. Here docker may help. The cifar10 and MNist examples probably run fine, others may fail. None of the above solutions is fail-safe. What is missing? A working VM image probably.


LINKS

tf install - TensorFlow installation instructions from Google.

TF EC2 install - TensorFlow installation on a Amazon EC2 instance.

TF EC2 install2 - TensorFlow installation on a Amazon PV EBS-Backed 64-bit EC2 instance quick example

TF GPU install - tensorflow GPU install on UBUNTU