“不支持/Eigen/CXX11/Tensor:没有这样的文件或目录"在使用 TensorFlow 时 [英] "unsupported/Eigen/CXX11/Tensor: No such file or directory" while working with TensorFlow

查看:175
本文介绍了“不支持/Eigen/CXX11/Tensor:没有这样的文件或目录"在使用 TensorFlow 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 C++ 应用程序中使用 tensorflow 作为外部库(主要遵循 本教程).到目前为止我做了什么:

I'm trying to use tensorflow as a external library in my C++ application (mainly following this tutorial). What I done so far:

  1. 我已经克隆了 tensorflow 存储库(假设存储库根目录是 $TENSORFLOW)
  2. 运行 /.configure(所有设置默认,所以没有 CUDA,没有 OpenCL 等).
  3. 使用 bazel build -c/opt//tensorflow:libtensorflow_cc.so 构建共享库(构建成功完成)
  4. 现在我正在尝试 #include "tensorflow/core/public/session.h".但是在包含它之后(并添加 $TENSORFLOW$TENSORFLOW/bazel-genfiles 以包含路径),我收到错误:

  1. I have cloned the tensorflow reporitory (let's say, that the repo root dir is $TENSORFLOW)
  2. Run /.configure (which all settings default, so no CUDA, no OpenCL etc.).
  3. Build shared library with bazel build -c /opt //tensorflow:libtensorflow_cc.so (build completed successfully)
  4. Now I'm trying to #include "tensorflow/core/public/session.h". But after including it (and adding $TENSORFLOW and $TENSORFLOW/bazel-genfiles to include path), I'm receiving error:

$TENSORFLOW/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42:
fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory

为类似问题创建了一个 github 问题,但它被标记为关闭而没有提供的任何解决方案.我还尝试了 master 分支以及 v.1.4.0 版本.

There is a github issue created for similar problem, but it's marked as closed without any solution provided. Also I tried with master branch as well as v.1.4.0 release.

您是否知道会导致此类问题的原因以及如何处理?

Do you happen to know, what could cause this kind of problem and how to deal with it?

推荐答案

我(和许多其他人)为同样的问题苦恼.它可能可以使用 bazel 解决,但我不太了解该工具,现在我使用 make 解决了这个问题.混淆的根源在于包含了一个名为 Tensor 的文件,并且它本身包含了一个名为 Tensor 的文件,从而导致一些人错误地得出 Tensor 包含自身的结论.

I (and many others) agonized over the same problem. It probably can be solved using bazel but I don't know that tool well enough and now I solve this using make. The source of confusion is that a file named Tensor is included and it itself includes a file named Tensor, which has caused some people to wrongly conclude Tensor is including itself.

如果您构建并安装了 python .whl 文件,那么 dist-packages 中将有一个 tensorflow 目录和一个包含目录,例如在我的系统上:

If you built and installed the python .whl file there will be a tensorflow directory in dist-packages and an include directory below that, e.g. on my system:

/usr/local/lib/python2.7/dist-packages/tensorflow/include

从包含目录

find . -type f -name 'Tensor' -print
./third_party/eigen3/unsupported/Eigen/CXX11/Tensor
./external/eigen_archive/unsupported/Eigen/CXX11/Tensor

第一个有

#include "unsupported/Eigen/CXX11/Tensor"

应该满足这个条件的文件是第二个.

and the file that should satisfy this is the second one.

因此要编译包含 session.h 的 session.cc,以下将起作用

So to compile session.cc that includes session.h, the following will work

INC_TENS1=/usr/local/lib/python2.7/dist-packages/tensorflow/include/
INC_TENS2=${INC_TENS1}external/eigen_archive/
gcc -c -std=c++11 -I $INC_TENS1 -I $INC_TENS2 session.cc

我看到有人声称您必须从 tensorflow 树构建应用程序并且必须使用 bazel.但是,我相信您需要的所有头文件都在 dist-packages/tensorflow/include 中,至少对于初学者来说,您可以构建 makefile 或 cmake 项目.

I've seen claims that you must build apps from the tensorflow tree and you must use bazel. However, I believe all the header files you need are in dist-packages/tensorflow/include and at least for starters you can construct makefile or cmake projects.

这篇关于“不支持/Eigen/CXX11/Tensor:没有这样的文件或目录"在使用 TensorFlow 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆