tensorflow源碼安裝

主要參考:https://www.tensorflow.org/install/install_sources#ConfigureInstallation


卸載tensorflow
?? ?sudo pip uninstall tensorflow

安裝git

??? 安裝git時記得先安裝,后更新系統
??? sudo apt install git



安裝jdk8:
?? ?my@ubuntu:~$ java

?? ?my@ubuntu:~$ sudo add-apt-repository ppa:openjdk/ppa

?? ?my@ubuntu:~$ sudo add-apt-repository ppa:openjdk-r/ppa
?
?? ?my@ubuntu:~$ sudo apt-get update

?? ?my@ubuntu:~$ sudo apt-get install openjdk-8-jdk

?? ?my@ubuntu:~$ sudo apt-get install openjdk-8-jre openjdk-8-jdk-headlesss
?? ?
?? ?my@ubuntu:~$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Install Bazel:
?? ?sudo apt-get update && sudo apt-get install bazel
?? ?sudo apt-get upgrade bazel
?? ?bazel version

一、安裝virtualenv:
?? ?my@ubuntu:~$ sudo apt-get install python-virtualenv

??? 在virtualenv中創建tensorfloe環境

?? ?my@ubuntu:~$ virtualenv --system-site-packages ~/tensorflow

??? 激活tensorflow的virtualenv環境

?? ?my@ubuntu:~$ source ~/tensorflow/bin/activate

??? 為虛擬環境創建快捷方式:
?? ?sudo printf '\nalias tensorflow="source ~/tensorflow/bin/activate"'>>~/.bashrc
??? 讓其生效:
?? ?source ~/.bashrc

二、在env環境中
?? ?
?? ?git clone https://github.com/tensorflow/tensorflow

?? ?sudo apt-get install python-numpy python-dev python-pip python-wheel

因為我的vm中沒有gpu,省去gpu的配置環節:

?? ?sudo apt-get install libcupti-dev

?? ? sudo pip install six numpy wheel


下面這段摘自tensorflow的官方文檔:
?? ?$cd tensorflow? # cd to the top-level directory created
?? ?$ ./configure
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7
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/lib/python2.7/dist-packages]

Using python library path: /usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL support will be enabled for TensorFlow
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]
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/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]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] Y
CUDA support will be enabled for TensorFlow
Do you want to use clang as CUDA compiler? [y/N]
nvcc will be used as CUDA compiler
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 6
Please specify the location where cuDNN 6 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
這里是非常重要的編譯配置:可以參考http://blog.csdn.net/nicholas_wong/article/details/70215127,但還要結合自己的機器報的警告來配置,
我的機器報如下警告:
/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. ?
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. ?
W tensorflow/core/platform,那我安裝的時候就配置sse4.1和sse4.2的選項,剛開始直接把人家的復制過來用,安裝完后報錯,后來自己配置了一下,安裝成功。而且上面的警告有時候是不會出現的,
我在安裝SyntaxNet wrapper 地址及安裝:https://github.com/short-edition/syntaxnet-wrapper時報錯,導致測試走不下去,只能消除警告,
?? ?sudo bazel build -c opt? --copt=-msse4.1 --copt=-msse4.2? //tensorflow/tools/pip_package:build_pip_package
這個編譯時間超長,要有耐心。

上述命令會生成一個叫做build_pip_package的腳本,按照如下命令運行這個腳本,在/tmp/tensorflow_pkg文件夾中創建pip的安裝包:

?? ?bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
?? ?cd? /tmp/tensorflow_pkg
?? ?ls
會發現一個whl的文件:tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl,這是編譯生成的。
下面進行安裝:

?? ?sudo? pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp27-cp27mu-linux_x86_64.whl
安裝完成后進行測試:注意測試的時候不要到安裝目錄下測試。
$ python

Enter the following short program inside the python interactive shell:

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

如果不報sse4.1和sse4.2錯誤,有可能安裝成功。

安裝syntaxnet:
?? ?前提是tensorflow已經安裝好,
?? ?git clone --recursive https://github.com/tensorflow/models.git

?? ?cd models/syntaxnet/tensorflow
配置選項:
?? ?$ ./configure

(tensorflow) my@ubuntu:~/models/syntaxnet/tensorflow$ cd ..

?? ?(tensorflow) my@ubuntu:~/models/syntaxnet$ bazel test syntaxnet/... util/utf8/...

?? ?(tensorflow) my@ubuntu:~/models/syntaxnet$ chmod +x? syntaxnet/demo.sh

7、pip安裝 asciitree、mock

?? ?(tensorflow) my@ubuntu:~/models/syntaxnet$? pip install asciitree

?? ?(tensorflow) my@ubuntu:~/models/syntaxnet$ pip install mock


??? 測試一個句子:

?? ?(tensorflow) my@ubuntu:~/models/syntaxnet$ sudo? echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh
?? ?

測試中文:?? ?

MODEL_DIRECTORY為解壓的中文模型的位置,一種方式是從http://download.tensorflow.org/models/parsey_universal/Chinese.zip下載
然后解壓到/home/py/models/syntaxnet/syntaxnet/models/parsey_universal,
另外一種方式是安裝 A lightweight SyntaxNet wrapper 地址及安裝:https://github.com/short-edition/syntaxnet-wrapper,它會自動安裝語言模型

測試:
py@ubuntu:~/models/syntaxnet$ MODEL_DIRECTORY=/home/py/models/syntaxnet/syntaxnet/models/parsey_universal/Chinese

py@ubuntu:~/models/syntaxnet$ echo '然而,中國經歷了30多年的改革開放' | syntaxnet/models/parsey_universal/tokenize_zh.sh $MODEL_DIRECTORY | syntaxnet/models/parsey_universal/parse.sh $MODEL_DIRECTORY


安裝SyntaxNet Wrapper

直接復制文檔了:

A lightweight SyntaxNet wrapper

The wrapper allows generic use of SyntaxNet in python. It provides interfaces for morphological analyse, pos tagging and dependency resolution along with optional formatting tool.

The wrapper does not intend to make any assumptions on the use of SyntaxNet, that's why it provides a simple interface and the raw output as default.

Disclaimer : Has been inspired from another wrapper but we did not want a server based wrapper.
Installation

We assume here that you have SyntaxNet installed and working properly on your workstation. If not, please refer to SyntaxNet official page

The wrapper has been tester on Ubuntu 14.04 Trusty and 16.04 Xenial.

(virtualenv)$ git clone https://github.com/short-edition/syntaxnet-wrapper.git
(virtualenv)$ cd syntaxnet-wrapper
(virtualenv)/syntaxnet-wrapper$ pip install -r requirements.txt
(virtualenv)/syntaxnet-wrapper$ vim syntaxnet_wrapper/config.yml
syntaxnet:
? ROOT_DIR: /home/user/workspace/syntactic_parser/tensorflow_models/syntaxnet
? PARSER_EVAL: bazel-bin/syntaxnet/parser_eval
? CONTEXT: syntaxnet/models/parsey_universal/context.pbtxt
? MODEL: syntaxnet/models/parsey_universal

(virtualenv)/syntaxnet-wrapper$ python -m unittest discover syntaxnet_wrapper
(virtualenv)/syntaxnet-wrapper$ pip install .

這一句比較重要:創建 /usr/share/syntaxnet_wrapper_config.yml,內容就是
syntaxnet:
? ROOT_DIR: /home/py/models/syntaxnet
? PARSER_EVAL: bazel-bin/syntaxnet/parser_eval
? CONTEXT: syntaxnet/models/parsey_universal/context.pbtxt
? MODEL: syntaxnet/models/parsey_universal


You should be able to use the wrapper from now. Instead of creating config.yml in the current folder, you can also expose it though the environment variable SYNTAXNET_WRAPPER_CONFIG or copying it in /usr/share/syntaxnet_wrapper_config.yml

You can also use the Dockerfile provided that will install SyntaxNet itself and the wrapper
How to use this wrapper

Two mode

You can use the wrapper in two modes, embodied in two different classes with the same interface

??? SyntaxNetWrapperSubprocess, a python implementation of demo.sh shell script provided in SyntaxNet. It starts new subprocesses at each call.
??? SyntaxNetWrapper, using wrapper's syntaxnet python implementation. Have the advantage to be faster and more memory efficient than the version with subprocesses. However, we are experience some trouble with it. See Well-known issues

The interface

The wrapper is expecting unicode text compatible with utf-8 format. The interface is the same for both classes :

??? morpho_sentence, make morphological analyse for a single sentence

??? morpho_sentences, make morphological analyse for a sentences list

??? tag_sentence, make pos tagging for a single sentence

??? tag_sentences, make pos tagging for a sentences list

??? parse_sentence, make dependency parsing for a single sentence

??? parse_sentences, make dependency parsing for a sentences list

??? transform_morpho, transform_tag and transform_dependency format the outputs in a more readable form. Deleting unfilled field.

例子:

>>> from syntaxnet_wrapper.wrapper import SyntaxNetWrapper
>>> sn_wrapper = SyntaxNetWrapper()
>>> dependency_output = sn_wrapper.parse_sentence(u"Bob brought a pizza to Alice")
>>> print dependency_output
u'1\tBob\t_\tPROPN\tNNP\tNumber=Sing|fPOS=PROPN++NNP\t2\tnsubj\t_\t_\n2\tbrought\t_\tVERB\tVBD\tMood=Ind|Tense=Past|VerbForm=Fin|fPOS=VERB++VBD\t0\tROOT\t_\t_\n3\ta\t_\tDET\tDT\tDefinite=Ind|PronType=Art|fPOS=DET++DT\t4\tdet\t_\t_\n4\tpizza\t_\tNOUN\tNN\tNumber=Sing|fPOS=NOUN++NN\t2\tdobj\t_\t_\n5\tto\t_\tADP\tIN\tfPOS=ADP++IN\t6\tcase\t_\t_\n6\tAlice\t_\tPROPN\tNNP\tNumber=Sing|fPOS=PROPN++NNP\t4\tnmod\t_\t_\n\n'

Use of different language

The wrapper use by default english model but you can use every "Parsey Universal" released by Google. You just need to pass the name of the model as a constructor's argument. The wrapper will then automatically download the model and use it.

>>> sn_wrapper = SyntaxNetWrapper(language='French')



轉載于:https://www.cnblogs.com/herosoft/p/8134123.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/453237.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/453237.shtml
英文地址,請注明出處:http://en.pswp.cn/news/453237.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Makefile學習之通配符和自動變量

規則中的通配符 “*” ,“?” ,“ [...]”, " % " , " wildcard " 1.“*” *.c表示所有后綴為.C的文件; 如果文件中用到通配符,使用“\*”; 2.通配符在變量中的使用; objects*.c 注意…

英語中十二個月名稱的由來

轉自網絡,原出處不詳。 公歷一年有12個月,但不少人并不知道12 個月的英語名稱的來歷。公歷起源于古羅馬歷法。羅馬的英語原來只有10 個月,古羅馬皇帝決定增加兩個月放在年尾,后來朱里斯*凱撒大帝把這兩個月移到年初,…

進程和程序的關系

1 進程是一個動態概念,而程序是一個靜態概念。 2 進程具有并行特征,程序沒有。 3 進程是競爭資源的基本單位。 4 一個程序對應多個進程,一個進程為多個程序服務。

Android怎么插手機卡,魅藍E手機卡怎么裝 魅藍E手機SIM卡安裝圖文教程

昨天下午,魅族發布了全新系列魅藍手機——魅藍E,定位魅藍高端產品線,售價1299元,李楠號稱魅藍E采用三四千元的旗艦機工藝,外觀/屏幕/拍照提升明顯。此外,魅藍E依舊支持全網通雙卡雙待。那么魅藍E怎么插卡/裝…

快速冪總結

快速冪總結 快速冪這個東西比較好理解,但實現起來到不老好辦,記了幾次老是忘,今天把它系統的總結一下防止忘記。 首先,快速冪的目的就是做到快速求冪,假設我們要求a^b,按照樸素算法就是把a連乘b次,這樣一來…

第三章

一.項目前期的主要工作 1.現狀分析 ①.硬件分析 ②.軟件分析 2.需求收集 3.粗略設計 ①.體系結構分析 ②.硬件(網絡)設計 ③.應用系統設計 ④.安全設計 ⑤.配套設計 4.可行性分析 二.結構的項目前期實例 1.組織分析 3.需求收集 4.粗略設計 ①.系統體系結…

進程的靜止和活動狀態

進程有3個主要狀態,即就緒,執行和等待。當一個進程被創建的時候,處于就緒狀態,嚴格地說是靜止就緒狀態,等到被激活,該進程就處于活動就緒狀態,如果時間片輪到該進程,那么該進程就執行…

榮耀magic3會用鴻蒙,趙明:榮耀Magic3芯片領先行業,大家看到以后會換掉手機!...

榮耀CEO趙明親自參加高通2021技術峰會,宣布與高通達成戰略合作,未來全系產品采用高通平臺。趙明同時透露未來的產品動向,不排除未來與華為繼續合作,采用鴻蒙操作系統的可能。趙明表示,Android操作系統依舊是榮耀的首選…

公司里從員工到經理,不同層級應該關注的事情

最近在看《領導梯隊》,超級棒的一本書,受益匪淺,推薦給各位從事管理方向的朋友 第一階段:從管理自我到管理他人(leader級)   新員工工作的最初幾年是個人貢獻者。無論他們從事的是銷售、會計、工程或是市…

繼續教育學習腳本

/* 本腳本運行于瀏覽器conlose中,自動點擊“繼續學習”按鈕,以實現阻止視頻的暫停 */ (function(){ var getStylefunction(obj,styleName){ if(obj.style){ return obj.style[styleName]; }else if(obj.currentStyle){ …

三周第三次課 3.7 su命令 3.8 sudo命令 3.9 限制root遠程登錄

3.7 su命令1、su命令su命令是用來切換用戶的;su命令需要使用- 進行切換,如果不使用- 也可以,但當前目錄是在root下,沒有徹底切換在root下 使用su命令創建文件,以指定用戶的身份創建文件切換后顯示-bash-4.2因為user5的…

js中加載指定的html代碼,在js或JQuery中怎樣判斷頁面html代碼中含有指定名稱的div元素...

在我們制作網頁的過程中,想要在某個頁面中的某一元素中添加新的內容,而不想改動那個頁面,我們一般會直接在全局的jsz中直接加入document.getElementById("指定id")來給定指定元素新的內容,但在一些頁面中沒有指定id的div元素瀏覽器就會報錯&am…

處理機和cpu的區別

處理機 處理機是計算機系統中存儲程序和數據,并按照程序規定的步驟執行指令的部件。程序是描述處理機完成某項任務的指令序列。指令則是處理機能直接解釋、執行的信息單位。處理機包括中央處理器(cpu),主存儲器,輸入-輸出接口。處…

三星手機官方固件下載

一,網站下載: https://updato.com/firmware-archive-select-model 查詢對應固件信息 https://www.sammobile.com/firmwares/galaxy-a7/SM-A7000/ http://samsung-updates.com/device/?idSM-A7000&detailsSM-A7000 二,下載器下載&#x…

133. Clone Graph

歡迎fork and star:Nowcoder-Repository-github 133. Clone Graph 題目 Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJs undirected graph serialization:Nodes are labeled uniquely. We use # as a separa…

進程控制塊PCB簡介

PCB(process control block),進程控制塊,是我們學習操作系統后遇到的第一個數據結構描述,它是對系統的進程進行管理的重要依據,和進程管理相關的操作無一不用到PCB中的內容。一般情況下,PCB中包含以下內容:…

html坐標繪制路徑,canvas學習筆記之繪制簡單路徑

1 線段(直線路徑)繪制線段一般步驟:moveTo(x,y) 移動畫筆到指定的坐標點(x,y)lineTo(x,y) 使用直線連接當前端點和指定的坐標點(x,y)stroke() 根據當前的畫線樣式,繪制當前或已經存在的路徑2 矩形路徑繪制矩形路徑一般步驟:rect(x, y, width, height) 矩形路徑&…

如何實現Punycode中文域名轉碼

如果你見過中文域名應該會覺得很奇怪,為什么復制出來的域名變成一個很莫名其妙的字符串,比如這個秀恩愛的域名“郝越.我愛你”,實際顯示的域名是 http://xn--vq3al9d.xn--6qq986b3xl/ 這就叫 Punycode 具體查看 https://www.punycoder.com/ P…

進程控制塊包含的信息

進程控制塊包含三類信息 1.標識信息。 用于唯一地標識一個進程,常常分由用戶使用的外部標識符和被系統使用的內部標識號。幾乎所有操作系統中進程都被賦予一個唯一的、內部使用的數值型的進程號,操作系統的其他控制表可以通過進程號來交叉引用進程控制…

增加表單的文字段的html的代碼是,表單及表單新增元素(示例代碼)

要想更好運用表單就要了解表單的的更多元素與屬性,首先看看對表單基本了解。表單的基本了解 元素用于用戶輸入數據的收集元素是最重要的表單元素,有許多type其中是用于向表單處理程序提交表單的按鈕。元素 元素定義待選擇的下拉列表選項,元素…