Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. It's very slow than c. I know tensorfow has a C++ API, but it's not clear. 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? 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.

like image 681
darren1231 Avatar asked May 27 '16 04:05

darren1231


Video Answer


1 Answers

It's not so easy, but it is possible. First, you need to create tensorflow graph in python and save it in file. This article may help you
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. This article may help you this time
https://medium.com/jim-fleming/loading-tensorflow-graphs-via-host-languages-be10fd81876f#.p9s69rn7u

like image 158
Anton Pechenko Avatar answered Oct 22 '22 09:10

Anton Pechenko