Tensorflow is a very effective machine learning library implemented by C++, we can use tensorflow with Python, but, there is a problem if we don't compile the tensorflow, it would cost a lot of time to compute. when we install the tensorflow with pip, we can see a warning message:"The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations." when import tensorflow. so, we need to compile the tensorflow library to speed up computation.

What to prepare:

  1. Java 8
  2. Bazel
  3. Tensorflow
  4. Python 3+
  5. CuDNN and CUDA toolkit(if you want to build tensorflow-gpu version)

Install Bazel:

  1. check you JAVA_HOME or test java: $ java -version
  2. get Bazel package: $ git clone  https://github.com/bazelbuild/bazel.git (bazel can't install with yum.)
  3. switch to a proper version: $ git checkout tags/0.3.0
  4. $ cd bazel
  5. $ ./compile.sh
  6. add bazel to PATH for convenient: $ PATH = $PATH:(PATH_TO_BAZEL)/output/

Tensorflow:

  1. get Tensorflow package: $ git clone https://github.com/tensorflow/tensorflow
  2. $ cd tensorflow
  3. configure

    ./configure
    Please specify the location of python. [Default is /usr/bin/python]: /home/xxxx/.pyenv/version/python36/bin/python
    Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
    Do you wish to use jemalloc as the malloc implementation? [Y/n] Y
    jemalloc enabled
    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 Hadoop File System support? [y/N] N
    No Hadoop File System support will be enabled for TensorFlow
    Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] N
    No XLA JIT support will be enabled for TensorFlow
    Found possible Python library paths:
      /usr/local/lib/python2.7/dist-packages
      /usr/lib/python2.7/dist-packages
    Please input the desired Python library path to use.  Default is [/usr/local/lib/python2.7/dist-packages]
    Using python library path: /home/xxxx/.pyenv/version/python36/lib/python3.6/site-packages
    Do you wish to build TensorFlow with OpenCL support? [y/N] N
    No OpenCL support will be enabled for TensorFlow
    Do you wish to build TensorFlow with CUDA support? [y/N] N
     
    Configuration finished
  4. build tensorflow with bazel: $ bazel build -c opt --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package
  5. build whl file: $ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
  6. install tensorflow with whl file: $ pip install --upgrade /tmp/tensorflow_pkg/<your whl file>.whl

#Troubleshotting

After installing tensorflow with whl file, if you get an error with message "illegal instruction", that may caused by you use unsupported sse to build tensorflow, AVX, SSE4.1, SSE4.2, MFA are different kinds of extended instruction sets on X86 CPUs. Many contain optimized instructions for processing matrix or vector operations. before installing, check which instructions your CPU support, and put those optimizing flags in for all.

$ bazel build -c opt --copt=-mavx --copt=-msse4.1 --copt=-msse4.2  -k //tensorflow/tools/pip_package:build_pip_package

This solution refer to: https://github.com/tensorflow/tensorflow/issues/8976

How to compile tensorflow on CentOS的更多相关文章

  1. 【转】Compile FFmpeg on CentOS 6.x

    This guide is based on a minimal CentOS installation and will install FFmpeg with several external e ...

  2. CentOS 6 编译 TensorFlow for Java 以及 Maven Pom

    我们的系统环境 CentOS 6.5, JDK 1.8 更新yum源 $ yum update 安装 Python 2.7 $ yum install python27 python27-numpy ...

  3. centos上tensorflow一键安装脚本

    鉴于tensorflow在centos上安装相当麻烦,特地制作了一个脚本方便以后移植到其它机器上,脚本含有其它python常用包: #! /bin/bash   sudo yum install -y ...

  4. Ubuntu TensorFlow 源码 Android Demo的编译运行

    Ubuntu TensorFlow 源码 Android Demo的编译运行 一. 安装 Android 的SDK和NDK SDK 配置 A:下载 国内下载地址选最新的: SDK: https://d ...

  5. TensorFlow Android Camera Demo 使用android studio编译安装和解决Execution failed for task ':buildNativeBazel'报错

    可以参考官网:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android#android-stud ...

  6. Tensorflow[目录结构]

    1 - Tensorflow源码目录结构 基于2018年5月28日github的tensorflow源码,即1.8版本 第一层: tensorflow: 核心代码目录. third_party:第三方 ...

  7. centos7 源码编译安装TensorFlow CPU 版本

    一.前言 我们都知道,普通使用pip安装的TensorFlow是万金油版本,当你运行的时候,会提示你不是当前电脑中最优的版本,特别是CPU版本,没有使用指令集优化会让TensorFlow用起来更慢. ...

  8. How to install tensorflow from source on ubuntu 18.04 64bit

    1,install dependencies sudo apt-get install openjdk-8-jdk git python-dev python3-dev python-numpy py ...

  9. TensorFlow编译androiddemo

    首先是把tensorflow克隆到本地一份. git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git 既 ...

随机推荐

  1. Hadoop学习笔记1 - 使用Java API访问远程hdfs集群

    转载请标注原链接 http://www.cnblogs.com/xczyd/p/8570437.html 2018年3月从新司重新起航了.之前在某司过了的蛋疼三个月,也算给自己放了个小假了. 第一个小 ...

  2. Java for-each循环解惑

    Java for-each循环解惑 2014/04/24 | 分类: 技术之外 | 0 条评论 | 标签: JAVA 分享到:21 本文由 ImportNew - liqing 翻译自 javarev ...

  3. BZOJ 4265 货币系统

    今天比赛的时候做到的.题解写得很简单,但是感觉对于我这种蒟蒻还是很有思考的价值的. 题面(由于题面很短,就不概括了):小Q当上了新的宇宙大总统,他现在准备重新设计一套货币系统. 这个货币系统要求一共有 ...

  4. OO第二次博客作业(第二单元总结)

    在我开始写这次博客作业的时候,窗外响起了希望之花,由此联想到乘坐自己写的电梯FROM-3-TO--1下楼洗澡,然后······ 开个玩笑,这么辣鸡的电梯肯定不会投入实际使用的,何况只是一次作业.还是从 ...

  5. Ubuntu中,wxpython的TextCtrl引发的error:_pixman_log_error

    1>在windows下,执行下面的代码,不会报错,但是在Ubuntu下,就会报错 2>在Ubuntu下执行上面的代码,会提示下面的错. 解决方法: 若是TextCtrl中不写wx.TE_M ...

  6. hnsdfz -- 6.20 -- day5

    今天子贞的题...... 比前两天充实多了……肝了一个线段树,还玩了一个题答…… 虽然线段树不知道为什么50->25,题答题数据太水全场90+... 感觉也没想出来啥思路,无脑肝线段树,无脑玩题 ...

  7. js数据三大储存格式

    一.String格式  做为一个前端者 你第一手得到的数据都是字符串 二.数组格式 1.定义  var arr=[“张三”,”李四”,”王五”]; 数据通过索引去查找对应的元素   arr[3] 2. ...

  8. haproxy反向代理

    haproxy是个高性能的tcp和http的反向代理.它就是个代理.不像nginx还做web服务器 官网地址为www.haproxy.org nginx的优点和缺点 优点: 1.web服务器,应用比较 ...

  9. pycharm操作

  10. Java创建对象的4种方式

    Java创建对象的方式共有四种: 使用new语句实例化一个对象: 通过反射机制创建对象: 通过clone()方法创建一个对象: 通过反序列化的方式创建对象. 一.使用new语句实例化一个对象 new语 ...