Search code examples
c++tensorflowcc

Tensorflow C++ r1.13 build error: 'TopK' is not a member of 'tensorflow::ops'


This is my first time trying to build a C++ Tensorflow project, and figuring out how to build TF libraries was already too much work so I used the github tensorflow_cc project, which provides a docker image with TF C++ api already built for Ubuntu 18.04.

This seemed like a great start but the compile fails with:

error: 'TopK' is not a member of 'tensorflow::ops'

on a line of code:

tensorflow::ops::TopK(root.WithOpName(output_name), outputs[0], how_many_labels);

However, according to the TF api doc TopK clearly is in the tensorflow::ops namespace. Now, before you say, go report this as an issue to the tensorflow_cc project, note that the doc says to

#include <nn_ops.h>

except nn_ops.h does not exist in the tensorflow repo at all! (According to github search and "find . -name nn_ops.h" in clones.) What does exist is "tensorflow/core/ops/nn_ops.cc".

I know this is a starter issue, and there must be some simple things I'm missing out on, but it's hard to understand this conflict between the API doc and the repo. The example code I'm trying to build has been built & run before, but I can't get any support for it. Anyone recently built TF C++ projects with TopK? Any suggestions for the best way to get started doing TF C++?


Solution

  • The tensorflow_cc project provides a static binding build environment and a shared library or dynamic binding environment (static or shared use of the built Tensorflow libs). I was trying to build the project with the floopcz/tensorflow_cc:ubuntu-static docker image, the static version. There was no problem building using the shared library image floopcz/tensorflow_cc:ubuntu-shared.

    @jdehesa I believe the required headers were generated as you suggest. See explanation here. However the Tensorflow API doc still seems to have a contradiction, since including nn_ops.h was not necessary.