Skip to content

Instantly share code, notes, and snippets.

@meikuam
Last active June 5, 2020 11:30
Show Gist options
  • Save meikuam/aee59b6911e3dc7eab06388255c88e34 to your computer and use it in GitHub Desktop.
Save meikuam/aee59b6911e3dc7eab06388255c88e34 to your computer and use it in GitHub Desktop.
tensorflow 2.2.0 compile
# build tensorflow2.2.0
sudo apt-get install -y \
protobuf-compiler python3-pil python3-lxml python3-tk cython \
autoconf automake libtool curl make g++ unzip wget git \
libgflags-dev libgoogle-glog-dev liblmdb-dev libleveldb-dev \
libhdf5-serial-dev libhdf5-dev python3-opencv\
python3-dev python3-numpy python3-skimage gfortran libturbojpeg \
libboost-all-dev libopenblas-dev libsnappy-dev software-properties-common \
libfreetype6-dev pkg-config \
libpng-dev libhdf5-103 libhdf5-cpp-103 libc-ares-dev libblas-dev \
libeigen3-dev libatlas-base-dev openjdk-8-jdk libopenblas-base \
openmpi-bin libopenmpi-dev gcc libgfortran5 libatlas3-base liblapack-dev
python3 -m pip install pip --upgrade
python3 -m pip install Cython contextlib2 pillow lxml jupyter matplotlib keras_applications --no-deps keras_preprocessing --no-deps h5py &six numpy wheel mock pybind11
sudo mkdir -p /tensorrt && \
cd /tensorrt
work_dir=/tensorrt
git clone -b v2.2.0 --depth 1 https://github.com/tensorflow/tensorflow.git && \
wget https://github.com/bazelbuild/bazel/releases/download/2.0.0/bazel-2.0.0-installer-linux-x86_64.sh && \
chmod +x bazel-2.0.0-installer-linux-x86_64.sh
sudo ./bazel-2.0.0-installer-linux-x86_64.sh
# as tensorrt support only python3.6, we can't build with it
# # you should download tensorrt from:
# # https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
# sudo dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
# sudo apt-key add /var/nv-tensorrt-repo-cuda10.2-trt7.0.0.11-ga-20191216/7fa2af80.pub
# sudo apt update
# sudo apt install tensorrt
# sudo apt-get install uff-converter-tf
# wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/python3-libnvinfer_7.0.0-1+cuda10.2_amd64.deb
# wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/python3-libnvinfer-dev_7.0.0-1+cuda10.2_amd64.deb
# sudo dpkg -i python3-libnvinfer_7.0.0-1+cuda10.2_amd64.deb
# sudo dpkg -i python3-libnvinfer-dev_7.0.0-1+cuda10.2_amd64.deb
# sudo apt install \
# python3-libnvinfer \
# python3-libnvinfer-dev
PATH=/usr/local/cuda-10.2/bin:$PATH \
LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH \
TF_CUDA_VERSION=10.2 \
TF_CUDNN_VERSION=7
bazel version
cd tensorflow
./configure
bazel build \
--config=opt \
--config=cuda \
--config=v2 \
--local_resources=16000.0,12.0,1.0 \
--host_force_python=PY3 \
--noincompatible_do_not_split_linking_cmdline \
//tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
cp /tmp/tensorflow_pkg/tensorflow-2.2.0-cp37-cp37m-linux_x86_64.whl /tensort
cd ..
ls -l
pip3 uninstall tensorflow-gpu tensorflow
pip3 install tensorflow-2.2.0-cp37-cp37m-linux_x86_64.whl
#check
# >>> import tensorflow as tf
# >>> from tensorflow.python.client import device_lib
# >>> device_lib.list_local_devices()
# link to whl:
# https://drive.google.com/open?id=1PGisZ9fvpg777zkGFQA5O33_lF1bgAS7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment