zoukankan      html  css  js  c++  java
  • tensorflow源代码方式安装

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

    获取TensorFlow源代码

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

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

    安装 Bazel

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

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

      安装 Bazel 其他所需依赖:

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

      执行如下命令来安装Bazel:

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

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

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

    安装其他依赖

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

    配置安装

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

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

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

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

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

  • 相关阅读:
    C++强大的背后
    C++ 非托管的vc工程中部分文件使用.Net Framwork
    C++ 基于 Visual C++6.0 的 DLL 编程实现
    C++ 中指针,指针的引用,指针的指针的区别
    C# 中重用c/c++旧模块
    C++ 打开exe文件的方法(VS2008)
    C++ 指针 指针高级<高质量编程>
    C++ 函数指针
    有用但不常见的c++函数
    C++ int & *p; //不能建立指向引用的指针;int *a; int * & p=a; //正确,指针变量的引用
  • 原文地址:https://www.cnblogs.com/simplelovecs/p/5150114.html
Copyright © 2011-2022 走看看