虚拟环境:conda create -n tensorflow=1.13 python=3.6 (【Ubuntu】安装Anaconda并搭建虚拟环境和迁移)
pip install -U pip six numpy wheel setuptools mock future>=0.17.1
pip install -U keras_applications==1.0.6 --no-deps
pip install -U keras_preprocessing==1.0.5 --no-deps
pip install numpy==1.16.4
pip install scipy
pip install matplotlib
pip install Pillow
pip install tqdm
参考链接:Installing using binary installer
用二进制安装程序安装Bazel
注意:使用Using Bazel's APT repository方式安装会导致Bazel版本过高问题。
wget https://github.com/bazelbuild/bazel/releases/download/0.26.1/bazel-0.26.1-installer-linux-x86_64.sh
chmod +x bazel-0.26.1-installer-linux-x86_64.sh
./bazel-0.26.1-installer-linux-x86_64.sh --user
# --------------------------------------------------
sudo vim ~/.bashrc
export PATH="$PATH:$HOME/bin"
source ~/.bashrc
1. 下载Tensorflow源码
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
2. 配置编译系统
./configure
# ------------------------------------------------------- #
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.26.1 installed.
Please specify the location of python. [Default is /home/zzw/anaconda3/bin/python]: /home/zzw/anaconda3/envs/tensorflow=1.13/bin/python3
Found possible Python library paths:
/data2/zzw/Tensorflow-test/models/research/slim
/data0/zzw/tvm/python
/home/zzw/anaconda3/envs/tensorflow=1.12/lib/python3.6/site-packages
/data1/zzw/Caffe-test/caffe-ssd/python
/data0/zzw/tvm/nnvm/python
/data0/zzw/tvm/topi/python
Please input the desired Python library path to use. Default is [/data2/zzw/Tensorflow-test/models/research/slim]
/home/zzw/anaconda3/envs/tensorflow=1.12/lib/python3.6/site-packages
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: y
CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with TensorRT support? [y/N]: n
No TensorRT support will be enabled for TensorFlow.
Found CUDA 10.0 in:
/usr/local/cuda/lib64
/usr/local/cuda/include
Found cuDNN 7 in:
/usr/local/cuda/lib64
/usr/local/cuda/include
Please specify a list of comma-separated CUDA compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5]:
Do you want to use clang as CUDA compiler? [y/N]: n
nvcc will be used as CUDA compiler.
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
Searching for NDK and SDK installations.
Please specify the home path of the Android NDK to use. [Default is /home/zzw/Android/Sdk/ndk-bundle]:
The path /home/zzw/Android/Sdk/ndk-bundle or its child file "source.properties" does not exist.
Please specify the home path of the Android NDK to use. [Default is /home/zzw/Android/Sdk/ndk-bundle]: /data0/zzw/Android/Sdk/ndk-bundle
Please specify the (min) Android NDK API level to use. [Available levels: ['14', '15', '16', '17', '18', '19', '21', '22', '23', '24', '26', '27', '28']] [Default is 18]: 27
Please specify the home path of the Android SDK to use. [Default is /home/zzw/Android/Sdk]: /data0/zzw/Android/Sdk/android-sdk-linux
Please specify the Android SDK API level to use. [Available levels: ['26', '28']] [Default is 28]: 26
Please specify an Android build tools version to use. [Available versions: ['.knownPackages', '26.0.0', '27.0.0', '28.0.3']] [Default is 28.0.3]: 27.0.0
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
--config=mkl # Build with MKL support.
--config=monolithic # Config for mostly static monolithic build.
--config=gdr # Build with GDR support.
--config=verbs # Build with libverbs support.
--config=ngraph # Build with Intel nGraph support.
--config=numa # Build with NUMA support.
--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.
--config=v2 # Build TensorFlow 2.x instead of 1.x.
Preconfigured Bazel build configs to DISABLE default on features:
--config=noaws # Disable AWS S3 filesystem support.
--config=nogcp # Disable GCP support.
--config=nohdfs # Disable HDFS support.
--config=noignite # Disable Apache Ignite support.
--config=nokafka # Disable Apache Kafka support.
--config=nonccl # Disable NVIDIA NCCL support.
Configuration finished
-------------------------------------------------
安装Android-NDK: https://blog.csdn.net/qq_37643960/article/details/97814466
安装Android-sdk: https://blog.csdn.net/qq_37643960/article/details/97615153
我的安装目录:/data0/zzw/Android/Sdk/ndk-bundle
/data0/zzw/Android/Sdk/android-sdk-linux
另外,Android8.1选择android-ndk-r17c, sdk-tools-linux-4333796.zip
3. Bazel build
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
4. 安装软件包
pip install /tmp/tensorflow_pkg/tensorflow-1.14.0-cp36-cp36m-linux_x86_64.whl
参考链接:从源代码编译TensorFlow
源代码编译安装TensorFlow
Ubuntu 环境 TensorFlow 源码编译安装
Ubuntu 18.04 系统从源代码编译安装GPU支持的Tensorflow 1.8.0
RTX 2080ti bazel build: nvcc fatal: Unsupported gpu architecture 'compute_75'