如何为Windows独立应用程序部署经过Tensorflow训练的模型以进行推理 [英] How to deploy a Tensorflow trained model for inference for a Windows standalone application

查看:354
本文介绍了如何为Windows独立应用程序部署经过Tensorflow训练的模型以进行推理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows独立桌面应用程序中使用经过Tensorflow训练的模型。我只需要执行预测,就可以使用Tensorflow Python API训练模型。推荐的方法是什么?

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?

我知道有C ++ API,但是很难编译,尤其是在Windows上。我可以找到用于Windows的任何预构建的C ++ Tensorflow二进制文件吗?

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?

是否可以使用Tensorflow作为Windows安装程序的先决条件来分发Python?

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

我可以在其他技术中导入Tensorflow模型并将其用于推理吗? OpenCv DNN模块具有从Tensorflow导入数据的功能,但我知道它有很多局限性,因此无法通过OpenCv导入和使用模型。

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.

谢谢寻求帮助!

推荐答案

我问了,并最终找到了自己的答案。最后,我发现 Tensorflow指令实际上非常好(我在阅读它们时发现太糟糕了!)。我没有尝试过将Bazel用于Windows,但是使用CMake构建Tensorflow最终可以正常工作。

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.

主要问题是编译器堆空间问题。如果您使用的是MS Visual Studio 32位编译器(默认),这似乎总是在某个随机位置发生。关键是要确保您运行 vcvarsall.bat vcvars64.bat 或调用64-位编译器(在任务管理器中,它应该显示为 cl.exe ,而不是 cl.exe * 32 )发现很难(阅读:不可能)使Visual Studio使用64位编译器,但是使用 MSBuild 工具在命令行上进行编译可以很好地工作。

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.

一旦您可以构建示例程序,您就有一个应用程序示例,该应用程序链接到静态tensorflow库以完成其工作。您可以根据自己的需要将自己的应用程序链接到该库。

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.

这篇关于如何为Windows独立应用程序部署经过Tensorflow训练的模型以进行推理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆