Setup TensorFlow on DigitalOcean for Shiny server

TensorFlow’s official website presented different ways to install TensorFlow. I tried the pip install, and after several times fail, finially I can pass the test your installation. However, when I try to run the tutorial of Image Recognition, I can’t find the imagenet directory under models/image. After searching for a while, I got the words: Most of the example sources are no longer in the pip package …. So, I decided to install it from source (github).

Step 1: install pip.

When installing from source you will build a pip wheel that you then install using pip.

sudo apt-get install python-pip python-dev

Step 2: Clone TensorFlow repository

git clone --recurse-submodules

Step 3: Install Bazel

  • Install JDK 8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

If encount error message: GPG error: trusty/ Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9 when running sudo apt-get update, run the following command to replace the key with the one that is displayed in the error message (more).

sudo apt-key adv --keyserver --recv-keys 51716619E084DAB9
  • Install required packages
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip
  • Install Bazel
chmod +x
./ --user
export PATH="$PATH:$HOME/bin"

Step 4: Install other dependencies and configure the installation

sudo apt-get install python-numpy swig python-dev

cd tensorflow

Test the installation

Navigate to directory imagenet under tensorflow.

cd tensorflow/tensorflow/models/image/imagenet/

There is a Python script called “”, which is used to recoganize image. Run the following command:

sudo python

If you can see message, like:

giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89233) indri, indris, Indri indri, Indri brevicaudatus (score = 0.00859) lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00264) custard apple (score = 0.00141) earthstar (score = 0.00107)

You have completed the installation!

A shiny-app was created according to the codes of Yuki Katoh.

Written on March 3, 2016