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
tensorflow源码安装相关推荐
- Tensorflow 源码安装成功,导入报错 ImportError: cannot import name 'build_info'
ImportError: cannot import name 'build_info' ImportError: Could not import tensorflow. Do not import ...
- 源码安装tensorflow
因为官网上的源码安装教程基本也是使用的Python2,所以我这里使用Python3来安装 操作系统:xubuntu17.04 64位 下载bazel,下载页面为https://github.com/b ...
- anaconda tensorflow 2.3_安装anaconda amp;源码安装lightgbm,xgboost
一.下载anaconda安装包 进anaconda官网下载自己系统对应的安装包https://www.anaconda.com/ 二.安装anaconda 三.创建快捷键 安装完成后点击windows ...
- cuda 编译 linux,Linux下安装Tensorflow源码及编译
下载Tensorflow源码 git clone https://github.com/tensorflow/tensorflow 如果无法下载也可以在github上直接下载tensorflow的打包 ...
- ubuntu16.04中源码安装仅仅支持CPU的TensorFlow
直接用pip3安装的tensorflow在运行代码时,总是会提醒另一种更加高效率的编译模式,很烦人,再加上据说在CPU上计算速度会加倍,于是就尝试用tensorflow的源码进行安装,主要参考了T ...
- 干货|TensorFlow开发环境搭建(Ubuntu16.04+GPU+TensorFlow源码编译)
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|机器学习算法工程师 安装平台 1 平台 目前Tensor ...
- Tensorflow源码解析1 -- 内核架构和源码结构
1 主流深度学习框架对比 当今的软件开发基本都是分层化和模块化的,应用层开发会基于框架层.比如开发Linux Driver会基于Linux kernel,开发Android app会基于Android ...
- [图解tensorflow源码] 入门准备工作附常用的矩阵计算工具[转]
[图解tensorflow源码] 入门准备工作 附常用的矩阵计算工具[转] Link: https://www.cnblogs.com/yao62995/p/5773142.html tensorfl ...
- Tensorflow源码编译
相比源码编译各版本之间遇到的坑来说,pip安装真心省事.不过由于项目需要采用C++实现的整个感知模块,只能把DL前向传播这块也写成C++形式.这是我去年的编译过程,当时有不少坑没能记录下来,以后有机会 ...
最新文章
- 南科大新任校长薛其坤:考研3次才进入中科院,杨振宁曾点赞他「诺奖级」研究成果...
- Safe or Glitch-Free Clock Gating
- mysql5720_Mysql内置功能《五》 函数
- gRPC中Java和node进行异构通信-互为客户端和服务端
- IP地址概念及其划分
- 每天一道LeetCode-----寻找两个链表的交点
- CentOS7—HAProxy安装与配置
- tomcat如何修改java版本_Java程序员必备——Tomcat配置技巧Top10
- 【轻松一刻】计算公式:为什么我们都是猪
- poj1979 深度优先搜索 挑战程式设计竞赛
- 阴谋还是骗局?美国最牛家族的“董事长”,跑到中国开了家假银行.....
- 没有光芯片,何谈 5G 与 AI !
- 20210612:力扣第244周周赛题解(上)
- 自学python免费教材-python零基础自学教材
- IIR数字程控滤波器
- Roson的Qt之旅 #117 QTcpSocket和QUdpSocket详细介绍
- 2021腾讯算法大赛
- python中一切都是对象对吗_在 Python 中一切皆对象,它完全支持()
- BT源代码学习心得(十五):客户端源代码分析(下载过程中的块选取策略)
- 淘宝按关键词搜索天猫商品接口调用展示
热门文章
- Eclipse中使用Checkstyle,checkstyle插件检查java代码的自定义配置文件:
- android中资源文件的两种访问方式,Android_Android学习笔记-保存文件(Saving Files),Android设备有两种文件存储区域 - phpStudy...
- (多线程)leetcode1195. 交替打印字符串 最简单解法一个变量搞定
- 数据结构课上笔记11
- C++:02---命名空间
- 最近准备学习下mongodb(一 Windows安装篇)
- network---written test
- 算法(24)-股票买卖
- Python(18)-字典dictionary、集合
- dataframe 筛选_Spark.DataFrame与Spark.ML简介