手机版
你好,游客 登录 注册
背景:
阅读新闻

Ubuntu 15.04下TensorFlow源代码方式安装

[日期:2016-07-16] 来源:Linux社区  作者:Linux [字体:大 中 小]

本文介绍TensorFlow源代码方式安装。安装的系统为 Ubuntu 15.04。

获取TensorFlow源代码

1
git clone --recurse-submodules https://github.com/tensorflow/tensorflow

使用 --recurse-submodules 选项来获取 TensorFlow 需要依赖的 protobuf 库文件。

安装 Bazel

  遵从以下 指令 来安装 bazel 依赖。bazel 安装文件:下载地址

  bazel 缺省需要使用JDK1.8,如你使用JDK1.7,请下载相应的安装包。

  安装 Bazel 其他所需依赖:

1
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip

  执行如下命令来安装Bazel:

1
2
chmod +x PATH_TO_INSTALL.SH
./PATH_TO_INSTALL.SH --user

   记住把 PATH_TO_INSTALL.SH 替换为你下载的Bazel安装文件名,如:

1
./bazel-0.1.4-installer-linux-x86_64.sh  --user

安装其他依赖

1
sudo apt-get install Python-numpy swig python-dev

配置安装

  运行 tensorflow 根目录下的 configure 脚本。这个脚本会要求你输入 python 解释器的安装路径,并允许你可选择安装CUDA库。

  如果不安装CUDA,则这一步主要是定位python和numpy头文件所在位置:

1
2
./configure
Please specify the location of python. [Default is /usr/bin/python]:

   如果要安装CUDA,则除了指定 python 外,还需指定 CUDA 安装位置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
./configure
Please specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
 
Please specify the location where CUDA 7.0 toolkit is installed. Refer to
README.md for more details. [default is: /usr/local/cuda]: /usr/local/cuda
 
Please specify the location where the cuDNN v2 library is installed. Refer to
README.md for more details. [default is: /usr/local/cuda]: /usr/local/cuda
 
Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Configuration finished

构建支持GPU的Tensorflow 

  在tensorflow 根目录下执行如下命令:

$ bazel build -c opt --config=cuda --spawn_strategy=standalone //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.

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-07/133223.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款