1. 程式人生 > >從原始碼編譯TensorFlow CPU版本

從原始碼編譯TensorFlow CPU版本

1 安裝Python3 的依賴

sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel

2從原始碼安裝Bazel
sudo apt-get install openjdk-8-jdk.
release page 下載最新版的安裝包

tar -zxvf bazelXXXX.tgz -C bazel
cd bazel
bash ./compile.sh
cp out/bazel /usr/bin/

3 從原始碼安裝TensorFlow

$ git clone https://github.com/tensorflow/tensorflow 
$ cd tensorflow
$ git checkout Branch # where Branch is the desired branch(like v1.2.1)
$ ./configure 
Please specify the location of python. [Default is /usr/local/bin/python]: /usr/bin/python3
Found possible Python library paths:
  /usr/local/lib/python3.4/dist-packages
  /usr/lib/python3/dist-packages
Please input the desired Python library path to use.  Default is [/usr/local/lib/python3.4/dist-packages]
/usr/lib/python3/dist-packages
Do
you wish to build TensorFlow with MKL support? [y/N] y MKL support will be enabled for TensorFlow Do you wish to download MKL LIB from the web? [Y/n] n Please specify the location where MKL is installed. [Default is /opt/intel/mklml]: /opt/intel/mkl Please specify optimization flags to use during compilation when
bazel option "--config=opt" is specified [Default is -march=native]: -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 Do you wish to build TensorFlow with VERBS support? [y/N] n No VERBS support will be enabled for TensorFlow 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 No CUDA support will be enabled for TensorFlow Extracting Bazel installation... ........ INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes. Configuration finished $ bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 -k //tensorflow/tools/pip_package:build_pip_package $ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg $ sudo pip3 install /tmp/tensorflow_pkg/XXX.whl(或者換成pip3 install --user /tmp/tensorflow_pkg/XXX.whl)

其中 –copt=-mavx 等等引數使用SIMD指令集增強計算效能。實際測算大概有30%左右的效能提升

Installing with virtualenv

Take the following steps to install TensorFlow with Virtualenv:

Install pip and virtualenv by issuing one of the following commands:

$ sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
$ sudo apt-get install python3-pip python3-dev python-virtualenv # for Python 3.n
Create a virtualenv environment by issuing one of the following commands:

$ virtualenv --system-site-packages targetDirectory # for Python 2.7
$ virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n
where targetDirectory specifies the top of the virtualenv tree. Our instructions assume that targetDirectory is ~/tensorflow, but you may choose any directory.
Activate the virtualenv environment by issuing one of the following commands:

 $ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
 $ source ~/tensorflow/bin/activate.csh  # csh or tcsh
The preceding source command should change your prompt to the following:

 (tensorflow)$ 
Issue one of the following commands to install TensorFlow in the active virtualenv environment:

 (tensorflow)$ pip install --upgrade tensorflow      # for Python 2.7
 (tensorflow)$ pip3 install --upgrade tensorflow     # for Python 3.n
 (tensorflow)$ pip install --upgrade tensorflow-gpu  # for Python 2.7 and GPU
 (tensorflow)$ pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
If the preceding command succeeds, skip Step 5. If the preceding command fails, perform Step 5.
(Optional) If Step 4 failed (typically because you invoked a pip version lower than 8.1), install TensorFlow in the active virtualenv environment by issuing a command of the following format:

 (tensorflow)$ pip install --upgrade tfBinaryURL   # Python 2.7
 (tensorflow)$ pip3 install --upgrade tfBinaryURL  # Python 3.n 
where tfBinaryURL identifies the URL of the TensorFlow Python package. The appropriate value of tfBinaryURLdepends on the operating system, Python version, and GPU support. Find the appropriate value for tfBinaryURL for your system here. For example, if you are installing TensorFlow for Linux, Python 2.7, and CPU-only support, issue the following command to install TensorFlow in the active virtualenv environment:

(tensorflow)$ pip3 install --upgrade \
 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp34-cp34m-linux_x86_64.whl
If you encounter installation problems, see Common Installation Problems.

Next Steps

After installing TensorFlow, validate the installation.

Note that you must activate the virtualenv environment each time you use TensorFlow. If the virtualenv environment is not currently active, invoke one of the following commands:

$ source ~/tensorflow/bin/activate      # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh  # csh or tcsh
When the virtualenv environment is active, you may run TensorFlow programs from this shell. Your prompt will become the following to indicate that your tensorflow environment is active:

(tensorflow)$ 
When you are done using TensorFlow, you may deactivate the environment by invoking the deactivate function as follows:

(tensorflow)$ deactivate 
The prompt will revert back to your default prompt (as defined by the PS1 environment variable).

Uninstalling TensorFlow

To uninstall TensorFlow, simply remove the tree you created. For example:

$ rm -r targetDirectory 

相關推薦

原始碼編譯TensorFlow CPU版本

1 安裝Python3 的依賴 sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel 2從原始碼安裝Bazel sudo apt-get install ope

Ubuntu16.04原始碼安裝TensorFlow(CPU only, python3.5)

好大一個坑!趕快跑!我們跳過去! TensorFlow原始碼下載https://github.com/tensorflow/tensorflow 順便小手一戳到安裝指引的link:https://www.tensorflow.org/install/ 選擇對應的系統,這裡用Ubunt

centos7 源碼編譯安裝TensorFlow CPU 版本

grpc 遇到 cloud pla bin index.php 都在 頭文件 evel 一、前言 我們都知道,普通使用pip安裝的TensorFlow是萬金油版本,當你運行的時候,會提示你不是當前電腦中最優的版本,特別是CPU版本,沒有使用指令集優化會讓TensorFlo

虛擬機 Ubuntu18.04 tensorflow cpu 版本

http 虛擬機 style 設置 不存在 vgg 正常 div 都是 虛擬機 Ubuntu18.04 tensorflow cpu 版本 虛擬機VMware 配置: 20G容量,可擴充 2G內存,可擴充 網絡采用NAT模式 平臺:win10下的Ubuntu18.04

CentOS 原始碼編譯並安裝 Nginx

Linux 系統要求 Nginx 在 Linux 作業系統下執行的時候,要想獲取高併發能力,要求 Linux 核心必須在 2.6 以上,可通過以下命令檢視 Linux 核心版本。 $ uname -r 2.6.18-128.e15 安裝 Nginx 的必備軟體 通過以下命令安裝使用

RHEL6.9 原始碼編譯安裝SVN版本控制器

svn版本:1.11.0下載連結:http://mirrors.shu.edu.cn/apache/subversion/subversion-1.11.0.tar.bz2依賴包下載:apr:http://mirrors.hust.edu.cn/apache//apr/apr-1.6.5.tar.bz2apr

Linux原始碼編譯安裝程式詳解

1.原始碼編譯概述 1.1 使用原始碼安裝軟體的優點: 獲得最新的軟體版本,及時修復bug 根據使用者需要,靈活定製軟體功能 1.2 應用場合舉例 安裝較新版本的應用程式時 當前安裝的程式無法滿足需要時  需要為應用程式新增新的功能時

window上安裝tensorflow cpu版本

https://blog.csdn.net/wust_lh/article/details/80408505 下載anaconda的時候,注意選擇python3.5對應的版本。 Anaconda版本:Anaconda3-4.3.0 Python版本:Python

macOS原始碼安裝TensorFlow出現問題ERROR: error loading package 'tensorflow/core/kernels/cloud': 解決方法

ERROR: error loading package 'tensorflow/core/kernels/cloud': Encountered error while reading extension file 'protobuf.bzl': no such p

golang 原始碼編譯記錄

下載golang 原始碼 筆者寫此部落格的時候最新是go 1.10.1 版本。 原始碼目錄 /root/source_bk/go_source/go 基本編譯流程解釋 go 語言編譯器自1.5版本開始自舉 ( 使用go編譯器編譯go編譯器 ) 。所

caffe2 02 caffe2 win10 vs2015編譯(預設CPU版本)

01 基本環境 win10 vs2015 Git python3.5.3 cmake-gui(3.7.2) caffe2的依賴庫都已經採用submodule形式整合到程式碼中了。 caffe2編譯重點參考原始碼下面的 scripts

Python3.7.1原始碼編譯安裝

#!/bin/bash #確保shell 切換到當前shell 指令碼資料夾 current_file_path= ( c

linux下原始碼編譯比特幣客戶端

下載原始碼 這個是master分支的,建議在tag裡選最新的穩定版,目前是v0.14.2 直接下載zip,別clone了,clone很慢。 編譯程式碼 不妨先看看官方的編譯說明 ps: 第一手的官方的資源一般都是最好的,有問題了最好

在win10裡原始碼編譯nodejs的安裝包和學習原始碼

大家其實都是從網站上下載直接安裝檔案的,為什麼還要從原始碼安裝呢?可能原因就兩個,一個想自己優化,新增一個特定的東西;另一個想學習nodejs的實現,知道為什麼這樣實現的。我這裡主要為學習nodejs的實現,所以要到下面的網站下載原始碼:https://nodejs.org/

ARM64原始碼編譯docker(v1.9.1)

在X86_64機器fedora系統下,不要使用官方編譯的rpm包,交叉編譯bootstrap會出現異常,使用原始碼編譯的go. 1.編譯X86_64的go binary cd /root git clone https://github.co

原始碼安裝tensorflow

bazel build -c opt --copt=-mavx --copt=-march=native  --copt=-mfpmath=both --copt=-msse4.2  //tensorflow/tools/pip_package:build_pip_packagebazel build -c

零開始學習區塊鏈技術(一)--原始碼編譯比特幣

寫在開始之前,為什麼你一定要學習區塊鏈技術? 技術的變革和迭代一直在飛速發展中,作為有著15年程式開發經驗的我,常常在思考現在的我們到底改如何做,到底應該學習些什麼,才能跟上新的時代變革,保持自身的競爭力,並且能為這個世界帶來更好的改變呢? 答案是,學習

caffe2 01 caffe2 win10 vs2017編譯(預設CPU版本)

01 基本環境 win10 vs2017 git python3.5.3 cmake-gui(3.7.2) caffe2的依賴庫都已經採用submodule形式整合到程式碼中了。 caffe2編譯重點參考原始碼下面的 scripts目錄下面的指

原始碼編譯 tensorflow 1.3.0

 1. My os environment     Centos 7.4    2. Install bazel and protobuf     bazel version 0.5.

OpenCV安裝流程及原始碼編譯方法 + 配置VS

本篇文章記錄了安裝OpenCV 3.4.2及配置VS2017的方法,以及利用CMake從原始碼編譯適用於老版本VS2013的OpenCV 3.4.2的編譯及配置流程。本文也可以作為其他OpenCV及VS版本安裝配置方法的參考。 1 安裝OpenCV 3.4.2