Skip to content

Rebuilding library from scratch (for advanced users)

Memo Akten edited this page May 20, 2017 · 24 revisions

If you'd like to upgrade the addon's tensorflow to a new version, or rebuild the library for a new platform (e.g. debug vs release, GPU vs CPU etc) then follow the instructions below.

This has been tested on Ubuntu 16.04 and OSX 10.12.3, but should work on other *nix and OSX. Apparently Bazel on Windows is currently experimental.

Get the tensorflow source

Follow instructions at https://www.tensorflow.org/install/install_sources until the build command. i.e.:

  1. install dependencies (including Bazel)
  2. clone tensorflow repo. use my tensorflow repo as I have a modified bazel BUILD file
  3. [OPTIONAL] checkout a specific tensorflow src branch (e.g. r1.0)
  4. [OPTIONAL] setup GPU stuff (CUDA, cuDNN)
  5. run configure

Build the libtensorflow_cc.so library

You do not need to build or install the pip package (unless you want to for some reason). Instead, build the libtensorflow_cc target:

# for CPU only optimised (release) lib
bazel build --config=opt //tensorflow:libtensorflow_cc.so
# for GPU optimised (release) lib (make sure you've followed CUDA/cuDNN setup instructions and run configure accordingly)
bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so
# for debug lib
bazel build //tensorflow:libtensorflow_cc.so

This will build a libtensorflow_cc.so file in [your_tensorflow_src_path]/bazel-bin/tensorflow

On OSX the lib will contain a machine specific id. To clean it, run install_name_tool -id <in_path> <out_path>. See issue #14.

Copy library and set search path

Copy the libtensorflow.so to the relevant folders and update library search path (same step as in Getting Started)

Copy Tensorflow Headers

If you are upgrading to a new version of tensorflow, there might be new tensorflow headers (you'll realise this is the case if you get compiler errors referencing missing tensorflow headers). If this is the case, you'll need to copy all of the tensorflow headers to the correct folders in ofxMSATensorFlow/libs/tensorflow/include. I wrote a script that does this in ofxMSATensorFlow/scripts/copy_headers.sh. Note, if the new version of tensorflow has radically different folder structure, then this script might give errors. It is quite human-readable so feel free to edit.

Copy Protobuf headers

If you are upgrading to a new version of tensorflow which requires a new version of protobuf, there might be new protobuf headers (you'll realise this is the case if you get compiler errors referencing missing or out of date protobuf headers). If this is the case, you'll need to copy the required protobuf headers to ofxMSATensorFlow/libs/google/include/google/protobuf

  1. Download the specific version of protobuf required from https://github.com/google/protobuf/releases
  2. Install as explained at https://github.com/google/protobuf/tree/master/src
  3. Copy the installed header files from /usr/local/include/google/protobuf (or wherever you installed it) to ofxMSATensorFlow/libs/google/include/google/protobuf