【问题标题】:Building Tensorflow C++ project outside the TensorFlow repo?在 TensorFlow 存储库之外构建 TensorFlow C++ 项目?
【发布时间】:2016-08-15 08:48:19
【问题描述】:

所以我安装了 Tensorflow as described hereOne of the answers 提到该项目必须在克隆的本地 TensorFlow 存储库中。有没有办法让项目在 repo 之外?

【问题讨论】:

  • 也许这样的事情可以帮助 - 使用这个键运行配置:./configure --prefix=/somewhere/else/than/usr/local
  • 对不起。我不确定你说的其他地方是什么意思。你是说我项目的目录吗?

标签: c++ compilation tensorflow


【解决方案1】:

据我所知,没有官方方法可以在 TF 存储库之外构建代码。但是,您可以使用 tensorflow_cc 项目,该项目为您构建和安装 TF C++ 库并提供方便的 CMake 目标以及所有必要的标头和链接参数。

【讨论】:

    【解决方案2】:

    是的,您只需要执行以下操作:

    1. 克隆 tensorflow 存储库

    2. ./configure 到您的链接(启用 CUDA 等)

    3. 使用bazel build 构建//tensorflow:libtensorflow.so//tensorflow:libtensorflow_cc.so

    4. 创建您自己的项目,在存储库之外链接到您刚刚编译的 .so:s,您在编译/链接时需要以下选项:

      -I/path/to/repo/tensorflow
      -L/path/to/repo/tensorflow/bazel-bin/tensorflow
      -ltensorflow_framework -ltensorflow_cc
      
    5. 您的.hpp.cpp 文件现在可以通过包含适当的头文件来使用tensorflow::Session 和其他类:

      #include "tensorflow/core/public/session.h"
      #include "tensorflow/cc/ops/standard_ops.h"
      

    您可能还需要(对于由 protobuf 编译器生成的标头 protoc):

    -I/path/to/repo/tensorflow/bazel-genfiles/
    

    以及依赖库(例如它抱怨nsync):

    -I/path/to/repo/tensorflow/bazel-tensorflow/external/nsync/public
    

    希望这有帮助。

    【讨论】:

      【解决方案3】:

      我已经使用 Cmake 和 Visual Studio 2015 成功构建了 tensorflow-gpu 动态库,现在我可以将项目放在 TF 存储库之外。

      1.git clone -b r1.7 --single-branch https://github.com/tensorflow/tensorflow.git

      2.Cmake并选择共享库和enable-gpu的选项

      3.使用 Visual Studio 2015 构建 tensorflow.dll 和 tensorflow.lib

      在构建过程中会出现一些错误,但很容易修复。 如果您希望了解详细信息,请发表评论。

      【讨论】:

        猜你喜欢
        • 2019-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多