- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When using std::promise
in Inference Request's callback function, I got a segmentation fault error. I tried to use std::shared_ptr
to manage the memory of this promise but also got this error.
Here is my code:
#include <iostream>
#include <string>
#include <future>
#include <openvino/openvino.hpp>
#include <opencv2/opencv.hpp>
std::string model_file = "test.onnx";
std::string image_file = "test.jpg";
ov::Core core;
ov::CompiledModel compiled_model;
ov::InferRequest infer_request;
cv::Mat blob;
std::shared_ptr<std::promise<ov::Tensor>> promise_ptr;
std::future<ov::Tensor> infer()
{
compiled_model = core.compile_model(model_file, "AUTO");
infer_request = compiled_model.create_infer_request();
cv::Mat img = cv::imread(image_file);
cv::Mat resized_img;
cv::resize(img, resized_img, cv::Size(416, 416));
blob = cv::dnn::blobFromImage(resized_img, 1 / 255.0, cv::Size(416, 416), cv::Scalar(0, 0, 0), true).clone();
auto input_port = compiled_model.input();
ov::Tensor input_tensor(input_port.get_element_type(), ov::Shape(std::vector<size_t>{1, 3, 416, 416}), blob.ptr(0));
infer_request.set_input_tensor(input_tensor);
promise_ptr = std::make_shared<std::promise<ov::Tensor>>();
infer_request.set_callback([&](std::exception_ptr ex_ptr)
{
promise_ptr->set_value(infer_request.get_output_tensor());
});
infer_request.start_async();
return promise_ptr->get_future();
}
int main(int argc, char* argv[]) {
std::cout << ov::get_openvino_version().description << ':' << ov::get_openvino_version().buildNumber << std::endl;
auto output = infer().get();
auto output_shape = output.get_shape();
std::cout << "The shape of output tensor:" << output_shape << std::endl;
cv::Mat output_buffer(output_shape[1], output_shape[2], CV_32F, output.data());
std::cout << output_buffer.size() << std::endl;
return 0;
}
When I run this code, it gets a segmentation fault
OpenVINO Runtime:2022.3.0-9052-9752fafe8eb-releases/2022/3 [1] 238814 segmentation fault (core dumped)
I have open an issue on github:
https://github.com/openvinotoolkit/openvino/issues/16543
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ericsic,
We noticed that your issue has been solved in GitHub discussion. Hence, we will close this thread as well.
Regards,
Peh

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page