简体   繁体   English

如何使用张量流在C ++中训练模型?

[英]How to train a model in C++ with tensorflow?

I tried to trained a experiment with deep learning model. 我试图用深度学习模型训练一个实验。 I found that tensorflow is the best way to do this. 我发现张量流是执行此操作的最佳方法。 But there is problem that tensorflow need to be writen in python. 但是有一个问题,需要用python编写tensorflow。 And my program contain many loops.Like this.. 而且我的程序包含很多循环。

for i=1~2000
 for j=1~2000

I know this is a big drawback for python. 我知道这是python的一大缺点。 It's very slow than c. 比c慢很多。 I know tensorfow has a C++ API, but it's not clear. 我知道tensorfow有一个C ++ API,但是还不清楚。 https://www.tensorflow.org/api_docs/cc/index.html (This is the worst Specification I have ever looked) Can someone give me an easy example in that? https://www.tensorflow.org/api_docs/cc/index.html (这是我看过的最糟糕的规范),有人可以给我一个简单的例子吗? All I need is two simple code. 我需要的只是两个简单的代码。 One is how to create a graph. 一种是如何创建图形。 The other is how to load this graph and run it. 另一个是如何加载此图并运行它。 I really eager need this.Hope someone can help me out. 我真的很需要这个。希望有人能帮助我。

It's not so easy, but it is possible. 这不是那么容易,但是有可能。 First, you need to create tensorflow graph in python and save it in file. 首先,您需要在python中创建tensorflow图并将其保存在文件中。 This article may help you 本文可能对您有帮助
https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f#.krslipabt https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f#.krslipabt

Second, you need to compile libtensorflow, link it to your program (you need tensorflow headers as well, so it's a bit tricky) and load the graph from the file. 其次,您需要编译libtensorflow,将其链接到您的程序(还需要tensorflow标头,因此有点棘手),然后从文件中加载图形。 This article may help you this time 这篇文章可能对您有帮助
https://medium.com/jim-fleming/loading-tensorflow-graphs-via-host-languages-be10fd81876f#.p9s69rn7u https://medium.com/jim-fleming/loading-tensorflow-graphs-via-host-languages-be10fd81876f#.p9s69rn7u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM