TensorFlow基础笔记(15) 编译TensorFlow.so,提供给C++平台调用
参考
http://blog.csdn.net/rockingdingo/article/details/75452711
https://www.cnblogs.com/hrlnw/p/7007648.html
https://www.cnblogs.com/hrlnw/p/7383951.html
1.下载tensorflow源码
git clone https://github.com/tensorflow/tensorflow
2.安装bazel
sudo apt-get update && sudo apt-get install bazel
升级bazel
sudo apt-get upgrade bazel
使用bazel编译出现最低版本要求 0.4.5, 而本身的版本为0.11.1的时候,
将 最低版本要求 0.4.5文件中的0.4.5修改为0.0.0
3.编译源码,生成so库
## 进入tensoflow源码根目录后编译
# 编译生成.so文件, 编译C++ API的库 (建议)
bazel build //tensorflow:libtensorflow_cc.so
# 也可以选择,编译C API的库
bazel build //tensorflow:libtensorflow.so
编译出现问题,建议Git clone最新的tensoflow代码 重新编译
编译完成,可以看到编译生成的文件路径
tensorflow/cc/gradients/data_flow_grad.cc:151:1: note: in expansion of macro 'REGISTER_GRADIENT_OP'
REGISTER_GRADIENT_OP("ParallelDynamicStitch", DynamicStitchGrad);
^
Target //tensorflow:libtensorflow_cc.so up-to-date:
bazel-bin/tensorflow/libtensorflow_cc.so
INFO: Elapsed time: 1051.314s, Critical Path: 74.06s
INFO: Build completed successfully, 2355 total actions
4 编译完成,配准调用环境
在等待30多分钟后, 如果编译成功,在tensorflow根目录下出现 bazel-bin, bazel-genfiles 等文件夹,
按顺序执行以下命令将对应的libtensorflow_cc.so文件和其他文件拷贝进入 /usr/local/lib/ 目录
mkdir /usr/local/include/tf
cp -r bazel-genfiles/ /usr/local/include/tf/
cp -r tensorflow /usr/local/include/tf/
cp -r third_party /usr/local/include/tf/
cp -r bazel-bin/tensorflow/libtensorflow_cc.so /usr/local/lib/
这一步完成后,我们就准备好了libtensorflow_cc.so文件等,后面在自己的C++编译环境和代码目录下编译时链接这些库即可。
5 c++调用libtensorflow_cc.so
安装protobuf出现了问题
+ autoreconf -f -i -Wall,no-obsolete
configure.ac:30: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
网上的方案
https://superuser.com/questions/565988/autoconf-libtool-and-an-undefined-ac-prog-libtool
已经安装了 libtool
sudo apt-get install libtool (失败)
可以解决的方法
You need to reinstall it in order to fix the error so follow these steps :
1] Remove current libtool if installed: sudo apt-get purge libtool
2] Download it from official website https://www.gnu.org/software/libtool/
3] Untar it: tar -xzvf "name of the tar_file"
4] Enter folder and type: ./configure && make
5] Install it: sudo make install
And you are done, error should be fixed !
安装步骤
git clone https://github.com/google/protobuf.git
(0)./autogen.sh
(1)./configure --prefix=/usr/local/protobuf
(2)make
(3)make check
(4)make install
注意:
安装成功后,将它的bin和lib目录分别加入到PATH和LD_LIBRARY_PATH环境变量,以方便直接调用。
设置环境变量过程:编辑/etc/profile,在文件末尾添加:
注意:这里添加的路径不同版本protobuf可能不同,需要根据提示确认路径,否则会出现root用户和普通用户版本不同的问题。
export PATH=$PATH:/usr/local/protobuf/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib
此时最好重启一次。
查看protobuf版本的命令为:protoc --version,如果普通用户无法查看,或者与sudo protoc --version查看的版本不同,就是出现了上述路径添加错误的情况。
TensorFlow基础笔记(15) 编译TensorFlow.so,提供给C++平台调用的更多相关文章
- TensorFlow基础笔记(0) 参考资源学习文档
1 官方文档 https://www.tensorflow.org/api_docs/ 2 极客学院中文文档 http://www.tensorfly.cn/tfdoc/api_docs/python ...
- TensorFlow基础笔记(3) cifar10 分类学习
TensorFlow基础笔记(3) cifar10 分类学习 CIFAR-10 is a common benchmark in machine learning for image recognit ...
- TensorFlow学习笔记0-安装TensorFlow环境
TensorFlow学习笔记0-安装TensorFlow环境 作者: YunYuan 转载请注明来源,谢谢! 写在前面 系统: Windows Enterprise 10 x64 CPU:Intel( ...
- TensorFlow基础笔记(8) TensorFlow简单人脸识别
数据材料 这是一个小型的人脸数据库,一共有40个人,每个人有10张照片作为样本数据.这些图片都是黑白照片,意味着这些图片都只有灰度0-255,没有rgb三通道.于是我们需要对这张大图片切分成一个个的小 ...
- TensorFlow基础笔记(0) tensorflow的基本数据类型操作
import numpy as np import tensorflow as tf #build a graph print("build a graph") #生产变量tens ...
- TensorFlow基础笔记(14) 网络模型的保存与恢复_mnist数据实例
http://blog.csdn.net/huachao1001/article/details/78502910 http://blog.csdn.net/u014432647/article/de ...
- TensorFlow基础笔记(13) tf.name_scope tf.variable_scope学习
转载http://blog.csdn.net/jerr__y/article/details/60877873 1. 首先看看比较简单的 tf.name_scope(‘scope_name’). tf ...
- TensorFlow基础笔记(13) Mobilenet训练测试mnist数据
主要是四个文件 mnist_train.py #coding: utf-8 import os import tensorflow as tf from tensorflow.examples.tut ...
- TensorFlow基础笔记(11) conv2D函数
#链接:http://www.jianshu.com/p/a70c1d931395 import tensorflow as tf import tensorflow.contrib.slim as ...
随机推荐
- c#实现用SQL池(多线程),定时批量执行SQL语句
在实际项目开发中,业务逻辑层的处理速度往往很快,特别是在开发Socket通信服务的时候,网络传输很快,但是一旦加上数据库操作,性能一落千丈,数据库操作的效率往往成为一个系统整体性能的瓶颈.面对这问题, ...
- powerdesigner基础操作
一.建表 1. 打开PowerDesigner,点击File->New 2. 选择Conceptual Data Model,并修改Model name. 3. ...
- python 报错 SyntaxError: Non-ASCII character
报错: SyntaxError: Non-ASCII character 概意思是,默认文件是ASCII格式,需要更改文件编码,操作是在文件首行加上 #!/usr/bin/python # -*- c ...
- C++ 链接Mysql 函数介绍
通过MySQL自己的API函数进行连接 1.使用API的方式连接,需要加载mysql的头文件和lib文件.在VS2010的附加包含目录中添加\MySQL\MySQL Server 5.1\includ ...
- [na]wac无线控制器集中转发部署的几种情况
1,背景: sta属于vlan20.ap属于vlan20.本地转发. 现象: Ap获取到的地址是vlan20的地址池的某地址 用户无法获取地址. 注意:本地转发,ap获取地址dhcp包不走隧道.用户获 ...
- spring mvc 2.5.6配置
兼容公司老版本号项目.必须得用spring mvc2.5.6,那么问题来了. 怎么配置controller都抛出no mapping的错误.经过查文档得出下面配置.仅供參考. servlet-conf ...
- Photoshop制作Android UI: 怎样将图片背景变为透明
看烦了代码.今天玩玩PS吧.本人是PS小白.Android开发中不可避免的要做一些图片,但我发现居然没有相似的专门教程.真想拜个美工为师.还记得2012年去宁波实习时为了将图片缩小我还matlab写个 ...
- solr进阶九:solr对数字和单个字符的搜索
solr中配有分词器,但分词器里面有大写转换为小写的过滤器时,数字就会被过滤.比如123中国ABC.123就会被过滤掉了,所以才查1|12|123都会失败. <Solr 数字字符不能搜索的一个问 ...
- Mybatis Spring multiple databases Java configuration
https://stackoverflow.com/questions/18201075/mybatis-spring-multiple-databases-java-configuration ** ...
- C中fread()函数的返回值
这个问题很容易搞错,并导致很多问题,需要强调的是fread函数返回的并不是字节数. realRead = fread(buf,item,count,fp) (每次读item大小的数据块,分cou ...