问题
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