【TensorFlow学习一】基于Anaconda虚拟环境源码编译安装TensorFlow-gpu

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • TensorFlow installed from (source or binary): source
  • TensorFlow version: 1.13.0
  • Python version: 3.6.9
  • Bazel version (if compiling from source): 0.26.1
  • GCC/Compiler version (if compiling from source): 5.0
  • CUDA/cuDNN version: CUDA 10.0 cuDNN 7.3.0
  • GPU model and memory: RTX2080Ti 11G

虚拟环境:conda create -n tensorflow=1.13 python=3.6 (【Ubuntu】安装Anaconda并搭建虚拟环境和迁移)


一. 安装 TensorFlow pip 软件包依赖项

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
    

二. 安装Bazel (0.26.1版)

    参考链接: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

三. 编译安装Tensorflow

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'                 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值