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. 【EMV L2】EMV终端数据

    Account TypeAcquirer IdentifierAdditional Terminal CapabilitiesAmount, Authorised (Binary)Amount, Au ...

  2. uva 202

    #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> # ...

  3. Linux本地yum源配置以及使用yum源安装gcc编译环境

    本文档是图文安装本地yum源的教程,以安装gcc编译环境为例. 适用范围:所有的cetos,红帽,fedroa版本 适用人群:有一点linux基础的小白 范例系统版本:CentOS Linux rel ...

  4. 巡风配置安装 –centOS6.5

    巡风是一款适用于企业内网的漏洞快速应急.巡航扫描系统,通过搜索功能可清晰的了解内部网络资产分布情况,并且可指定漏洞插件对搜索结果进行快速漏洞检测并输出结果报表. 其主体分为两部分:网络资产识别引擎,漏 ...

  5. cin.ignore

    功能:函数用于输入流.它读入字符,直到已经读了num 个字符(默认为1)或是直到字符delim 被读入(默认为EOF).其调用形式为cin.ignore(n,终止字符)       原型:istrea ...

  6. KMeams算法应用:图片压缩与贝叶斯公式理解

    from sklearn.datasets import load_sample_image import matplotlib.pyplot as plt from sklearn.cluster ...

  7. python 写入文件形式

    写入文件的不只是文本,还有二进制等,字节流是什么样式关系到能否写入文件. 以获取网页写入文件操作示例: response = requests.get("http://www.baidu.c ...

  8. tomcat之虚拟目录

    一般我们都是直接引用webapps下面的web项目,如果我们要部署一个在其它地方的WEB项目,这就要在TOMCAT中设置虚拟路径了,Tomcat的加载web顺序是先加载 $Tomcat_home$\c ...

  9. zabbix 监控进程

    参考资料 官方文档. 有时候某个进程挂了没有发现,直到业务中断才想起去检查.希望能有个功能在某个进程挂了以后发出告警. zabbix提供proc.num这个key对后台进程进行监控.原理很简单,其实就 ...

  10. 1--STM32 ADC1与ADC2 16通道DMA采集笔记(原创)

    最近在搞ADC,网上还是很多资源的,以下为参考链接:1.对STM32 ADC单次转换模式 连续转换模式 扫描模式的理解:https://www.cnblogs.com/zhanghankui/p/51 ...