Oct 11, 2018

Compile tensorflow and opencv from source

Tensorflow

sudo apt install python3-dev python3-pip
pip install -U pip six numpy wheel mock
pip install -U keras_applications==1.0.5 keras_preprocessing==1.0.3 --no-deps

./configure  # see 'View sample configuration session' here https://www.tensorflow.org/install/source
bazel build --config=opt --config=cuda --config=mkl --config=monolithic //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl

cuDNN

Instructions here: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

Bazel

Follow instructions: https://docs.bazel.build/versions/master/install-ubuntu.html#using-bazel-custom-apt-repository
Download from https://github.com/bazelbuild/bazel/releases
Be sure Java installed

# Bazel 18.1 for TF r1.12 
# Details why so: https://github.com/tensorflow/tensorflow/issues/23401

chmod +x bazel--installer-linux-x86_64.sh
./bazel--installer-linux-x86_64.sh --user

# add:
# export PATH="$PATH:$HOME/bin"
# to ~/.bashrc

git clone https://github.com/tensorflow/tensorflow
git checkout r1.12
https://www.tensorflow.org/install/source

Opencv

https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

ln -s /usr/local/lib/python3.6/site-packages/cv2.so cv2.so
cp -r ~/anaconda3/envs/opencv_build/lib/python3.6/site-packages/cv2/ ~/anaconda3/envs/tf_build/lib/python3.6/site-packages/