How to program with C++ API library on Windows using Bazel?

Viewed 2145

What I want to do

First of all, my goal is using Tensorflow C++ API as a library on Windows, which is part of my project, instead of building my project inside Tensorflow.

Background

I had achieved this by building Tensorflow with CMake. However, from Tensorflow 1.10, building with CMake was deprecated and Bazel is recommended instead. But the official way to use C++ API is building project inside Tensorflow with Bazel. Thus, this way is not good for me.

What I have done

To use a newer version of Tensorflow, I have been trying to build Tensorflow with Bazel as a standalone library.

Some maintainer denoted that it is possible by substituting //tensorflow/tools/pip_package:build_pip_package to //tensorflow:libtensorflow_cc.so in the official tutorial. But in fact I encountered some problems and solved them by reading this tutorial. Now I have successfully built libtensorflow_cc.so.

What the problem is

However, I have no idea what should be done next to use the built result. And it is exactly what my problem is. There is no documentation of course. Only some incomplete ideas on it I have found, and I will show all of them, trying to give you more information:

There must be someone struggling with similar problems like me. I hope this question can build a reservoir of ways to solve the problem.

1 Answers

It's over 2 years since this question was asked, and the news is not good: it seems there are insufficient people with Windows skills in a position to provide the support to integrate Tensorflow into Windows applications using the familiar headers + library model. And Tensorflow advances week by week, meaning that the Windows support falls further behind.

In my assessment, the path to building on Windows is currently blocked due to inadequate documentation. It's not so much that "There is no documentation of course" as the OP asserts, it's that the sparse documentation is distributed throughout dozens of separate posts, each of which dates rapidly with the continuing development of the Tensorflow along paths other than Windows C++.

I originally gave this answer to a similar question, but updated it with advice along the following lines yesterday:

  • Windows is a Microsoft product, so watch what Microsoft is doing
  • You can implement your (ONNX) model on Windows in C++ in at least 3 ways:
    • Windows ML (uses Onnx runtime)
    • Onnx runtime (supports DirectML as an execution provider)
    • DirectML (how Microsoft uses graphics cards to boost performance)

We don't have the latest or best hardware (e.g. we have Intel graphics cards), but have been able to get a solution based on Onnx runtime that classifies 224 x 224 RGB images in about 20 milliseconds for us. We found the Windows ML path much more difficult to work with legacy code, and also slower to run.

Related