[教程.待续]Setup Tensorflow in Ubuntu16.04 with CUDA8.0

没想到安装一个Tensorflow 都有那么多坑
经过一天时间的折腾,重要完美的走完所有 菜鸟会遇到的坑。

以下经验教训总结为 傻瓜式 完全教程。

一. 在Windows10 下安装 双系统的Ubuntu

Win10下硬盘安装Ubuntu双系统教程(EasyBCD法)

二.配置Ubuntu 系统环境

1.因为默认系统环境 是open-jdk8.0 ,所以作为开发环境 需要替换成 oracel jdk会更好。

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

2.命令行里 确认 $ : python --version

是否对应 python2.7,Yes就继续

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%
...

关于 遇到的疑难杂症: 重启后无限登陆 不进去图形桌面

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

看看有沒有改善

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容