[英]TensorFlow c++ API crashes on session->run()
I am writing a Tensorflow c++ code to check if a sequence of images that i receive on the server falls into a "true" category or a "false" one. 我正在编写Tensorflow c ++代码来检查我在服务器上收到的图像序列是否属于“真实”类别或“假”类别。 i have trained the model using python and generated a .pb file for the model.
我使用python训练了模型,并为模型生成了一个.pb文件。
Now I am loading the model into c++ and passing images from a vector that i receive from a connection to it using the following code: 现在我将模型加载到c ++中,并使用以下代码从我从连接接收的向量传递图像:
for (int iLSP = 0; iLSP < LSPs.size(); iLSP++)
{
Mat image1 []= {LSPs[iLSP], LSPs[iLSP], LSPs[iLSP]};
Mat image;
merge(image1,3,image);
image.convertTo(image, CV_32FC1);
image = image / 255.0;
resize(image, image, Size(Width, Height));
Tensor image_tensor(DT_FLOAT, TensorShape({1,Width,Height,3}));
StringPiece tmp_data = image_tensor.tensor_data();
memcpy(const_cast<char*>(tmp_data.data()), (image.data), Height * Width * sizeof(float));
Session *sess;
SessionOptions options;
TF_CHECK_OK(NewSession(options, &sess));
GraphDef graph_def;
TF_CHECK_OK(ReadBinaryProto(Env::Default(), "models/model.pb", &graph_def));
TF_CHECK_OK(sess->Create(graph_def));
std::vector<std::pair<string, tensorflow::Tensor>> inputs = {{"x", image_tensor }};
std::vector<tensorflow::Tensor> outputs;
Status status = sess->Run(inputs, {"y_pred"}, {}, &outputs);
if (!status.ok())
{
cout<<"Error: "<<status.ToString()<<endl;
}
auto output_mapped = outputs[0].tensor<float, 2>();
totalFalse += output_mapped(0);
totalTrue += output_mapped(1);
sess->Close();
image.release();
}
The code compiles and run. 代码编译并运行。 The issue is after a number of connection to the server and receiving several image sequences, the code crashes without any error output or indication why it crashed (not even a segmentation fault).
问题是在与服务器连接多次并接收多个图像序列之后,代码崩溃而没有任何错误输出或指示它崩溃的原因(甚至不是分段错误)。
Did a "cout" on each of the lines to check where the code is crashing and apparrently it happens on the following line: 在每一行上都有一个“cout”来检查代码崩溃的位置,并且显然它发生在以下行:
Status status = sess->Run(inputs, {"y_pred"}, {}, &outputs);
Is there a why to debug what is happening inside the sess->run? 有没有什么可以调试sess-> run中发生的事情? as the code is not even filling the status variable to get an idea!.
因为代码甚至没有填充状态变量来获得一个想法! also is there a way to get an exception thrown form the session run?
也有办法从会话运行中获得异常抛出? as i already mentioned this will be a server code and at least if the session->run is not working i can catch the exception while keeping the program running and not crash the full server
正如我已经提到过的,这将是一个服务器代码,至少如果session-> run不工作,我可以在保持程序运行的同时捕获异常并且不会使整个服务器崩溃
在exit()
, _exit()
exit()
和terminate()
函数上设置断点并运行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.