mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
Fix infer hanging
This commit is contained in:
parent
fcaeeac931
commit
e00cfe067d
@ -530,10 +530,11 @@ public:
|
|||||||
explicit RequestPool(std::vector<InferenceEngine::InferRequest>&& requests);
|
explicit RequestPool(std::vector<InferenceEngine::InferRequest>&& requests);
|
||||||
|
|
||||||
void execute(Task&& t);
|
void execute(Task&& t);
|
||||||
void waitAndShutdown();
|
void waitAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void callback(Task task, InferenceEngine::InferRequest& request, size_t id);
|
void callback(Task task, InferenceEngine::InferRequest& request, size_t id);
|
||||||
|
void setup();
|
||||||
|
|
||||||
QueueClass<size_t> m_idle_ids;
|
QueueClass<size_t> m_idle_ids;
|
||||||
std::vector<InferenceEngine::InferRequest> m_requests;
|
std::vector<InferenceEngine::InferRequest> m_requests;
|
||||||
@ -542,11 +543,15 @@ private:
|
|||||||
// RequestPool implementation //////////////////////////////////////////////
|
// RequestPool implementation //////////////////////////////////////////////
|
||||||
cv::gimpl::ie::RequestPool::RequestPool(std::vector<InferenceEngine::InferRequest>&& requests)
|
cv::gimpl::ie::RequestPool::RequestPool(std::vector<InferenceEngine::InferRequest>&& requests)
|
||||||
: m_requests(std::move(requests)) {
|
: m_requests(std::move(requests)) {
|
||||||
for (size_t i = 0; i < m_requests.size(); ++i) {
|
setup();
|
||||||
m_idle_ids.push(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cv::gimpl::ie::RequestPool::setup() {
|
||||||
|
for (size_t i = 0; i < m_requests.size(); ++i) {
|
||||||
|
m_idle_ids.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cv::gimpl::ie::RequestPool::execute(cv::gimpl::ie::RequestPool::Task&& t) {
|
void cv::gimpl::ie::RequestPool::execute(cv::gimpl::ie::RequestPool::Task&& t) {
|
||||||
size_t id = 0u;
|
size_t id = 0u;
|
||||||
m_idle_ids.pop(id);
|
m_idle_ids.pop(id);
|
||||||
@ -566,12 +571,13 @@ void cv::gimpl::ie::RequestPool::callback(cv::gimpl::ie::RequestPool::Task task,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NB: Not thread-safe.
|
// NB: Not thread-safe.
|
||||||
void cv::gimpl::ie::RequestPool::waitAndShutdown() {
|
void cv::gimpl::ie::RequestPool::waitAll() {
|
||||||
// NB: It will be blocked if at least one request is busy.
|
// NB: It will be blocked if at least one request is busy.
|
||||||
for (size_t i = 0; i < m_requests.size(); ++i) {
|
for (size_t i = 0; i < m_requests.size(); ++i) {
|
||||||
size_t id = 0u;
|
size_t id = 0u;
|
||||||
m_idle_ids.pop(id);
|
m_idle_ids.pop(id);
|
||||||
}
|
}
|
||||||
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GCPUExcecutable implementation //////////////////////////////////////////////
|
// GCPUExcecutable implementation //////////////////////////////////////////////
|
||||||
@ -632,7 +638,7 @@ void cv::gimpl::ie::GIEExecutable::run(cv::gimpl::GIslandExecutable::IInput &in
|
|||||||
if (cv::util::holds_alternative<cv::gimpl::EndOfStream>(in_msg))
|
if (cv::util::holds_alternative<cv::gimpl::EndOfStream>(in_msg))
|
||||||
{
|
{
|
||||||
// (3) Wait until all passed task are done.
|
// (3) Wait until all passed task are done.
|
||||||
m_reqPool->waitAndShutdown();
|
m_reqPool->waitAll();
|
||||||
out.post(cv::gimpl::EndOfStream{});
|
out.post(cv::gimpl::EndOfStream{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -671,7 +677,7 @@ void cv::gimpl::ie::GIEExecutable::run(cv::gimpl::GIslandExecutable::IInput &in
|
|||||||
// (5) In non-streaming mode need to wait until the all tasks are done
|
// (5) In non-streaming mode need to wait until the all tasks are done
|
||||||
// FIXME: Is there more graceful way to handle this case ?
|
// FIXME: Is there more graceful way to handle this case ?
|
||||||
if (!m_gm.metadata().contains<Streaming>()) {
|
if (!m_gm.metadata().contains<Streaming>()) {
|
||||||
m_reqPool->waitAndShutdown();
|
m_reqPool->waitAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2005,6 +2005,29 @@ TEST_F(InferWithReshapeNV12, TestInferListYUV)
|
|||||||
// Validate
|
// Validate
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ROIList, CallInferMultipleTimes)
|
||||||
|
{
|
||||||
|
cv::GArray<cv::Rect> rr;
|
||||||
|
cv::GMat in;
|
||||||
|
cv::GArray<cv::GMat> age, gender;
|
||||||
|
std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
|
||||||
|
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
|
||||||
|
|
||||||
|
auto pp = cv::gapi::ie::Params<AgeGender> {
|
||||||
|
params.model_path, params.weights_path, params.device_id
|
||||||
|
}.cfgOutputLayers({ "age_conv3", "prob" });
|
||||||
|
|
||||||
|
auto cc = comp.compile(cv::descr_of(cv::gin(m_in_mat, m_roi_list)),
|
||||||
|
cv::compile_args(cv::gapi::networks(pp)));
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
cc(cv::gin(m_in_mat, m_roi_list), cv::gout(m_out_gapi_ages, m_out_gapi_genders));
|
||||||
|
}
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace opencv_test
|
} // namespace opencv_test
|
||||||
|
|
||||||
#endif // HAVE_INF_ENGINE
|
#endif // HAVE_INF_ENGINE
|
||||||
|
Loading…
Reference in New Issue
Block a user