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 ...
随机推荐
- eclipse智能提示优化
1.Windows→Preferences→Java→Editor→Content Assist 其中的AutoActivation Delay默认值为200(单位是毫秒)也就是说在打“.”之后停留2 ...
- linux下判断文件和目录是否存在
1.前言 工作中涉及到文件系统,有时候需要判断文件和目录是否存在.我结合APUE第四章文件和目录,总结一下如何正确判断文件和目录是否存在,方便以后查询. 2.stat系列函数 stat函数用来返回与文 ...
- __attribute__中constructor和destructor
1.前言 最近看到一份代码,看到一个函数前面用__attribute__((destructor))修饰,当时感觉有点怪怪的,搜了整个程序,也没发现哪个地方调用这个函数.于是从字面意思猜想,该函数会在 ...
- Python2 cmp() 函数
描述 cmp(x,y) 函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1. 语法 以下是 cmp() 方法的语法: cmp( ...
- NRF24L01
转http://blog.csdn.net/wangshenzhen123/article/details/47207837 1.一个发送通道,6个接收通道.发送端发送通道地址寄存器中的地址指向的就是 ...
- scikit-learn 入门
简介: scikit-learn是一个基于NumPy.SciPy.Matplotlib的开源机器学习工具包.採用Python语言编写.主要涵盖分类. 回归和聚类等算法,比如knn.SVM.逻辑回归.朴 ...
- [na]二层+tcp/udp数据包格式
标准:6+6+2+3 =17 3 思科:6+6+2+3+3=20 6 ip首部格式 tcp首部格式
- [Golong]学习笔记(一) 基础知识
Go编程基础 Go的内置keyword(25个) 不多 break default func interface select case defer go map struct chan else g ...
- sudo和man的tab自动补全
要加入sudo和man的tab自动补全功能,只需在~/.bashrc中加入: #Enabling tab-completioncomplete -cf sudocomplete -cf man
- Solr学习之五
一.段管理 段是一个自包含,仅可读的solr的索引的子集.一旦一个段被刷新到持久存储后,它将不会改变.当添加新文档到你的索引时候,它们被写入到新的段中.因此,在你的索引中,有很多激活的段.一次查询必须 ...