[教程.待續(xù)]Setup Tensorflow in Ubuntu16.04 with CUDA8.0

沒想到安裝一個Tensorflow 都有那么多坑
經(jīng)過一天時間的折騰,重要完美的走完所有 菜鳥會遇到的坑楔壤。

以下經(jīng)驗教訓(xùn)總結(jié)為 傻瓜式 完全教程。

一. 在Windows10 下安裝 雙系統(tǒng)的Ubuntu

Win10下硬盤安裝Ubuntu雙系統(tǒng)教程(EasyBCD法)

二.配置Ubuntu 系統(tǒng)環(huán)境

1.因為默認系統(tǒng)環(huán)境 是open-jdk8.0 翎蹈,所以作為開發(fā)環(huán)境 需要替換成 oracel jdk會更好还蹲。

[在Linux系統(tǒng)配置Oracle Java JDK 8]
(http://jingyan.baidu.com/article/215817f7eea4a01eda142326.html)

2.命令行里 確認 $ : python --version

是否對應(yīng) python2.7,Yes就繼續(xù)

3. Install Bazel

sudo apt-get update && sudo apt-get install bazel

4.Install other dependencies

sudo apt-get install python-numpy swig python-dev python-wheel

5.

三.下載CUDA8.0 +CUDNN5

1. 下載(CUDA8.0 的兩個文件)[https://developer.nvidia.com/cuda-release-candidate-download]

Paste_Image.png

2. (下載CUDNN5)[https://developer.nvidia.com/rdp/cudnn-download]

選擇 cuDNN v5.1 for CUDA 8.0RC


Paste_Image.png
tar xvzf cudnn-8.0-linux-x64-v4.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

四.以源文件編譯方式安裝Tensorflow

1. clone tensorflow sources

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

2. download and install cuDNN

Download and install cuDNN
https://developer.nvidia.com/cudnn
Download cuDNN v4 (v5 is currently a release candidate and is only supported when installing TensorFlow from sources).
Uncompress and copy the cuDNN files into the toolkit directory. Assuming the toolkit is installed in /usr/local/cuda
, run the following commands (edited to reflect the cuDNN version you downloaded):

3.Configure the installation

Run the configure
script at the root of the tree. The configure script asks you for the path to your python interpreter and allows (optional) configuration of the CUDA libraries.
This step is used to locate the python and numpy header files as well as enabling GPU support if you have a CUDA enabled GPU and Toolkit installed. Select the option Y
when asked to build TensorFlow with GPU support.
If you have several versions of Cuda or cuDNN installed, you should definitely select one explicitly instead of relying on the system default.
For example:

$ ./configurePlease specify the location of python. [Default is /usr/bin/python]:
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 GPU support? [y/N] y

GPU support will be enabled for TensorFlow
Please specify which gcc nvcc should use 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]: 
7.5Please specify the location where CUDA 7.5 toolkit is installed. 

Refer to README.md for more details. 
[Default is /usr/local/cuda]:
Please specify the cuDNN version you want to use. 
[Leave empty to use system default]: 5

Please specify the location where cuDNN 5 library is installed. 
Refer to README.md for more details. [Default is /usr/local/cuda]:
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.
[Default is: "3.5,5.2"]: 3.0

Setting up Cuda include
Setting up Cuda libSetting up Cuda bin
Setting up Cuda nvvmSetting up CUPTI include
Setting up CUPTI lib64Configuration finished

This creates a canonical set of symbolic links to the Cuda libraries on your system.
Every time you change the Cuda library paths you need to run this step again before you invoke the bazel build command.
For the cuDNN libraries, use '6.5' for R2, '7.0' for R3, and '4.0.4' for R4-RC.

$ bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer$ bazel-bin/tensorflow/cc/tutorials_example_trainer
 --use_gpu
# Lots of output. This tutorial iteratively calculates the major eigenvalue of
# a 2x2 matrix, on GPU. The last few lines look like this.
000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]

Note that "--config=cuda" is needed to enable the GPU support.

Known issues
Although it is possible to build both Cuda and non-Cuda configs under the same source tree, we recommend to run bazel clean
when switching between these two configs in the same source tree.

You have to run configure before running bazel build. Otherwise, the build will fail with a clear error message. In the future, we might consider making this more convenient by including the configure step in our build process.

Create the pip package and install

When building from source, you will still build a pip package and install that.

$ 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

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# The name of the .whl file will depend on your platform.
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.10.0rc0-py2-none-any.whl

Setting up TensorFlow for Development

If you're working on TensorFlow itself, it is useful to be able to test your changes in an interactive python shell without having to reinstall TensorFlow.

To set up TensorFlow such that all files are linked (instead of copied) from the system directories, run the following commands inside the TensorFlow root directory:


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

Note that this setup still requires you to rebuild the //tensorflow/tools/pip_package:
build_pip_package
target every time you change a C++ file; add, delete, or move any python file;
or if you change bazel build rules.

Train your first TensorFlow neural net model

$ cd tensorflow/models/image/mnist
$ python convolutional.py


Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
...
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Epoch 0.12
Minibatch loss: 3.285, learning rate: 0.010000
Minibatch error: 6.2%
Validation error: 7.0%
...

關(guān)于 遇到的疑難雜癥: 重啟后無限登陸 不進去圖形桌面

ctrl+alt+f1
sudo stop lightdmsudo
 apt-get updatesudo 
apt-get upgradesudo 
apt-get install --reinstall lightdm
sudo reboot

看看有沒有改善

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末奔滑,一起剝皮案震驚了整個濱河市艾岂,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌朋其,老刑警劉巖王浴,帶你破解...
    沈念sama閱讀 216,324評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異令宿,居然都是意外死亡叼耙,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,356評論 3 392
  • 文/潘曉璐 我一進店門粒没,熙熙樓的掌柜王于貴愁眉苦臉地迎上來筛婉,“玉大人,你說我怎么就攤上這事癞松∷觯” “怎么了?”我有些...
    開封第一講書人閱讀 162,328評論 0 353
  • 文/不壞的土叔 我叫張陵响蓉,是天一觀的道長硕勿。 經(jīng)常有香客問我,道長枫甲,這世上最難降的妖魔是什么源武? 我笑而不...
    開封第一講書人閱讀 58,147評論 1 292
  • 正文 為了忘掉前任扼褪,我火速辦了婚禮,結(jié)果婚禮上粱栖,老公的妹妹穿的比我還像新娘话浇。我一直安慰自己,他們只是感情好闹究,可當我...
    茶點故事閱讀 67,160評論 6 388
  • 文/花漫 我一把揭開白布幔崖。 她就那樣靜靜地躺著,像睡著了一般渣淤。 火紅的嫁衣襯著肌膚如雪赏寇。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,115評論 1 296
  • 那天价认,我揣著相機與錄音嗅定,去河邊找鬼。 笑死刻伊,一個胖子當著我的面吹牛露戒,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播捶箱,決...
    沈念sama閱讀 40,025評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼智什,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了丁屎?” 一聲冷哼從身側(cè)響起荠锭,我...
    開封第一講書人閱讀 38,867評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎晨川,沒想到半個月后证九,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,307評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡共虑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,528評論 2 332
  • 正文 我和宋清朗相戀三年愧怜,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片妈拌。...
    茶點故事閱讀 39,688評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡拥坛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出尘分,到底是詐尸還是另有隱情猜惋,我是刑警寧澤,帶...
    沈念sama閱讀 35,409評論 5 343
  • 正文 年R本政府宣布培愁,位于F島的核電站著摔,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏定续。R本人自食惡果不足惜谍咆,卻給世界環(huán)境...
    茶點故事閱讀 41,001評論 3 325
  • 文/蒙蒙 一禾锤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧卧波,春花似錦时肿、人聲如沸庇茫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,657評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽旦签。三九已至查坪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間宁炫,已是汗流浹背偿曙。 一陣腳步聲響...
    開封第一講書人閱讀 32,811評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留羔巢,地道東北人望忆。 一個月前我還...
    沈念sama閱讀 47,685評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像竿秆,于是被迫代替她去往敵國和親启摄。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,573評論 2 353

推薦閱讀更多精彩內(nèi)容