参考

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++平台调用的更多相关文章

  1. TensorFlow基础笔记(0) 参考资源学习文档

    1 官方文档 https://www.tensorflow.org/api_docs/ 2 极客学院中文文档 http://www.tensorfly.cn/tfdoc/api_docs/python ...

  2. TensorFlow基础笔记(3) cifar10 分类学习

    TensorFlow基础笔记(3) cifar10 分类学习 CIFAR-10 is a common benchmark in machine learning for image recognit ...

  3. TensorFlow学习笔记0-安装TensorFlow环境

    TensorFlow学习笔记0-安装TensorFlow环境 作者: YunYuan 转载请注明来源,谢谢! 写在前面 系统: Windows Enterprise 10 x64 CPU:Intel( ...

  4. TensorFlow基础笔记(8) TensorFlow简单人脸识别

    数据材料 这是一个小型的人脸数据库,一共有40个人,每个人有10张照片作为样本数据.这些图片都是黑白照片,意味着这些图片都只有灰度0-255,没有rgb三通道.于是我们需要对这张大图片切分成一个个的小 ...

  5. TensorFlow基础笔记(0) tensorflow的基本数据类型操作

    import numpy as np import tensorflow as tf #build a graph print("build a graph") #生产变量tens ...

  6. TensorFlow基础笔记(14) 网络模型的保存与恢复_mnist数据实例

    http://blog.csdn.net/huachao1001/article/details/78502910 http://blog.csdn.net/u014432647/article/de ...

  7. TensorFlow基础笔记(13) tf.name_scope tf.variable_scope学习

    转载http://blog.csdn.net/jerr__y/article/details/60877873 1. 首先看看比较简单的 tf.name_scope(‘scope_name’). tf ...

  8. TensorFlow基础笔记(13) Mobilenet训练测试mnist数据

    主要是四个文件 mnist_train.py #coding: utf-8 import os import tensorflow as tf from tensorflow.examples.tut ...

  9. TensorFlow基础笔记(11) conv2D函数

    #链接:http://www.jianshu.com/p/a70c1d931395 import tensorflow as tf import tensorflow.contrib.slim as ...

随机推荐

  1. Win2008 r2 IIS7.5出现FastCGI进程最近常常失败。请过一会再尝试此请求的解决方法

    错误信息如图所示: 应用程序“PIAOYUN.CC”中的服务器错误Internet Information Services 7.5 错误摘要HTTP 错误 500.0 - Internal Serv ...

  2. CheckedComboBoxEditExtension

    public static class CheckedComboBoxEditExtension { public static void BindData(this CheckedComboBoxE ...

  3. 多主机共享ssh Public/Private Key

    前期服务器比较少,所有代码都放在github的私库中,在自己的github 设置中设置SSH keys就可以拉下相应的库中的代码到本地与服务器了,但是最近服务器多家了几台,每台都生成key加到gith ...

  4. 深入浅出 妙用Javascript中apply、call、bind【转】

    网上文章虽多,大多复制粘贴,且晦涩难懂,我希望能够通过这篇文章,能够清晰的提升对apply.call.bind的认识,并且列出一些它们的妙用加深记忆. apply.call 在 javascript ...

  5. GCC中文错误提示

    最近在教人学c语言,英语不过关,想把ubuntu16.04的gcc改为中文提示,经查找后发现:目前(2016.8.5)基于gcc5.4版本的中文帮助好像还没有. 后来又仔细查找,现在最新的有中文的也就 ...

  6. [Mongodb] 借mongodb被入侵勒索事件,谈下Linux服务器端口安全问题

    一.缘由: 最近几天Mongodb勒索事件甚嚣尘上:由于对外网开放访问并且没有开启授权机制被删库.远程拖库.勒索.接着又曝出Elasticsearch被勒索事件,缘由一样,Elasticsearch服 ...

  7. [转]手工实现RTTI

    运行时的动态类型检查(RTTI,Run Time Type Indentifiation)是c++中提供的一项语言机制,它主要用于判断多态对象的具体类型. 为什么不使用c++提供的RTTI功能  但c ...

  8. 快速写excel的方法

    对于用com组件写excel,笔者表示那个太慢了.而且很耗资源,还要装excel. 今天我们就用写文本文件的方式来写excel. 步骤1,用excel写好一个设计一个我们想要的模板. 步骤2,我们把做 ...

  9. Ribbon对于SocketTimeOutException重试的坑以及重试代码解析

    背景 本文基于Spring-Cloud, Daltson SR4 微服务一般多实例部署,在发布的时候,我们要做到无感知发布:微服务调用总会通过Ribbon,同时里面会实现一些重试的机制,相关配置是: ...

  10. js判断字符是否存在汉字的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...