---------------------
required packages
---------------------
// install pip3 in /usr/bin/
$ sudo apt install python3-dev python3-pip
// install packages in ~/.local/lib/python3.6/site-packages/
// pip 19.3.1 is installed in here too.
// This pip is used from now on.
$ which pip
/home/soh/.local/bin/pip
$ pip3 install -U --user pip six numpy wheel setuptools mock 'future>=0.17.1'
$ pip install -U --user keras_applications==1.0.6 --no-deps
$ pip install -U --user keras_preprocessing==1.0.5 --no-deps
---------------------------------------------------------------
bazel: NOTE: version is important 0.26.1 or lower needed.
---------------------------------------------------------------
// according to the tensorflow doc, 0.29.1 is max. but configure complains.
$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3
// download bazel-0.26.1-installer-linux-x86_64.sh from https://github.com/bazelbuild/bazel/releases
$ chmod +x bazel-0.26.1-installer-linux-x86_64.sh
$ ./bazel-0.26.1-installer-linux-x86_64.sh --user
// bazel is installed in ~/bin/
$ export PATH="$PATH:$HOME/bin"
// actually, already in .profile
------------------------------------------
GPU support: nvidia drivers, etc.
------------------------------------------
// follow the guildes in https://www.tensorflow.org/install/gpu
// OR
// nvidia driver is already installed with .run file: 430.50
// cuda toolkit 10.1: Installer Type: deb(network)
$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
$ sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
$ sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
$ sudo apt-get update
$ sudo apt-get -y install cuda
// cuDNN: download "cuDNN vX.X Library for Linux" or 3 .deb files for Ubuntu 18.04
$ sudo dpkg -i ~/tmp/libcudnn7_7.6.4.38-1+cuda10.1_amd64.deb
$ sudo dpkg -i ~/tmp/libcudnn7-dev_7.6.4.38-1+cuda10.1_amd64.deb
$ sudo dpkg -i ~/tmp/libcudnn7-doc_7.6.4.38-1+cuda10.1_amd64.deb
$ vi .bashrc
export CUDA_HOME="/usr/local/cuda"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${CUDA_HOME}/lib64:/usr/local/cuda/extras/CUPTI/lib64"
// cupti is installed with CUDA toolkit
$ vi .profile
if [ -d "/usr/local/cuda/bin" ] ; then
PATH="/usr/local/cuda/bin:$PATH"
fi
$ source .profile
// .bashrc is included in .profile currently
---------------------
Tensorflow 1.x
---------------------
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ git checkout r1.15
$ ./configure
// python3 instead of python
// default values except CUDA
$ bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
...
INFO: Elapsed time: 7888.942s, Critical Path: 198.44s
INFO: 27351 processes: 27351 local.
INFO: Build completed successfully, 37588 total actions
$ ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
$ pip install --user /tmp/tensorflow_pkg/tensorflow-1.15.0-cp36-cp36m-linux_x86_64.whl
// without --user option, permission error
// tensorflow is installed in ~/.local/
$ cd
// change directory to outside the TensorFlow source tree
// check
$ python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
-------------------------------
Tensorflow 2.0 (latest)
-------------------------------
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ ./configure
// python3 instead of python
// default values except CUDA
$ bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
...
INFO: Elapsed time: 4152.719s, Critical Path: 195.95s
INFO: 10975 processes: 10975 local.
INFO: Build completed successfully, 11556 total actions
$ ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Mon Oct 28 18:41:32 KST 2019 : === Preparing sources in dir: /tmp/tmp.2nM4TJKNsz
~/tobuildtf/tensorflow ~/tobuildtf/tensorflow
~/tobuildtf/tensorflow
/tmp/tmp.2nM4TJKNsz/tensorflow/include ~/tobuildtf/tensorflow
~/tobuildtf/tensorflow
Mon Oct 28 18:41:39 KST 2019 : === Building wheel
warning: no files found matching 'README'
warning: no files found matching '*.pyd' under directory '*'
warning: no files found matching '*.pd' under directory '*'
warning: no files found matching '*.dylib' under directory '*'
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.csv' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow_core/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow_core/include/third_party'
Mon Oct 28 18:41:58 KST 2019 : === Output wheel file is in: /tmp/tensorflow_pkg
// without --user option, permission error
// tensorflow is installed in ~/.local/
$ pip install --user /tmp/tensorflow_pkg/tensorflow-2.0.0-cp36-cp36m-linux_x86_64.whl
Processing /tmp/tensorflow_pkg/tensorflow-2.0.0-cp36-cp36m-linux_x86_64.whl
Requirement already satisfied: wrapt>=1.11.1 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.11.2)
Requirement already satisfied: six>=1.12.0 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.12.0)
Collecting tensorflow-estimator<2.1.0,>=2.0.0
Using cached https://files.pythonhosted.org/packages/fc/08/8b927337b7019c374719145d1dceba21a8bb909b93b1ad6f8fb7d22c1ca1/tensorflow_estimator-2.0.1-py2.py3-none-any.whl
Requirement already satisfied: numpy<2.0,>=1.16.0 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.17.3)
Requirement already satisfied: absl-py>=0.7.0 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.8.1)
Requirement already satisfied: gast==0.2.2 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.2.2)
Collecting protobuf>=3.8.0
Using cached https://files.pythonhosted.org/packages/a8/52/d8d2dbff74b8bf517c42db8d44c3f9ef6555e6f5d6caddfa3f207b9143df/protobuf-3.10.0-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied: grpcio>=1.8.6 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.24.3)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.33.6)
Requirement already satisfied: keras-applications>=1.0.8 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.0.8)
Requirement already satisfied: google-pasta>=0.1.6 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.1.7)
Requirement already satisfied: astor>=0.6.0 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.8.0)
Collecting keras-preprocessing>=1.1.0
Using cached https://files.pythonhosted.org/packages/28/6a/8c1f62c37212d9fc441a7e26736df51ce6f0e38455816445471f10da4f0a/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl
Requirement already satisfied: termcolor>=1.1.0 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.1.0)
Collecting tensorboard<2.1.0,>=2.0.0
Using cached https://files.pythonhosted.org/packages/9b/a6/e8ffa4e2ddb216449d34cfcb825ebb38206bee5c4553d69e7bc8bc2c5d64/tensorboard-2.0.0-py3-none-any.whl
Requirement already satisfied: opt-einsum>=2.3.2 in /home/soh/.local/lib/python3.6/site-packages (from tensorflow==2.0.0) (3.1.0)
Requirement already satisfied: setuptools in /home/soh/.local/lib/python3.6/site-packages (from protobuf>=3.8.0->tensorflow==2.0.0) (41.4.0)
Requirement already satisfied: h5py in /home/soh/.local/lib/python3.6/site-packages (from keras-applications>=1.0.8->tensorflow==2.0.0) (2.10.0)
Requirement already satisfied: werkzeug>=0.11.15 in /home/soh/.local/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0.0) (0.16.0)
Requirement already satisfied: markdown>=2.6.8 in /home/soh/.local/lib/python3.6/site-packages (from tensorboard<2.1.0,>=2.0.0->tensorflow==2.0.0) (3.1.1)
Installing collected packages: tensorflow-estimator, protobuf, keras-preprocessing, tensorboard, tensorflow
Found existing installation: tensorflow-estimator 1.15.1
Uninstalling tensorflow-estimator-1.15.1:
Successfully uninstalled tensorflow-estimator-1.15.1
Found existing installation: Keras-Preprocessing 1.0.5
Uninstalling Keras-Preprocessing-1.0.5:
Successfully uninstalled Keras-Preprocessing-1.0.5
Found existing installation: tensorboard 1.15.0
Uninstalling tensorboard-1.15.0:
Successfully uninstalled tensorboard-1.15.0
Successfully installed keras-preprocessing-1.1.0 protobuf-3.10.0 tensorboard-2.0.0 tensorflow-2.0.0 tensorflow-estimator-2.0.1
$ cd
// change directory to outside the TensorFlow source tree
// check
$ python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
...
tf.Tensor(-1256.161, shape=(), dtype=float32)
$ python3 -c "import tensorflow as tf; print("tf.__version__")"
2.0.0