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. react-native-printer

    react-native-printer A React Native Library to support USB/BLE/Net printer for Android platform Inst ...

  2. Linux 环境下安装Mysql的步骤

    一,以linux cent 6.9 安装mysql 5.6.39为例#下载安装包wget --no-check-certificate https://dev.mysql.com/get/Downlo ...

  3. hexdump

    一个十六进制格式化输出: #include <stdio.h> #include <stdlib.h> #include <string.h> void hexdu ...

  4. Python中的常用魔术方法介绍

    1.__init__ 初始化魔术方法 触发时机:初始化对象时触发(不是实例化触发,但是和实例化在一个操作中) 参数:至少有一个self,接收对象 返回值:无 作用:初始化对象的成员 注意:使用该方式初 ...

  5. 将jar包安装到本地repository中

    mvn install:install-file -Dfile=G:/lcn_springboot2.0/tx-plugins-db-4.1.2.jar -DgroupId=com.codingapi ...

  6. vue day4 table

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. 网络操作基础(two)

    P106 一.什么是活动目录?活动目录有哪些优点? 二.什么是域.域树.森林? 三.什么是信任?什么是域的方向及传递性? 四.如何管理活动目录的信任与站点? 解答! (一) 1.活动目录:提供了用于存 ...

  8. 第五章Bookstrap

    响应式原理: @media screen and (min-width:300px) and (max-width:500px) { /* CSS 代码 */ } #代表页面宽度大于300px和小雨5 ...

  9. 左耳听风-ARTS-第2周(2019/3/31-2019/4/6)

    Algorithm 验证括号题(https://leetcode.com/problems/valid-parentheses/).这道题在极客时间上覃超的<算法面试通关40讲>(http ...

  10. 记录一个源码安装mysql5.6的方法

    https://www.jb51.net/article/118853.htm 如果之前源码安装过mysql5.6的话,卸载方法如下:rm -rf /var/lib/mysql/rm -rf /usr ...