tradr-project / tensorflow_ros

Project moved to tensorflow_ros_cpp
https://github.com/tradr-project/tensorflow_ros_cpp
26 stars 10 forks source link

error: EIGEN_DEVICE_FUNC does not name a type #2

Closed rdube closed 7 years ago

rdube commented 7 years ago

Hi @peci1 thanks a lot for making this available! :)

I compiled tensorflow_ros and added it in the package.xml of my catkin package as depend.

Then I added these two includes in my file :

#include <tensorflow/core/public/session.h>
#include <tensorflow/core/platform/env.h>

And am getting this compilation error:

In file included from /usr/local/lib/python2.7/dist-packages/tensorflow/include/unsupported/Eigen/CXX11/../SpecialFunctions:46:0,
                 from /usr/local/lib/python2.7/dist-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:31,
                 from /usr/local/lib/python2.7/dist-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
                 from /usr/local/lib/python2.7/dist-packages/tensorflow/include/tensorflow/core/framework/tensor.h:19,
                 from /usr/local/lib/python2.7/dist-packages/tensorflow/include/tensorflow/core/public/session.h:23,
                 from /home/renaud/catkin_ws/src/segmatch_private/segmatch/src/descriptors/autoencoder.cpp:7:
/usr/local/lib/python2.7/dist-packages/tensorflow/include/unsupported/Eigen/CXX11/../src/SpecialFunctions/SpecialFunctionsImpl.h:82:3: error: EIGEN_DEVICE_FUNC does not name a type
   EIGEN_DEVICE_FUNC

Have you seen this before? Any idea?

rdube commented 7 years ago

I am using python version 2.7.6, tensorflow version 1.0.0-rc2 and gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4. Can the gcc version be the issue?

peci1 commented 7 years ago

I'd first try upgrading to gcc 4.9. It did not hurt anything on my Ubuntu 14.04.

And I use Tensorflow 1.1.0.

rdube commented 7 years ago

Thanks! It looks like the problem lays in having dependencies on two different eigen whereas your example does not use eigen. I will try building a simple non-eigen dependent package around your TensorflowGraphExecutor

peci1 commented 7 years ago

Yes, that's what I do (because of requirements for different Protobuf versions).

You basically build the graph executor standalone and use private (forward) declarations of everything from Tensorflow in the .h file, so that you no longer have to include the TF headers to use the executor class.

rdube commented 7 years ago

Ok it is now compiling! Now I just have to transfer all our preprocessing python code into c++ and cross my fingers that the model can actually be used! :-)

Thanks!

stomachacheGE commented 5 years ago

@peci1 could you please elaborate how did you solve the conflict by forward declaration? I tried the following:

// inference.cc
#include <"tensorflow/core/public/session.h">
class Inferencer {
    void infernce(); // where sess.run is called
}

// detector.cc
class Inferencer; // forward declaration
class Detector {
    void detector() {
       Inferencer inferencer;
       inferencer.inference() // this is not allowed because Inferencer has incomplete type
    }
}

As you will expect, inferencer.inference() will cause compiler error since Inferencer has incomplete type. How did you use forward declaration to solve this problem? Thanks in advance.

peci1 commented 5 years ago

@stomachacheGE You have to use PIMPL or a similar idiom: https://cpppatterns.com/patterns/pimpl.html . You cannot have a variable with incomplete type, but you can have a pointer to incomplete type (in PIMPL case a std::unique_ptr).