1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #19533 from TolyaTalamanov:at/async-requests-hotfix

[G-API] Async infer request hotfix

* Fix hanging on empty roi list

* Prevent possible data race

* Clean up
This commit is contained in:
Anatoliy Talamanov
2021-02-17 14:43:18 +03:00
committed by GitHub
parent 20d5d1c4c2
commit 413c056504
2 changed files with 141 additions and 26 deletions
+112 -8
View File
@@ -1112,10 +1112,7 @@ TEST(InferList, TestStreamingInfer)
// Load IE network, initialize input data using that.
cv::Mat in_mat;
std::vector<cv::Mat> ie_ages;
std::vector<cv::Mat> ie_genders;
std::vector<cv::Mat> gapi_ages;
std::vector<cv::Mat> gapi_genders;
std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
@@ -1206,10 +1203,7 @@ TEST(Infer2, TestStreamingInfer)
// Load IE network, initialize input data using that.
cv::Mat in_mat;
std::vector<cv::Mat> ie_ages;
std::vector<cv::Mat> ie_genders;
std::vector<cv::Mat> gapi_ages;
std::vector<cv::Mat> gapi_genders;
std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
@@ -1286,6 +1280,116 @@ TEST(Infer2, TestStreamingInfer)
pipeline.stop();
}
TEST(InferEmptyList, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::gapi::ie::detail::ParamDesc params;
params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
params.device_id = "CPU";
// Load IE network, initialize input data using that.
cv::Mat in_mat;
std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
// NB: Empty list of roi
std::vector<cv::Rect> roi_list;
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GArray<cv::Rect> roi;
cv::GArray<GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
std::size_t num_frames = 0u;
std::size_t max_frames = 1u;
cv::VideoCapture cap;
cap.open(filepath);
if (!cap.isOpened())
throw SkipTestException("Video file can not be opened");
cap >> in_mat;
auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
pipeline.setSource(
cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
pipeline.start();
while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
{
EXPECT_TRUE(gapi_ages.empty());
EXPECT_TRUE(gapi_genders.empty());
}
}
TEST(Infer2EmptyList, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::gapi::ie::detail::ParamDesc params;
params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
params.device_id = "CPU";
// Load IE network, initialize input data using that.
cv::Mat in_mat;
std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
// NB: Empty list of roi
std::vector<cv::Rect> roi_list;
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GMat in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
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" });
std::size_t num_frames = 0u;
std::size_t max_frames = 1u;
cv::VideoCapture cap;
cap.open(filepath);
if (!cap.isOpened())
throw SkipTestException("Video file can not be opened");
cap >> in_mat;
auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
pipeline.setSource(
cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
pipeline.start();
while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
{
EXPECT_TRUE(gapi_ages.empty());
EXPECT_TRUE(gapi_genders.empty());
}
}
} // namespace opencv_test
#endif // HAVE_INF_ENGINE