2

We have trained our models and tested them successfully using the provided Python scripts. However, we now want to deploy it on our website and run a web-service for the second round of tests.

Is there a C++ wrapper so that we can use to run/execute our models the same way we do with Python scripts?

halfer
  • 19,824
  • 17
  • 99
  • 186
Hossein
  • 24,202
  • 35
  • 119
  • 224
  • There is no specific api for object detection, but once you finish training, you can save model to `tf.GraphDef` or `tf.MetaGraphDef` format and then deploy it with tensorflow serving. – Jie.Zhou Oct 12 '17 at 07:37
  • @Jie.ZHou: Thank you, but I I guess tensorflow serving can be used with google clouds only! I'm looking for something with the least dependency needs. bunch of dlls and libs so that I can use it easily anywhere. something like Caffe, which was very handy in such cases. – Hossein Oct 12 '17 at 07:50
  • 1
    So basically you just want to use tensorflow with c++ ? In that case it's entirely possible of course ! You'll need to export your graph as explained in the object detection API, then run it in c++ like [this](https://stackoverflow.com/a/45031496/7456923) (in short) – gdelab Oct 12 '17 at 08:28
  • @gdelab: yes thats exactly it. I really appreciate your help – Hossein Oct 12 '17 at 08:43

2 Answers2

6

I think the easiest way is to use cppflow. It is a C++ wrapper for the TensorFlow C API. It is simple but really easy to use and you do not need to install it neither compiling with Bazel. You just have to download the C API and use it like this:

Model model("graph.pb");
model.restore("path/to/checkpoint");

auto input = new Tensor(model, "input");
auto output = new Tensor(model, "output");

model.run(input, output);
Mario García
  • 71
  • 1
  • 2
2

You'll find code to run object detection on C++ here. You'll need an exported graph (.pb format), that you can get using the TF object detection API.

The compilation used to be tricky (except if you put your project in the tensorflow directory and compile everything with bazel, but you might not want to do that). I think it's supposed to be easier now, but I don't know how; or you can follow these instructions to compile tensorflow on its own and use it in a cmake project. You have another example of runing a graph in c++ here.

gdelab
  • 6,124
  • 2
  • 26
  • 59