ubuntu14.04+GTX1050+Anaconda2+tensorflow r1.1源码安装(GPU)【默认CUDA,CUDNN已安装好】

用了一晚上,试了tensorflow的两种安装方法

1.使用Anaconda2的conda建立envs直接安装gpu版的tf。出现的问题是作minst测试时出现了 error == cudaSuccess (30 vs 0) 的错误,网上也无法找到解决方案,估计是conda对gpu版的tf采取的默认设置,一些关于本机电脑的gpu相关配置没有设置好(本人猜测,如有博友知晓原因,请指教,感激不尽),根据这个猜测,采取了tensorflow源码安装的方式。这篇博客也主要记录该方式的安装过程。

2.tf r1.1 源码安装。

建议去https://www.tensorflow.org/install/install_sources 查看已经通过测试的源代码配置,这样会大大提高安装成功率。


博主选择的是倒数第三种。

- 安装依赖

sudo apt-get install python-pip python-dev python-virtualenv python-numpy python-pip python-wheel
sudo apt-get install pkg-config zip g++ zlibig-dev unzip

- 安装Bazel  

1.根据配置,选择安装bazel0.4.2 ,在该网站上下载 https://github.com/bazelbuild/bazel/releases/tag/0.4.2 

文件是 bazel-0.4.2-installer-linux-x86_64.sh

修改安装脚本的权限

chmod +x bazel-0.4.2-installer-linux-x86_64.sh

2.安装 Java Development Kit8(JDK8)

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:webuppd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

3.安装Bazel

./bazel-0.4.2-installer-linux-x86_64.sh --user

使用user选项,Bazel被安装到HOME/bin目录。

sudo printf '\nexport PATH="$PATH:$HOME/bin"' >> ~/.bashrc    #更新~/.bashrc

确保bazel路径被添加到环境变量.

重启bash终端,运行

bazel version

有输出,代表安装成功。

- 安装CUDA,cudnn

博主这里安装的是CUDA8,cudnn5.1

- 从github下载 Tensorflow 源码

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

查看当前分支, 根据需求切换到指定分支, e.g. r1.1

$ cd tensorflow
$ git checkout r1.1

-设置安装配置

根据自己python版本, cuda, cudnn版本和GPU计算力设置【GTX1050 计算能力6.1,在configure设置中会用到】

注意几点:
1.路径填写anacodna的/home/stevenke/anaconda2/lib/python2.7/site-packages
2.cuda,cudnn填写自己的版本 cuda是8,cudnn是5
3.计算能力:填写显卡的计算能力 6.1
$ cd tensorflow  # cd to the top-level directory created
$ ./configure

-编译 pip package 

$ bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package  --local_resources 2048,.5,1.0

-生成.whl文件

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tensorflow/bin

-安装 .whl

$ pip install tensorflow-1.1.0-cp27-cp27mu-linux_x86_64.whl

-测试:mnist(测试python是否可以找到tf包,gpu是否工作)

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/",one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32,[None,784])

w = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))

y = tf.nn.softmax(tf.matmul(x,w) + b)

y_ = tf.placeholder(tf.float32,[None,10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),reduction_indices=[1]))

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

tf.global_variables_initializer().run()
#tf.initialize_all_variables().run()

for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    train_step.run({x: batch_xs, y_:batch_ys})

correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))

accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))

print(accuracy.eval({x: mnist.test.images, y_: mnist.test.labels}))

-问题汇总

1.问题:
编译安装tensorflow GPU版本时报错:Cannot find libdevice.10.bc under /usr/local/cuda-8.0
解决办法:
将/usr/local/cuda-8.0/nvvm/libdevice/libdevice.compute_50.10.bc改为libdevice.10.bc,并复制一份至/usr/local/cuda-8.0/
2.问题
grin 1.2.1 requires argparse>=1.1, which is not installed.
解决:pip install argparse
3.问题
pip 版本过旧
解决方法:
pip install -U pip
4.问题:
python-dateutil 过旧
解决:
pip install python-dateutil --upgrade

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值