如果您还在阅读,那么我假设您需要弄清楚如何在C ++的生产环境中运行Tensorflow。
2.2.1 编译tensorflow
对于我的项目,我想要一个可以链接和部署的Tensorflow共享库。这就是我们将在此项目中构建的内容,并使用它构建label_image示例。对于tensorflow c++接口来说,只能通过源码进行编译安装,不能通过pip安装。
要在C ++中运行我们的模型,我们首先需要获取Tensorflow源代码树。该指令在这里,但我们将在下面走通他们。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
(tensorflow) $ ~/Development/keras-to-tensorflow $ git clone https://github.com/tensorflow/tensorflow Cloning into 'tensorflow'... remote: Counting objects: 223667, done. remote: Compressing objects: 100% (15/15), done. remote: Total 223667 (delta 2), reused 8 (delta 0), pack-reused 223652 Receiving objects: 100% (223667/223667), 116.84 MiB | 3.17 MiB/s, done. Resolving deltas: 100% (173085/173085), done. Checking connectivity... done. (tensorflow) $ ~/Development/keras-to-tensorflow $ cd tensorflow/ (tensorflow) $ ~/Development/keras-to-tensorflow/tensorflow $ git checkout r1.1 Branch r1.1 set up to track remote branch r1.1 from origin. Switched to a new branch 'r1.12' (tensorflow) $ ~/Development/keras-to-tensorflow/tensorflow $ ls ACKNOWLEDGMENTS BUILD LICENSE tensorflow WORKSPACE ADOPTERS.md configure models.BUILD third_party AUTHORS CONTRIBUTING.md README.md tools bower.BUILD ISSUE_TEMPLATE.md RELEASE.md util (tensorflow) $ ~/Development/keras-to-tensorflow/tensorflow $ |
查看tensorflow的要求,我们选择bazel0.15.0,要求如下:

bazel的安装说明如下:
【mcj】bazel安装指定版本
验证以下bazel的版本信息:
bazel help
现在我们已经安装了所有东西,我们可以配置和构建。确保您位于顶级tensorflow目录中。我使用了所有默认配置选项。执行此操作时,配置工具将下载一堆依赖项 – 这需要一两分钟。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
(tensorflow) $ ~/Development/keras-to-tensorflow/tensorflow $ ./configure Please specify the location of python. [Default is /home/bitwise/anaconda3/envs/tensorflow/bin/python]: 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 Found possible Python library paths: /home/bitwise/anaconda3/envs/tensorflow/lib/python3.6/site-packages Please input the desired Python library path to use. Default is [/home/bitwise/anaconda3/envs/tensorflow/lib/python3.6/site-packages] Using python library path: /home/bitwise/anaconda3/envs/tensorflow/lib/python3.6/site-packages 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] No CUDA support will be enabled for TensorFlow Configuration finished INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes. ............ WARNING: ~/.cache/bazel/_bazel_bitwise/7f7ca38846ebb2cb18e80e7c35ca353a/external/bazel_tools/tools/build_defs/pkg/pkg.bzl:196:9: pkg_tar: renaming non-dict `files` attribute to `srcs` WARNING: ~/.cache/bazel/_bazel_bitwise/7f7ca38846ebb2cb18e80e7c35ca353a/external/bazel_tools/tools/build_defs/pkg/pkg.bzl:196:9: pkg_tar: renaming non-dict `files` attribute to `srcs` WARNING: ~/.cache/bazel/_bazel_bitwise/7f7ca38846ebb2cb18e80e7c35ca353a/external/bazel_tools/tools/build_defs/pkg/pkg.bzl:196:9: pkg_tar: renaming non-dict `files` attribute to `srcs` WARNING: ~/.cache/bazel/_bazel_bitwise/7f7ca38846ebb2cb18e80e7c35ca353a/external/bazel_tools/tools/build_defs/pkg/pkg.bzl:196:9: pkg_tar: renaming non-dict `files` attribute to `srcs` Building: no action running |
接下来进行build,如下:
bazel build --jobs=6 --verbose_failures -c opt --copt=-mavx --copt=-mfpmath=both --copt=-msse4.2 //tensorflow:libtensorflow_cc.so




最新评论
博主好,路过留言交流一下~我在做源头中转 Twinkle Model(利益相关):GPT 1折、国模 1折(GLM/DeepSeek/Kimi)、满血 Claude,低价稳定。价格全在模型广场 https://big-model.smart-agi.com/model-plaza ,有兴趣可以看看。
博主分享的 Surge 增强模式接管应用分流思路很赞!确实,系统大版本升级后,老牌 Proxifier 由于底层驱动兼容性问题经常莫名崩溃。在 Mac 上有 Surge 这种神器接管,但是在 Windows 平台上,很多人又很难找到兼顾‘轻量分流+稳定不崩溃’的工具:ProxiFyre 依赖 WireSock 内核驱动容易蓝屏且纯命令行,开 TUN 虚拟网卡又会把开发网段和公司 VPN 改乱。 如果是 Windows 用户寻找 Proxifier 替代品,非常推荐关注 Ghost Proxifier Pro: - 纯用户态 Winsock API Hook:完全免安装内核驱动和虚拟网卡,零蓝屏隐患,不改动系统默认网关与路由表; - 智能递归子进程树:很多现代客户端(如播放器、流媒体套件、IDE)会派生子进程,它能自动递归识别并接管流量,杜绝漏代理; - 现代 Fluent 图形界面:直接拖入目标 exe 即可一键绑定 SOCKS5/HTTP 节点,比老版配置规则直观很多。 注:该工具为非开源的独立客户端软件。 - 官网主页:https://ghostproxifier.com - 项目发布:https://github.com/liliBestCoder/ghost-proxifier-pro
曾经最爱之一,还有emlog,zblog
感谢分享经验,谢谢站长!!已收藏
牛牛牛
同样
站长您好,亚马逊云咨询推广资源,望建立联系,可邮件,谢谢。
换友情链接吗?