简体   繁体   English

TensorFlow c ++ API在session-> run()崩溃

[英]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.

相关问题 耗时的Tensorflow C ++会话-&gt;运行-用于实时推理的图像 - Time Consuming Tensorflow C++ Session->Run - Images for Real-time Inference C ++ Tensorflow,如何使用多线程进行session-> Run(),或者花费更少的时间 - C++ Tensorflow, how to make session->Run() with multithread, or spend less time Tensorflow C ++ API:`Session :: Run`中的`fetch_outputs`和`run_outputs`之间的区别 - Tensorflow C++ API: Difference between `fetch_outputs` and `run_outputs` in `Session::Run` 如何使用Session :: Run(TensorFlow C ++ API)以批处理模式对样品进行基于CNN的分类 - How to use Session::Run (TensorFlow C++ API) to perform CNN based classification of samples in batch mode TensorFlow C ++ API中ClientSession和Session之间的区别 - Difference between ClientSession and Session in TensorFlow C++ API 为TensorFlow C ++ API的会话选择特定的GPU - Select specific gpu for the session of tensorflow c++ api 如何修复 Onnxruntime session-&gt;Run 问题? - How can i fix Onnxruntime session->Run problem? 张量流源代码中的c ++客户端会话和c_api TF_Session与core / public / session之间有什么关系? - what's the relation between c++ client session and c_api TF_Session and core/public/session in tensorflow source code? tensorflow和tflearn c ++ API - tensorflow and tflearn c++ API 带有 TensorRT 的 C++ Tensorflow API - C++ Tensorflow API with TensorRT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM