ubuntu16.04 源碼方法安裝tensorflow


參考博客:http://blog.csdn.net/zhaoyu106/article/details/52793183/,
http://blog.csdn.net/u010900574/article/details/52201808
由於我之前已經配置過cuda8.0和cudnn5.1.10所以不用安裝了
1、安裝bazel
點擊鏈接: installer for your system,跳轉到Bazel的下載頁面:
下載bazel-0.7.0-installer-linux-x86_64.sh到桌面,下載最新版的,不用和我的一致,然后在terminal中輸入以下命令
cd  /home/***(自己的用戶名)/Desktop/###(這個命令意思是找到剛剛我們用U盤傳過來的文件)
chmod +x PATH_TO_INSTALL.SH #對.sh文件授權
./PATH_TO_INSTALL.SH --user #運行.sh文件

 2、安裝第三方庫

在terminal中輸入以下命令

sudo apt-get install python-numpy swig python-dev python-wheel #安裝第三方庫
sudo apt-get install git
git clone git://github.com/numpy/numpy.git numpy 

 3、安裝tensorflow

在terminal中輸入以下命令

git clone https://github.com/tensorflow/tensorflow

 在terminal中輸入以下命令:

cd ~/tensorflow #切換到tensorflow文件夾
./configure #執行configure文件

 

Do you wish to use jemalloc as the malloc implementation? [Y/n] y
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] n
No Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] n
No XLA JIT support will be enabled for TensorFlow
Found possible Python library paths:
  /usr/lib/python2.7/site-packages
  /usr/lib64/python2.7/site-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python2.7/site-packages]

Using python library path: /usr/lib/python2.7/site-packages
Do you wish to build TensorFlow with OpenCL support? [y/N] n
No OpenCL 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
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0

 4創建pip

在tensorflow的根目錄下,在terminal中輸入以下命令:
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /home/***(你自己的用戶名)/Desktop/tensorflow-0.10.0-cp2-none-any.whl

 tensorflow-0.10.0-cp2-none-any.whl要根據你下載的文件名有所更改。

5、設置tensorflow環境

 

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
 # To build with GPU support:
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* .
python setup.py develop

 6、tensorflow測試

 

$ python

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>

 大功告成

出現的錯誤
操作

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer

 報錯

ERROR: /home/yaroslavvb/tensorflow.git/tensorflow/tensorflow/core/kernels/BUILD:1080:1: undeclared inclusion(s) in rule '//tensorflow/core/kernels:cwise_op_gpu': 
this is missing dependency dependency for following files included by 'tensorflow/core/kernels/cwise_op_gpu_floor.cu.cc':
  '/usr/local/cuda-8.0/include/cuda_runtime.h'
  '/usr/local/cuda-8.0/include/host_config.h'
  '/usr/local/cuda-8.0/include/builtin_types.h'
  '/usr/local/cuda-8.0/include/device_types.h'
  '/usr/local/cuda-8.0/include/host_defines.h'
  '/usr/local/cuda-8.0/include/driver_types.h'
  '/usr/local/cuda-8.0/include/surface_types.h'
  '/usr/local/cuda-8.0/include/texture_types.h'

 可以進入tensorflow/third_party/gpus/crosstool/目錄,打開CROSSTOOL文件,搜索cxx_builtin_include_directory,應該有三行,在下面添加行如下
cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"

如果出現的錯誤是類似的,只要將cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"的文件路徑改一下就可以了,親測有效

再次運行上一步的命令,應該就沒問題了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM