Export the Python TensorFlow model and import it in C ++

I followed this tutorial and tried to change it for my needs. I have a python file where I train the model and save the TensorFlow graph and frozen_graph, which should have weight and architecture. And I have a C ++ file where I read the frozen_graph file and try to predict an example.

// The session will initialize the outputs vector<Tensor> outputs; // Run the session, evaluating our "softmax" operation from the graph status = session->Run(inputs, {"output_TT"}, {}, &outputs); int nHits = 0; int nClasses = 2; for (vector<Tensor>::iterator it = outputs.begin(); it != outputs.end(); ++it) { auto items = it->shaped<float, 2>({nTests, nClasses}); // 2 represent number of class for (int i = 0; i < nTests; i++) { int arg_max = 0; float val_max = items(i, 0); 

but when I try to get the results from the predictions, I get NaN from items(i, 0)

Here are all the files on github:

Am I saving the frozen_graph file incorrectly? I also created a frozen chart on the command line with bazel, but got the same effect. Am I reading data in C ++ incorrectly?

+5
source share

Source: https://habr.com/ru/post/1265510/


All Articles