How to deploy a Tensorflow trained model for inference for a Windows standalone application

不羁岁月 提交于 2020-06-25 09:49:24

问题


I would like to use a model trained with Tensorflow in a Windows standalone desktop application. I only need to perform predictions, I can train the model with Tensorflow Python API. What is the recommended approach?

I know there is a C++ API, but it is really hard to compile it, especially on Windows. Can I find any prebuilt C++ Tensorflow binaries for Windows?

Is there an easy way to distribute Python with Tensorflow as a Windows installer prerequisite?

Can I import the Tensorflow model in another technology and use it for inference? OpenCv DNN module has a function which imports data from Tensorflow, but I understood it has many limitations, and I was not able to import and use a model with OpenCv.

Thanks for help!


回答1:


I was challenging the same issues as you. You should at least try to compile it (try CMake, it might be easier)

If you still having trouble:

  • Compiler is out of Heap Space
  • Standalone Windows Lib
  • Basic Tensorflow Handling with C++



回答2:


I asked a similar question and eventually found my own way to the answer. In the end, I found the Tensorflow instructions were actually pretty good (it was my reading them that was bad!). I have not tried using Bazel for Windows, but building Tensorflow using CMake ended up working fine.

The main issue was the compiler heap space issue. This always seems to occur in some random place if you are using the MS Visual Studio 32-bit compiler (default). The key is to make sure you run vcvarsall.bat or vcvars64.bat or whatever it takes to invoke the 64-bit compiler (in Task Manager, it should show up as cl.exe, not cl.exe *32) I found it hard (read: impossible) to get Visual Studio to use the 64-bit compiler, but using the MSBuild tool to compile on the command line worked fine.

Once you can build the example program, you have an example of an application that links to a static tensorflow library to do its stuff. You can just make your own application link to this library for what you want.



来源:https://stackoverflow.com/questions/48320402/how-to-deploy-a-tensorflow-trained-model-for-inference-for-a-windows-standalone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!