Shurn the Awesomer
Tutorial: Setting up Tensorflow in Ubuntu 16.04

Tutorial: Setting up Tensorflow in Ubuntu 16.04

Written on Mon, 27 June 2016

So these days I'm just learning up on Machine Learning. Quite a fascinating subject. But I'm no data scientist (yet!) so it's quite daunting what Machine Learning is capable of.

Today's tutorial will just be about setting up TensorFlow on your Ubuntu machine. I won't go in depth about machine learning algorithm or help you build a Terminator T-5000, for obvious reasons.

In my machine build, I do not have a Graphic Card, so I won't be touching on graphic card related configuration. But I sure don't mind you sponsoring me a Quadro M6000. I'm also using 64bit computer. Seriously, why would you have a 32bit computer to run Machine Learning?

Step 1: Installing Python3


There's no reason to use a distribution no longer receiving upgrades. Python2 will still be maintained but why not use the one built for the future? Let's install Python3.

apt-get install python3-pip python3-dev

Step 2: Installing Tensorflow

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp35-cp35m-linux_x86_64.whl
pip3 install --upgrade $TF_BINARY_URL

This will take some time. Go make yourself some coffee!

Step3: Testing your installation


Let's execute python to make sure your installation works.

python3
>>>import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
Hello, TensorFlow!
>>>a = tf.constant(10)
>>>b = tf.constant(32)
>>>print(sess.run(a + b))
42
>>>exit()

Step 4: Run your first Tensorflow Model


Tensor is nothing if you don't run any machine learning. Let's run your first Tensorflow Model.

cd /usr/local/lib/python3.5/dist-packages/tensorflow
python3 -m tensorflow.models.image.mnist.convolutional

Congratulations! You have run your first Machine Learning model. This model will take quite awhile to complete. Took me more than 40 minutes on my slow machine without GPU. If you have a GPU installed, I'm sure it will be a whole load faster.