Skip to content

Instantly share code, notes, and snippets.

@tractatus
Last active June 18, 2021 23:15
Show Gist options
  • Save tractatus/1d422077c5c312bd0306fd616ba28ee5 to your computer and use it in GitHub Desktop.
Save tractatus/1d422077c5c312bd0306fd616ba28ee5 to your computer and use it in GitHub Desktop.
Speed-up by compiling TensorFlow from source?

Why compiling from source?

The most straigtforward way install TensorFlow is to work in a virtual Python environment and simply to use either the TensorFlow official packages in pip or a wheel (.whl) distribution.

Problems arise at some point when a lot of heavy image processing needs to be done.

Since prediction/inference primarly involves the CPU we might correctly ask ourselves:

Instead of precompiled binaries, that are not optimized for our set of CPU architecture extensions, what would be the speed gain if we would compile TensorFlow from source?

Why this blog post?

There are a lot of blog posts on the benefits of compiling Tensorflow from source however a lot of the benchmarks shown might not be really applicable to the day to day activities of biologist/microscopist.

In this post I will use StarDist's 3D prediction using a network trained to segment rolling circle amplification products for in situ sequencing.

Since a lot of microscope core facility computers tend to use softwares primarily running on Windows (Imaris etc.) I will compile on Microsoft Windows, which is a mess in itself if you come more from the *nix side of things.

Prerequisites

This guide roughly follows the official tutorial, Ive only added some comments that will save time: https://www.tensorflow.org/install/source_windows

Install Python3: https://www.python.org/downloads/windows/

Windows doesnt come with a C/C++ compiler so we need to install that first.

Install Build Tools for Visual Studio: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

Install C++ Redistributable for Visual Studio 2019: https://visualstudio.microsoft.com/downloads/#microsoft-visual-c-redistributable-for-visual-studio-2019

Install Git: https://git-scm.com/

Download the TensorFlow github repo:

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment