1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2019-2020 Intel Corporation
6 
7 #include "../test_precomp.hpp"
8 
9 #ifdef HAVE_INF_ENGINE
10 
11 #include <stdexcept>
12 
13 #include <inference_engine.hpp>
14 
15 #include <ade/util/iota_range.hpp>
16 
17 #include <opencv2/gapi/infer/ie.hpp>
18 #include <opencv2/gapi/streaming/cap.hpp>
19 
20 #include "backends/ie/util.hpp"
21 #include "backends/ie/giebackend/giewrapper.hpp"
22 
23 namespace opencv_test
24 {
25 namespace {
initTestDataPath()26 void initTestDataPath()
27 {
28 #ifndef WINRT
29     static bool initialized = false;
30     if (!initialized)
31     {
32         // Since G-API has no own test data (yet), it is taken from the common space
33         const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
34         if (testDataPath) {
35             cvtest::addDataSearchPath(testDataPath);
36         }
37         initialized = true;
38     }
39 #endif // WINRT
40 }
41 
42 class TestMediaBGR final: public cv::MediaFrame::IAdapter {
43     cv::Mat m_mat;
44     using Cb = cv::MediaFrame::View::Callback;
45     Cb m_cb;
46 
47 public:
__anon97dabe5e0202()48     explicit TestMediaBGR(cv::Mat m, Cb cb = [](){})
49         : m_mat(m), m_cb(cb) {
50     }
meta() const51     cv::GFrameDesc meta() const override {
52         return cv::GFrameDesc{cv::MediaFormat::BGR, cv::Size(m_mat.cols, m_mat.rows)};
53     }
access(cv::MediaFrame::Access)54     cv::MediaFrame::View access(cv::MediaFrame::Access) override {
55         cv::MediaFrame::View::Ptrs pp = { m_mat.ptr(), nullptr, nullptr, nullptr };
56         cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
57         return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
58     }
blobParams() const59     cv::util::any blobParams() const override {
60         return std::make_pair<InferenceEngine::TensorDesc,
61                               InferenceEngine::ParamMap>({IE::Precision::U8,
62                                                           {1, 3, 300, 300},
63                                                           IE::Layout::NCHW},
64                                                          {{"HELLO", 42},
65                                                           {"COLOR_FORMAT",
66                                                            InferenceEngine::ColorFormat::NV12}});
67     }
68 };
69 
70 class TestMediaNV12 final: public cv::MediaFrame::IAdapter {
71     cv::Mat m_y;
72     cv::Mat m_uv;
73 public:
TestMediaNV12(cv::Mat y,cv::Mat uv)74     TestMediaNV12(cv::Mat y, cv::Mat uv) : m_y(y), m_uv(uv) {
75     }
meta() const76     cv::GFrameDesc meta() const override {
77         return cv::GFrameDesc{cv::MediaFormat::NV12, cv::Size(m_y.cols, m_y.rows)};
78     }
access(cv::MediaFrame::Access)79     cv::MediaFrame::View access(cv::MediaFrame::Access) override {
80         cv::MediaFrame::View::Ptrs pp = {
81             m_y.ptr(), m_uv.ptr(), nullptr, nullptr
82         };
83         cv::MediaFrame::View::Strides ss = {
84             m_y.step, m_uv.step, 0u, 0u
85         };
86         return cv::MediaFrame::View(std::move(pp), std::move(ss));
87     }
88 };
89 
90 // FIXME: taken from DNN module
initDLDTDataPath()91 static void initDLDTDataPath()
92 {
93 #ifndef WINRT
94     static bool initialized = false;
95     if (!initialized)
96     {
97         const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH");
98         if (omzDataPath)
99             cvtest::addDataSearchPath(omzDataPath);
100         const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH");
101         if (dnnDataPath) {
102             // Add the dnnDataPath itself - G-API is using some images there directly
103             cvtest::addDataSearchPath(dnnDataPath);
104             cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models"));
105         }
106         initialized = true;
107     }
108 #endif // WINRT
109 }
110 
111 #if INF_ENGINE_RELEASE >= 2020010000
112 static const std::string SUBDIR = "intel/age-gender-recognition-retail-0013/FP32/";
113 #else
114 static const std::string SUBDIR = "Retail/object_attributes/age_gender/dldt/";
115 #endif
116 
117 // FIXME: taken from the DNN module
normAssert(cv::InputArray ref,cv::InputArray test,const char * comment,double l1=0.00001,double lInf=0.0001)118 void normAssert(cv::InputArray ref, cv::InputArray test,
119                 const char *comment /*= ""*/,
120                 double l1 = 0.00001, double lInf = 0.0001)
121 {
122     double normL1 = cvtest::norm(ref, test, cv::NORM_L1) / ref.getMat().total();
123     EXPECT_LE(normL1, l1) << comment;
124 
125     double normInf = cvtest::norm(ref, test, cv::NORM_INF);
126     EXPECT_LE(normInf, lInf) << comment;
127 }
128 
129 namespace IE = InferenceEngine;
130 
setNetParameters(IE::CNNNetwork & net,bool is_nv12=false)131 void setNetParameters(IE::CNNNetwork& net, bool is_nv12 = false) {
132     auto ii = net.getInputsInfo().at("data");
133     ii->setPrecision(IE::Precision::U8);
134     ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
135     if (is_nv12) {
136         ii->getPreProcess().setColorFormat(IE::ColorFormat::NV12);
137     }
138 }
139 
140 } // anonymous namespace
141 
142 // TODO: Probably DNN/IE part can be further parametrized with a template
143 // NOTE: here ".." is used to leave the default "gapi/" search scope
TEST(TestAgeGenderIE,InferBasicTensor)144 TEST(TestAgeGenderIE, InferBasicTensor)
145 {
146     initDLDTDataPath();
147 
148     cv::gapi::ie::detail::ParamDesc params;
149     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
150     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
151     params.device_id = "CPU";
152 
153     // Load IE network, initialize input data using that.
154     cv::Mat in_mat;
155     cv::Mat gapi_age, gapi_gender;
156 
157     IE::Blob::Ptr ie_age, ie_gender;
158     {
159         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
160         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
161         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
162         auto infer_request = this_network.CreateInferRequest();
163 
164         const auto &iedims = net.getInputsInfo().begin()->second->getTensorDesc().getDims();
165               auto  cvdims = cv::gapi::ie::util::to_ocv(iedims);
166         in_mat.create(cvdims, CV_32F);
167         cv::randu(in_mat, -1, 1);
168 
169         infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
170         infer_request.Infer();
171         ie_age    = infer_request.GetBlob("age_conv3");
172         ie_gender = infer_request.GetBlob("prob");
173     }
174 
175     // Configure & run G-API
176     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
177     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
178 
179     cv::GMat in;
180     cv::GMat age, gender;
181     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
182     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
183 
184     auto pp = cv::gapi::ie::Params<AgeGender> {
185         params.model_path, params.weights_path, params.device_id
186     }.cfgOutputLayers({ "age_conv3", "prob" });
187     comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
188                cv::compile_args(cv::gapi::networks(pp)));
189 
190     // Validate with IE itself (avoid DNN module dependency here)
191     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
192     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
193 }
194 
TEST(TestAgeGenderIE,InferBasicImage)195 TEST(TestAgeGenderIE, InferBasicImage)
196 {
197     initDLDTDataPath();
198 
199     cv::gapi::ie::detail::ParamDesc params;
200     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
201     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
202     params.device_id = "CPU";
203 
204     // FIXME: Ideally it should be an image from disk
205     // cv::Mat in_mat = cv::imread(findDataFile("grace_hopper_227.png"));
206     cv::Mat in_mat(cv::Size(320, 240), CV_8UC3);
207     cv::randu(in_mat, 0, 255);
208 
209     cv::Mat gapi_age, gapi_gender;
210 
211     // Load & run IE network
212     IE::Blob::Ptr ie_age, ie_gender;
213     {
214         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
215         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
216         setNetParameters(net);
217         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
218         auto infer_request = this_network.CreateInferRequest();
219         infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
220         infer_request.Infer();
221         ie_age    = infer_request.GetBlob("age_conv3");
222         ie_gender = infer_request.GetBlob("prob");
223     }
224 
225     // Configure & run G-API
226     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
227     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
228 
229     cv::GMat in;
230     cv::GMat age, gender;
231     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
232     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
233 
234     auto pp = cv::gapi::ie::Params<AgeGender> {
235         params.model_path, params.weights_path, params.device_id
236     }.cfgOutputLayers({ "age_conv3", "prob" });
237     comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
238                cv::compile_args(cv::gapi::networks(pp)));
239 
240     // Validate with IE itself (avoid DNN module dependency here)
241     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
242     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
243 }
244 
245 struct InferWithReshape: public ::testing::Test {
246     cv::gapi::ie::detail::ParamDesc params;
247     cv::Mat m_in_mat;
248     std::vector<cv::Rect> m_roi_list;
249     std::vector<size_t> reshape_dims;
250     std::vector<cv::Mat> m_out_ie_ages;
251     std::vector<cv::Mat> m_out_ie_genders;
252     std::vector<cv::Mat> m_out_gapi_ages;
253     std::vector<cv::Mat> m_out_gapi_genders;
254     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
255     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
256 
257     InferenceEngine::CNNNetwork net;
258     InferenceEngine::Core plugin;
259 
InferWithReshapeopencv_test::InferWithReshape260     InferWithReshape() {
261         // FIXME: it must be cv::imread(findDataFile("../dnn/grace_hopper_227.png", false));
262         m_in_mat = cv::Mat(cv::Size(320, 240), CV_8UC3);
263         cv::randu(m_in_mat, 0, 255);
264 
265         m_out_gapi_ages.resize(1);
266         m_out_gapi_genders.resize(1);
267 
268         // both ROIs point to the same face, with a slightly changed geometry
269         m_roi_list = {
270             cv::Rect(cv::Point{64, 60}, cv::Size{ 96,  96}),
271             cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
272         };
273 
274         // New dimensions for "data" input
275         reshape_dims = {1, 3, 70, 70};
276 
277         initDLDTDataPath();
278         params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
279         params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
280 
281         params.device_id = "CPU";
282 
283         plugin = cv::gimpl::ie::wrap::getPlugin(params);
284         net    = cv::gimpl::ie::wrap::readNetwork(params);
285         setNetParameters(net);
286         net.reshape({{"data", reshape_dims}});
287     }
288 
inferROIsopencv_test::InferWithReshape289     void inferROIs(IE::Blob::Ptr blob) {
290         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
291         auto infer_request = this_network.CreateInferRequest();
292         for (auto &&rc : m_roi_list) {
293             const auto ie_rc = IE::ROI {
294                 0u
295                 , static_cast<std::size_t>(rc.x)
296                 , static_cast<std::size_t>(rc.y)
297                 , static_cast<std::size_t>(rc.width)
298                 , static_cast<std::size_t>(rc.height)
299             };
300             infer_request.SetBlob("data", IE::make_shared_blob(blob, ie_rc));
301             infer_request.Infer();
302             using namespace cv::gapi::ie::util;
303             m_out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
304             m_out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
305         }
306     }
307 
inferopencv_test::InferWithReshape308     void infer(cv::Mat& in, const bool with_roi = false) {
309         if (!with_roi) {
310             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
311             auto infer_request = this_network.CreateInferRequest();
312             infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in));
313             infer_request.Infer();
314             using namespace cv::gapi::ie::util;
315             m_out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
316             m_out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
317         } else {
318             auto frame_blob = cv::gapi::ie::util::to_ie(in);
319             inferROIs(frame_blob);
320         }
321     }
322 
validateopencv_test::InferWithReshape323     void validate() {
324         // Validate with IE itself (avoid DNN module dependency here)
325         GAPI_Assert(!m_out_gapi_ages.empty());
326         ASSERT_EQ(m_out_gapi_genders.size(), m_out_gapi_ages.size());
327         ASSERT_EQ(m_out_gapi_ages.size(), m_out_ie_ages.size());
328         ASSERT_EQ(m_out_gapi_genders.size(), m_out_ie_genders.size());
329 
330         const size_t size = m_out_gapi_ages.size();
331         for (size_t i = 0; i < size; ++i) {
332             normAssert(m_out_ie_ages   [i], m_out_gapi_ages   [i], "Test age output");
333             normAssert(m_out_ie_genders[i], m_out_gapi_genders[i], "Test gender output");
334         }
335     }
336 }; // InferWithReshape
337 
338 struct InferWithReshapeNV12: public InferWithReshape {
339     cv::Mat m_in_uv;
340     cv::Mat m_in_y;
SetUpopencv_test::InferWithReshapeNV12341     void SetUp() {
342         cv::Size sz{320, 240};
343         m_in_y = cv::Mat{sz, CV_8UC1};
344         cv::randu(m_in_y, 0, 255);
345         m_in_uv = cv::Mat{sz / 2, CV_8UC2};
346         cv::randu(m_in_uv, 0, 255);
347         setNetParameters(net, true);
348         net.reshape({{"data", reshape_dims}});
349         auto frame_blob = cv::gapi::ie::util::to_ie(m_in_y, m_in_uv);
350         inferROIs(frame_blob);
351     }
352 };
353 
354 struct ROIList: public ::testing::Test {
355     cv::gapi::ie::detail::ParamDesc params;
356 
357     cv::Mat m_in_mat;
358     std::vector<cv::Rect> m_roi_list;
359 
360     std::vector<cv::Mat> m_out_ie_ages;
361     std::vector<cv::Mat> m_out_ie_genders;
362 
363     std::vector<cv::Mat> m_out_gapi_ages;
364     std::vector<cv::Mat> m_out_gapi_genders;
365 
366     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
367     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
368 
SetUpopencv_test::ROIList369     void SetUp() {
370         initDLDTDataPath();
371         params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
372         params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
373         params.device_id = "CPU";
374 
375         // FIXME: it must be cv::imread(findDataFile("../dnn/grace_hopper_227.png", false));
376         m_in_mat = cv::Mat(cv::Size(320, 240), CV_8UC3);
377         cv::randu(m_in_mat, 0, 255);
378 
379         // both ROIs point to the same face, with a slightly changed geometry
380         m_roi_list = {
381             cv::Rect(cv::Point{64, 60}, cv::Size{ 96,  96}),
382             cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
383         };
384 
385         // Load & run IE network
386         {
387             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
388             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
389             setNetParameters(net);
390             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
391             auto infer_request = this_network.CreateInferRequest();
392             auto frame_blob = cv::gapi::ie::util::to_ie(m_in_mat);
393 
394             for (auto &&rc : m_roi_list) {
395                 const auto ie_rc = IE::ROI {
396                     0u
397                     , static_cast<std::size_t>(rc.x)
398                     , static_cast<std::size_t>(rc.y)
399                     , static_cast<std::size_t>(rc.width)
400                     , static_cast<std::size_t>(rc.height)
401                 };
402                 infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
403                 infer_request.Infer();
404 
405                 using namespace cv::gapi::ie::util;
406                 m_out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
407                 m_out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
408             }
409         } // namespace IE = ..
410     } // ROIList()
411 
validateopencv_test::ROIList412     void validate() {
413         // Validate with IE itself (avoid DNN module dependency here)
414         ASSERT_EQ(2u, m_out_ie_ages.size());
415         ASSERT_EQ(2u, m_out_ie_genders.size());
416         ASSERT_EQ(2u, m_out_gapi_ages.size());
417         ASSERT_EQ(2u, m_out_gapi_genders.size());
418 
419         normAssert(m_out_ie_ages   [0], m_out_gapi_ages   [0], "0: Test age output");
420         normAssert(m_out_ie_genders[0], m_out_gapi_genders[0], "0: Test gender output");
421         normAssert(m_out_ie_ages   [1], m_out_gapi_ages   [1], "1: Test age output");
422         normAssert(m_out_ie_genders[1], m_out_gapi_genders[1], "1: Test gender output");
423     }
424 }; // ROIList
425 
426 struct ROIListNV12: public ::testing::Test {
427     cv::gapi::ie::detail::ParamDesc params;
428 
429     cv::Mat m_in_uv;
430     cv::Mat m_in_y;
431     std::vector<cv::Rect> m_roi_list;
432 
433     std::vector<cv::Mat> m_out_ie_ages;
434     std::vector<cv::Mat> m_out_ie_genders;
435 
436     std::vector<cv::Mat> m_out_gapi_ages;
437     std::vector<cv::Mat> m_out_gapi_genders;
438 
439     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
440     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
441 
SetUpopencv_test::ROIListNV12442     void SetUp() {
443         initDLDTDataPath();
444         params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
445         params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
446         params.device_id = "CPU";
447 
448         cv::Size sz{320, 240};
449         m_in_y = cv::Mat{sz, CV_8UC1};
450         cv::randu(m_in_y, 0, 255);
451         m_in_uv = cv::Mat{sz / 2, CV_8UC2};
452         cv::randu(m_in_uv, 0, 255);
453 
454         // both ROIs point to the same face, with a slightly changed geometry
455         m_roi_list = {
456             cv::Rect(cv::Point{64, 60}, cv::Size{ 96,  96}),
457             cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
458         };
459 
460         // Load & run IE network
461         {
462             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
463             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
464             setNetParameters(net, true);
465             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
466             auto infer_request = this_network.CreateInferRequest();
467             auto frame_blob = cv::gapi::ie::util::to_ie(m_in_y, m_in_uv);
468 
469             for (auto &&rc : m_roi_list) {
470                 const auto ie_rc = IE::ROI {
471                     0u
472                         , static_cast<std::size_t>(rc.x)
473                         , static_cast<std::size_t>(rc.y)
474                         , static_cast<std::size_t>(rc.width)
475                         , static_cast<std::size_t>(rc.height)
476                 };
477                 infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
478                 infer_request.Infer();
479 
480                 using namespace cv::gapi::ie::util;
481                 m_out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
482                 m_out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
483             }
484         } // namespace IE = ..
485     } // ROIList()
486 
validateopencv_test::ROIListNV12487     void validate() {
488         // Validate with IE itself (avoid DNN module dependency here)
489         ASSERT_EQ(2u, m_out_ie_ages.size());
490         ASSERT_EQ(2u, m_out_ie_genders.size());
491         ASSERT_EQ(2u, m_out_gapi_ages.size());
492         ASSERT_EQ(2u, m_out_gapi_genders.size());
493 
494         normAssert(m_out_ie_ages   [0], m_out_gapi_ages   [0], "0: Test age output");
495         normAssert(m_out_ie_genders[0], m_out_gapi_genders[0], "0: Test gender output");
496         normAssert(m_out_ie_ages   [1], m_out_gapi_ages   [1], "1: Test age output");
497         normAssert(m_out_ie_genders[1], m_out_gapi_genders[1], "1: Test gender output");
498     }
499 };
500 
501 struct SingleROI: public ::testing::Test {
502     cv::gapi::ie::detail::ParamDesc params;
503 
504     cv::Mat m_in_mat;
505     cv::Rect m_roi;
506 
507     cv::Mat m_out_gapi_age;
508     cv::Mat m_out_gapi_gender;
509 
510     cv::Mat m_out_ie_age;
511     cv::Mat m_out_ie_gender;
512 
SetUpopencv_test::SingleROI513     void SetUp() {
514         initDLDTDataPath();
515         params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
516         params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
517         params.device_id = "CPU";
518 
519         // FIXME: it must be cv::imread(findDataFile("../dnn/grace_hopper_227.png", false));
520         m_in_mat = cv::Mat(cv::Size(320, 240), CV_8UC3);
521         cv::randu(m_in_mat, 0, 255);
522 
523         m_roi = cv::Rect(cv::Point{64, 60}, cv::Size{96, 96});
524 
525         // Load & run IE network
526         IE::Blob::Ptr ie_age, ie_gender;
527         {
528             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
529             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
530             setNetParameters(net);
531             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
532             auto infer_request = this_network.CreateInferRequest();
533 
534             const auto ie_rc = IE::ROI {
535                     0u
536                     , static_cast<std::size_t>(m_roi.x)
537                     , static_cast<std::size_t>(m_roi.y)
538                     , static_cast<std::size_t>(m_roi.width)
539                     , static_cast<std::size_t>(m_roi.height)
540             };
541 
542             IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(m_in_mat), ie_rc);
543             infer_request.SetBlob("data", roi_blob);
544             infer_request.Infer();
545 
546             using namespace cv::gapi::ie::util;
547             m_out_ie_age    = to_ocv(infer_request.GetBlob("age_conv3")).clone();
548             m_out_ie_gender = to_ocv(infer_request.GetBlob("prob")).clone();
549         }
550     }
551 
validateopencv_test::SingleROI552     void validate() {
553         // Validate with IE itself (avoid DNN module dependency here)
554         normAssert(m_out_ie_age   , m_out_gapi_age   , "Test age output");
555         normAssert(m_out_ie_gender, m_out_gapi_gender, "Test gender output");
556     }
557 };
558 
559 struct SingleROINV12: public ::testing::Test {
560     cv::gapi::ie::detail::ParamDesc params;
561 
562     cv::Mat m_in_y;
563     cv::Mat m_in_uv;
564     cv::Rect m_roi;
565 
566     cv::Mat m_out_gapi_age;
567     cv::Mat m_out_gapi_gender;
568 
569     cv::Mat m_out_ie_age;
570     cv::Mat m_out_ie_gender;
571 
SetUpopencv_test::SingleROINV12572     void SetUp() {
573         initDLDTDataPath();
574         params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
575         params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
576         params.device_id = "CPU";
577 
578         cv::Size sz{320, 240};
579         m_in_y = cv::Mat{sz, CV_8UC1};
580         cv::randu(m_in_y, 0, 255);
581         m_in_uv = cv::Mat{sz / 2, CV_8UC2};
582         cv::randu(m_in_uv, 0, 255);
583 
584         m_roi = cv::Rect(cv::Point{64, 60}, cv::Size{96, 96});
585 
586         // Load & run IE network
587         IE::Blob::Ptr ie_age, ie_gender;
588         {
589             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
590             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
591             setNetParameters(net, /* NV12 */ true);
592             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
593             auto infer_request = this_network.CreateInferRequest();
594             auto blob = cv::gapi::ie::util::to_ie(m_in_y, m_in_uv);
595 
596             const auto ie_rc = IE::ROI {
597                     0u
598                     , static_cast<std::size_t>(m_roi.x)
599                     , static_cast<std::size_t>(m_roi.y)
600                     , static_cast<std::size_t>(m_roi.width)
601                     , static_cast<std::size_t>(m_roi.height)
602             };
603 
604             IE::Blob::Ptr roi_blob = IE::make_shared_blob(blob, ie_rc);
605             infer_request.SetBlob("data", roi_blob);
606             infer_request.Infer();
607 
608             using namespace cv::gapi::ie::util;
609             m_out_ie_age    = to_ocv(infer_request.GetBlob("age_conv3")).clone();
610             m_out_ie_gender = to_ocv(infer_request.GetBlob("prob")).clone();
611         }
612     }
613 
validateopencv_test::SingleROINV12614     void validate() {
615         // Validate with IE itself (avoid DNN module dependency here)
616         normAssert(m_out_ie_age   , m_out_gapi_age   , "Test age output");
617         normAssert(m_out_ie_gender, m_out_gapi_gender, "Test gender output");
618     }
619 };
620 
TEST_F(ROIList,TestInfer)621 TEST_F(ROIList, TestInfer)
622 {
623     cv::GArray<cv::Rect> rr;
624     cv::GMat in;
625     cv::GArray<cv::GMat> age, gender;
626     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
627     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
628 
629     auto pp = cv::gapi::ie::Params<AgeGender> {
630         params.model_path, params.weights_path, params.device_id
631     }.cfgOutputLayers({ "age_conv3", "prob" });
632     comp.apply(cv::gin(m_in_mat, m_roi_list),
633             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
634             cv::compile_args(cv::gapi::networks(pp)));
635     validate();
636 }
637 
TEST_F(ROIList,TestInfer2)638 TEST_F(ROIList, TestInfer2)
639 {
640     cv::GArray<cv::Rect> rr;
641     cv::GMat in;
642     cv::GArray<cv::GMat> age, gender;
643     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
644     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
645 
646     auto pp = cv::gapi::ie::Params<AgeGender> {
647         params.model_path, params.weights_path, params.device_id
648     }.cfgOutputLayers({ "age_conv3", "prob" });
649     comp.apply(cv::gin(m_in_mat, m_roi_list),
650                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
651                cv::compile_args(cv::gapi::networks(pp)));
652     validate();
653 }
654 
TEST(DISABLED_TestTwoIENNPipeline,InferBasicImage)655 TEST(DISABLED_TestTwoIENNPipeline, InferBasicImage)
656 {
657     initDLDTDataPath();
658 
659     cv::gapi::ie::detail::ParamDesc AGparams;
660     AGparams.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml", false);
661     AGparams.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin", false);
662     AGparams.device_id = "MYRIAD";
663 
664     // FIXME: Ideally it should be an image from disk
665     // cv::Mat in_mat = cv::imread(findDataFile("grace_hopper_227.png"));
666     cv::Mat in_mat(cv::Size(320, 240), CV_8UC3);
667     cv::randu(in_mat, 0, 255);
668 
669     cv::Mat gapi_age1, gapi_gender1, gapi_age2, gapi_gender2;
670 
671     // Load & run IE network
672     IE::Blob::Ptr ie_age1, ie_gender1, ie_age2, ie_gender2;
673     {
674         auto AGplugin1         = cv::gimpl::ie::wrap::getPlugin(AGparams);
675         auto AGnet1            = cv::gimpl::ie::wrap::readNetwork(AGparams);
676         setNetParameters(AGnet1);
677         auto AGplugin_network1 = cv::gimpl::ie::wrap::loadNetwork(AGplugin1, AGnet1, AGparams);
678         auto AGinfer_request1  = AGplugin_network1.CreateInferRequest();
679         AGinfer_request1.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
680         AGinfer_request1.Infer();
681         ie_age1    = AGinfer_request1.GetBlob("age_conv3");
682         ie_gender1 = AGinfer_request1.GetBlob("prob");
683 
684         auto AGplugin2         = cv::gimpl::ie::wrap::getPlugin(AGparams);
685         auto AGnet2            = cv::gimpl::ie::wrap::readNetwork(AGparams);
686         setNetParameters(AGnet2);
687         auto AGplugin_network2 = cv::gimpl::ie::wrap::loadNetwork(AGplugin2, AGnet2, AGparams);
688         auto AGinfer_request2     = AGplugin_network2.CreateInferRequest();
689         AGinfer_request2.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
690         AGinfer_request2.Infer();
691         ie_age2    = AGinfer_request2.GetBlob("age_conv3");
692         ie_gender2 = AGinfer_request2.GetBlob("prob");
693     }
694 
695     // Configure & run G-API
696     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
697     G_API_NET(AgeGender1, <AGInfo(cv::GMat)>,   "test-age-gender1");
698     G_API_NET(AgeGender2, <AGInfo(cv::GMat)>,   "test-age-gender2");
699     cv::GMat in;
700     cv::GMat age1, gender1;
701     std::tie(age1, gender1) = cv::gapi::infer<AgeGender1>(in);
702 
703     cv::GMat age2, gender2;
704     // FIXME: "Multi-node inference is not supported!", workarounded 'till enabling proper tools
705     std::tie(age2, gender2) = cv::gapi::infer<AgeGender2>(cv::gapi::copy(in));
706     cv::GComputation comp(cv::GIn(in), cv::GOut(age1, gender1, age2, gender2));
707 
708     auto age_net1 = cv::gapi::ie::Params<AgeGender1> {
709         AGparams.model_path, AGparams.weights_path, AGparams.device_id
710     }.cfgOutputLayers({ "age_conv3", "prob" });
711     auto age_net2 = cv::gapi::ie::Params<AgeGender2> {
712         AGparams.model_path, AGparams.weights_path, AGparams.device_id
713     }.cfgOutputLayers({ "age_conv3", "prob" });
714 
715     comp.apply(cv::gin(in_mat), cv::gout(gapi_age1, gapi_gender1, gapi_age2, gapi_gender2),
716                cv::compile_args(cv::gapi::networks(age_net1, age_net2)));
717 
718     // Validate with IE itself (avoid DNN module dependency here)
719     normAssert(cv::gapi::ie::util::to_ocv(ie_age1),    gapi_age1,    "Test age output 1");
720     normAssert(cv::gapi::ie::util::to_ocv(ie_gender1), gapi_gender1, "Test gender output 1");
721     normAssert(cv::gapi::ie::util::to_ocv(ie_age2),    gapi_age2,    "Test age output 2");
722     normAssert(cv::gapi::ie::util::to_ocv(ie_gender2), gapi_gender2, "Test gender output 2");
723 }
724 
TEST(TestAgeGenderIE,GenericInfer)725 TEST(TestAgeGenderIE, GenericInfer)
726 {
727     initDLDTDataPath();
728 
729     cv::gapi::ie::detail::ParamDesc params;
730     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
731     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
732     params.device_id = "CPU";
733 
734     cv::Mat in_mat(cv::Size(320, 240), CV_8UC3);
735     cv::randu(in_mat, 0, 255);
736 
737     cv::Mat gapi_age, gapi_gender;
738 
739     // Load & run IE network
740     IE::Blob::Ptr ie_age, ie_gender;
741     {
742         auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
743         auto net    = cv::gimpl::ie::wrap::readNetwork(params);
744         setNetParameters(net);
745         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
746         auto infer_request = this_network.CreateInferRequest();
747         infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
748         infer_request.Infer();
749         ie_age    = infer_request.GetBlob("age_conv3");
750         ie_gender = infer_request.GetBlob("prob");
751     }
752 
753     // Configure & run G-API
754     cv::GMat in;
755     GInferInputs inputs;
756     inputs["data"] = in;
757 
758     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", inputs);
759 
760     auto age    = outputs.at("age_conv3");
761     auto gender = outputs.at("prob");
762 
763     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
764 
765     cv::gapi::ie::Params<cv::gapi::Generic> pp{
766         "age-gender-generic", params.model_path, params.weights_path, params.device_id};
767 
768     comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
769                cv::compile_args(cv::gapi::networks(pp)));
770 
771     // Validate with IE itself (avoid DNN module dependency here)
772     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
773     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
774 }
775 
TEST(TestAgeGenderIE,InvalidConfigGeneric)776 TEST(TestAgeGenderIE, InvalidConfigGeneric)
777 {
778     initDLDTDataPath();
779 
780     std::string model_path   = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
781     std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
782     std::string device_id    = "CPU";
783 
784     // Configure & run G-API
785     cv::GMat in;
786     GInferInputs inputs;
787     inputs["data"] = in;
788 
789     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", inputs);
790     auto age     = outputs.at("age_conv3");
791     auto gender  = outputs.at("prob");
792     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
793 
794     auto pp = cv::gapi::ie::Params<cv::gapi::Generic>{
795         "age-gender-generic", model_path, weights_path, device_id
796     }.pluginConfig({{"unsupported_config", "some_value"}});
797 
798     EXPECT_ANY_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
799                      cv::compile_args(cv::gapi::networks(pp))));
800 }
801 
TEST(TestAgeGenderIE,CPUConfigGeneric)802 TEST(TestAgeGenderIE, CPUConfigGeneric)
803 {
804     initDLDTDataPath();
805 
806     std::string model_path   = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
807     std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
808     std::string device_id    = "CPU";
809 
810     // Configure & run G-API
811     cv::GMat in;
812     GInferInputs inputs;
813     inputs["data"] = in;
814 
815     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", inputs);
816     auto age     = outputs.at("age_conv3");
817     auto gender  = outputs.at("prob");
818     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
819 
820     auto pp = cv::gapi::ie::Params<cv::gapi::Generic> {
821         "age-gender-generic", model_path, weights_path, device_id
822     }.pluginConfig({{IE::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS,
823                      IE::PluginConfigParams::CPU_THROUGHPUT_NUMA}});
824 
825     EXPECT_NO_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
826                     cv::compile_args(cv::gapi::networks(pp))));
827 }
828 
TEST(TestAgeGenderIE,InvalidConfig)829 TEST(TestAgeGenderIE, InvalidConfig)
830 {
831     initDLDTDataPath();
832 
833     std::string model_path   = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
834     std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
835     std::string device_id    = "CPU";
836 
837     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
838     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
839 
840     cv::GMat in;
841     cv::GMat age, gender;
842     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
843     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
844 
845     auto pp = cv::gapi::ie::Params<AgeGender> {
846         model_path, weights_path, device_id
847     }.cfgOutputLayers({ "age_conv3", "prob" })
848      .pluginConfig({{"unsupported_config", "some_value"}});
849 
850     EXPECT_ANY_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
851                      cv::compile_args(cv::gapi::networks(pp))));
852 }
853 
TEST(TestAgeGenderIE,CPUConfig)854 TEST(TestAgeGenderIE, CPUConfig)
855 {
856     initDLDTDataPath();
857 
858     std::string model_path   = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
859     std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
860     std::string device_id    = "CPU";
861 
862     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
863     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
864 
865     cv::GMat in;
866     cv::GMat age, gender;
867     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
868     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
869 
870     auto pp = cv::gapi::ie::Params<AgeGender> {
871         model_path, weights_path, device_id
872     }.cfgOutputLayers({ "age_conv3", "prob" })
873      .pluginConfig({{IE::PluginConfigParams::KEY_CPU_THROUGHPUT_STREAMS,
874                      IE::PluginConfigParams::CPU_THROUGHPUT_NUMA}});
875 
876     EXPECT_NO_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
877                     cv::compile_args(cv::gapi::networks(pp))));
878 }
879 
TEST_F(ROIList,MediaInputBGR)880 TEST_F(ROIList, MediaInputBGR)
881 {
882     initDLDTDataPath();
883 
884     cv::GFrame in;
885     cv::GArray<cv::Rect> rr;
886     cv::GArray<cv::GMat> age, gender;
887     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
888     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
889 
890     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
891 
892     auto pp = cv::gapi::ie::Params<AgeGender> {
893         params.model_path, params.weights_path, params.device_id
894     }.cfgOutputLayers({ "age_conv3", "prob" });
895     comp.apply(cv::gin(frame, m_roi_list),
896                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
897                cv::compile_args(cv::gapi::networks(pp)));
898 
899     validate();
900 }
901 
TEST_F(ROIListNV12,MediaInputNV12)902 TEST_F(ROIListNV12, MediaInputNV12)
903 {
904     initDLDTDataPath();
905 
906     cv::GFrame in;
907     cv::GArray<cv::Rect> rr;
908     cv::GArray<cv::GMat> age, gender;
909     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
910     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
911 
912     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
913 
914     auto pp = cv::gapi::ie::Params<AgeGender> {
915         params.model_path, params.weights_path, params.device_id
916     }.cfgOutputLayers({ "age_conv3", "prob" });
917     comp.apply(cv::gin(frame, m_roi_list),
918                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
919                cv::compile_args(cv::gapi::networks(pp)));
920 
921     validate();
922 }
923 
TEST(TestAgeGenderIE,MediaInputNV12)924 TEST(TestAgeGenderIE, MediaInputNV12)
925 {
926     initDLDTDataPath();
927 
928     cv::gapi::ie::detail::ParamDesc params;
929     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
930     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
931     params.device_id = "CPU";
932 
933     cv::Size sz{320, 240};
934     cv::Mat in_y_mat(sz, CV_8UC1);
935     cv::randu(in_y_mat, 0, 255);
936     cv::Mat in_uv_mat(sz / 2, CV_8UC2);
937     cv::randu(in_uv_mat, 0, 255);
938 
939     cv::Mat gapi_age, gapi_gender;
940 
941     // Load & run IE network
942     IE::Blob::Ptr ie_age, ie_gender;
943     {
944         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
945         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
946         setNetParameters(net, true);
947         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
948         auto infer_request = this_network.CreateInferRequest();
949         infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat));
950         infer_request.Infer();
951         ie_age    = infer_request.GetBlob("age_conv3");
952         ie_gender = infer_request.GetBlob("prob");
953     }
954 
955     // Configure & run G-API
956     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
957     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
958 
959     cv::GFrame in;
960     cv::GMat age, gender;
961     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
962     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
963 
964     auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
965 
966     auto pp = cv::gapi::ie::Params<AgeGender> {
967         params.model_path, params.weights_path, params.device_id
968     }.cfgOutputLayers({ "age_conv3", "prob" });
969     comp.apply(cv::gin(frame), cv::gout(gapi_age, gapi_gender),
970                cv::compile_args(cv::gapi::networks(pp)));
971 
972 
973     // Validate with IE itself (avoid DNN module dependency here)
974     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
975     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
976 }
977 
TEST(TestAgeGenderIE,MediaInputBGR)978 TEST(TestAgeGenderIE, MediaInputBGR)
979 {
980     initDLDTDataPath();
981 
982     cv::gapi::ie::detail::ParamDesc params;
983     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
984     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
985     params.device_id = "CPU";
986 
987     cv::Size sz{320, 240};
988     cv::Mat in_mat(sz, CV_8UC3);
989     cv::randu(in_mat, 0, 255);
990 
991     cv::Mat gapi_age, gapi_gender;
992 
993     // Load & run IE network
994     IE::Blob::Ptr ie_age, ie_gender;
995     {
996         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
997         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
998         setNetParameters(net);
999         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1000         auto infer_request = this_network.CreateInferRequest();
1001         infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
1002         infer_request.Infer();
1003         ie_age    = infer_request.GetBlob("age_conv3");
1004         ie_gender = infer_request.GetBlob("prob");
1005     }
1006 
1007     // Configure & run G-API
1008     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1009     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1010 
1011     cv::GFrame in;
1012     cv::GMat age, gender;
1013     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
1014     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
1015 
1016     auto frame = MediaFrame::Create<TestMediaBGR>(in_mat);
1017 
1018     auto pp = cv::gapi::ie::Params<AgeGender> {
1019         params.model_path, params.weights_path, params.device_id
1020     }.cfgOutputLayers({ "age_conv3", "prob" });
1021     comp.apply(cv::gin(frame), cv::gout(gapi_age, gapi_gender),
1022                cv::compile_args(cv::gapi::networks(pp)));
1023 
1024 
1025     // Validate with IE itself (avoid DNN module dependency here)
1026     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
1027     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
1028 }
1029 
TEST(InferROI,MediaInputBGR)1030 TEST(InferROI, MediaInputBGR)
1031 {
1032     initDLDTDataPath();
1033 
1034     cv::gapi::ie::detail::ParamDesc params;
1035     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1036     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1037     params.device_id = "CPU";
1038 
1039     cv::Size sz{320, 240};
1040     cv::Mat in_mat(sz, CV_8UC3);
1041     cv::randu(in_mat, 0, 255);
1042 
1043     cv::Mat gapi_age, gapi_gender;
1044     cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
1045 
1046     // Load & run IE network
1047     IE::Blob::Ptr ie_age, ie_gender;
1048     {
1049         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1050         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1051         setNetParameters(net);
1052         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1053         auto infer_request = this_network.CreateInferRequest();
1054         const auto ie_rc = IE::ROI {
1055             0u
1056             , static_cast<std::size_t>(rect.x)
1057             , static_cast<std::size_t>(rect.y)
1058             , static_cast<std::size_t>(rect.width)
1059             , static_cast<std::size_t>(rect.height)
1060         };
1061         IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_mat), ie_rc);
1062         infer_request.SetBlob("data", roi_blob);
1063         infer_request.Infer();
1064         ie_age    = infer_request.GetBlob("age_conv3");
1065         ie_gender = infer_request.GetBlob("prob");
1066     }
1067 
1068     // Configure & run G-API
1069     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1070     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1071 
1072     cv::GFrame in;
1073     cv::GOpaque<cv::Rect> roi;
1074     cv::GMat age, gender;
1075     std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
1076     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1077 
1078     auto frame = MediaFrame::Create<TestMediaBGR>(in_mat);
1079 
1080     auto pp = cv::gapi::ie::Params<AgeGender> {
1081         params.model_path, params.weights_path, params.device_id
1082     }.cfgOutputLayers({ "age_conv3", "prob" });
1083     comp.apply(cv::gin(frame, rect), cv::gout(gapi_age, gapi_gender),
1084                cv::compile_args(cv::gapi::networks(pp)));
1085 
1086 
1087     // Validate with IE itself (avoid DNN module dependency here)
1088     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
1089     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
1090 }
1091 
TEST(InferROI,MediaInputNV12)1092 TEST(InferROI, MediaInputNV12)
1093 {
1094     initDLDTDataPath();
1095 
1096     cv::gapi::ie::detail::ParamDesc params;
1097     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1098     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1099     params.device_id = "CPU";
1100 
1101     cv::Size sz{320, 240};
1102     auto in_y_mat = cv::Mat{sz, CV_8UC1};
1103     cv::randu(in_y_mat, 0, 255);
1104     auto in_uv_mat = cv::Mat{sz / 2, CV_8UC2};
1105     cv::randu(in_uv_mat, 0, 255);
1106 
1107     cv::Mat gapi_age, gapi_gender;
1108     cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
1109 
1110     // Load & run IE network
1111     IE::Blob::Ptr ie_age, ie_gender;
1112     {
1113         auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1114         auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1115         setNetParameters(net, true);
1116         auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1117         auto infer_request = this_network.CreateInferRequest();
1118         const auto ie_rc = IE::ROI {
1119             0u
1120             , static_cast<std::size_t>(rect.x)
1121             , static_cast<std::size_t>(rect.y)
1122             , static_cast<std::size_t>(rect.width)
1123             , static_cast<std::size_t>(rect.height)
1124         };
1125         IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat), ie_rc);
1126         infer_request.SetBlob("data", roi_blob);
1127         infer_request.Infer();
1128         ie_age    = infer_request.GetBlob("age_conv3");
1129         ie_gender = infer_request.GetBlob("prob");
1130     }
1131 
1132     // Configure & run G-API
1133     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1134     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1135 
1136     cv::GFrame in;
1137     cv::GOpaque<cv::Rect> roi;
1138     cv::GMat age, gender;
1139     std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
1140     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1141 
1142     auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
1143 
1144     auto pp = cv::gapi::ie::Params<AgeGender> {
1145         params.model_path, params.weights_path, params.device_id
1146     }.cfgOutputLayers({ "age_conv3", "prob" });
1147     comp.apply(cv::gin(frame, rect), cv::gout(gapi_age, gapi_gender),
1148                cv::compile_args(cv::gapi::networks(pp)));
1149 
1150 
1151     // Validate with IE itself (avoid DNN module dependency here)
1152     normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
1153     normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
1154 }
1155 
TEST_F(ROIList,Infer2MediaInputBGR)1156 TEST_F(ROIList, Infer2MediaInputBGR)
1157 {
1158     cv::GArray<cv::Rect> rr;
1159     cv::GFrame in;
1160     cv::GArray<cv::GMat> age, gender;
1161     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
1162     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1163 
1164     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
1165 
1166     auto pp = cv::gapi::ie::Params<AgeGender> {
1167         params.model_path, params.weights_path, params.device_id
1168     }.cfgOutputLayers({ "age_conv3", "prob" });
1169     comp.apply(cv::gin(frame, m_roi_list),
1170                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1171                cv::compile_args(cv::gapi::networks(pp)));
1172     validate();
1173 }
1174 
TEST_F(ROIListNV12,Infer2MediaInputNV12)1175 TEST_F(ROIListNV12, Infer2MediaInputNV12)
1176 {
1177     cv::GArray<cv::Rect> rr;
1178     cv::GFrame in;
1179     cv::GArray<cv::GMat> age, gender;
1180     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
1181     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1182 
1183     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
1184 
1185     auto pp = cv::gapi::ie::Params<AgeGender> {
1186         params.model_path, params.weights_path, params.device_id
1187     }.cfgOutputLayers({ "age_conv3", "prob" });
1188     comp.apply(cv::gin(frame, m_roi_list),
1189                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1190                cv::compile_args(cv::gapi::networks(pp)));
1191     validate();
1192 }
1193 
TEST_F(SingleROI,GenericInfer)1194 TEST_F(SingleROI, GenericInfer)
1195 {
1196     // Configure & run G-API
1197     cv::GMat in;
1198     cv::GOpaque<cv::Rect> roi;
1199     cv::GInferInputs inputs;
1200     inputs["data"] = in;
1201 
1202     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", roi, inputs);
1203     auto age     = outputs.at("age_conv3");
1204     auto gender  = outputs.at("prob");
1205 
1206     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1207 
1208     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1209         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1210     };
1211     pp.cfgNumRequests(2u);
1212 
1213     comp.apply(cv::gin(m_in_mat, m_roi), cv::gout(m_out_gapi_age, m_out_gapi_gender),
1214             cv::compile_args(cv::gapi::networks(pp)));
1215 
1216     validate();
1217 }
1218 
TEST_F(SingleROI,GenericInferMediaBGR)1219 TEST_F(SingleROI, GenericInferMediaBGR)
1220 {
1221     // Configure & run G-API
1222     cv::GFrame in;
1223     cv::GOpaque<cv::Rect> roi;
1224     cv::GInferInputs inputs;
1225     inputs["data"] = in;
1226 
1227     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", roi, inputs);
1228     auto age     = outputs.at("age_conv3");
1229     auto gender  = outputs.at("prob");
1230 
1231     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1232 
1233     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1234         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1235     };
1236     pp.cfgNumRequests(2u);
1237 
1238     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
1239     comp.apply(cv::gin(frame, m_roi), cv::gout(m_out_gapi_age, m_out_gapi_gender),
1240             cv::compile_args(cv::gapi::networks(pp)));
1241 
1242     validate();
1243 }
1244 
TEST_F(SingleROINV12,GenericInferMediaNV12)1245 TEST_F(SingleROINV12, GenericInferMediaNV12)
1246 {
1247     // Configure & run G-API
1248     cv::GFrame in;
1249     cv::GOpaque<cv::Rect> roi;
1250     cv::GInferInputs inputs;
1251     inputs["data"] = in;
1252 
1253     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", roi, inputs);
1254     auto age     = outputs.at("age_conv3");
1255     auto gender  = outputs.at("prob");
1256 
1257     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1258 
1259     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1260         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1261     };
1262     pp.cfgNumRequests(2u);
1263 
1264     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
1265     comp.apply(cv::gin(frame, m_roi), cv::gout(m_out_gapi_age, m_out_gapi_gender),
1266             cv::compile_args(cv::gapi::networks(pp)));
1267 
1268     validate();
1269 }
1270 
TEST_F(ROIList,GenericInfer)1271 TEST_F(ROIList, GenericInfer)
1272 {
1273     cv::GMat in;
1274     cv::GArray<cv::Rect> rr;
1275     cv::GInferInputs inputs;
1276     inputs["data"] = in;
1277 
1278     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", rr, inputs);
1279     auto age     = outputs.at("age_conv3");
1280     auto gender  = outputs.at("prob");
1281 
1282     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1283 
1284     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1285         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1286     };
1287     pp.cfgNumRequests(2u);
1288 
1289     comp.apply(cv::gin(m_in_mat, m_roi_list),
1290             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1291             cv::compile_args(cv::gapi::networks(pp)));
1292 
1293     validate();
1294 }
1295 
TEST_F(ROIList,GenericInferMediaBGR)1296 TEST_F(ROIList, GenericInferMediaBGR)
1297 {
1298     cv::GFrame in;
1299     cv::GArray<cv::Rect> rr;
1300     cv::GInferInputs inputs;
1301     inputs["data"] = in;
1302 
1303     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", rr, inputs);
1304     auto age     = outputs.at("age_conv3");
1305     auto gender  = outputs.at("prob");
1306 
1307     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1308 
1309     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1310         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1311     };
1312     pp.cfgNumRequests(2u);
1313 
1314     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
1315     comp.apply(cv::gin(frame, m_roi_list),
1316             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1317             cv::compile_args(cv::gapi::networks(pp)));
1318 
1319     validate();
1320 }
1321 
TEST_F(ROIListNV12,GenericInferMediaNV12)1322 TEST_F(ROIListNV12, GenericInferMediaNV12)
1323 {
1324     cv::GFrame in;
1325     cv::GArray<cv::Rect> rr;
1326     cv::GInferInputs inputs;
1327     inputs["data"] = in;
1328 
1329     auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", rr, inputs);
1330     auto age     = outputs.at("age_conv3");
1331     auto gender  = outputs.at("prob");
1332 
1333     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1334 
1335     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1336         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1337     };
1338     pp.cfgNumRequests(2u);
1339 
1340     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
1341     comp.apply(cv::gin(frame, m_roi_list),
1342             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1343             cv::compile_args(cv::gapi::networks(pp)));
1344 
1345     validate();
1346 }
1347 
TEST_F(ROIList,GenericInfer2)1348 TEST_F(ROIList, GenericInfer2)
1349 {
1350     cv::GArray<cv::Rect> rr;
1351     cv::GMat in;
1352     GInferListInputs list;
1353     list["data"] = rr;
1354 
1355     auto outputs = cv::gapi::infer2<cv::gapi::Generic>("age-gender-generic", in, list);
1356     auto age     = outputs.at("age_conv3");
1357     auto gender  = outputs.at("prob");
1358 
1359     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1360 
1361     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1362         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1363     };
1364     pp.cfgNumRequests(2u);
1365 
1366     comp.apply(cv::gin(m_in_mat, m_roi_list),
1367             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1368             cv::compile_args(cv::gapi::networks(pp)));
1369     validate();
1370 }
1371 
TEST_F(ROIList,GenericInfer2MediaInputBGR)1372 TEST_F(ROIList, GenericInfer2MediaInputBGR)
1373 {
1374     cv::GArray<cv::Rect> rr;
1375     cv::GFrame in;
1376     GInferListInputs inputs;
1377     inputs["data"] = rr;
1378 
1379     auto outputs = cv::gapi::infer2<cv::gapi::Generic>("age-gender-generic", in, inputs);
1380     auto age     = outputs.at("age_conv3");
1381     auto gender  = outputs.at("prob");
1382 
1383     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1384 
1385     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1386         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1387     };
1388     pp.cfgNumRequests(2u);
1389 
1390     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
1391     comp.apply(cv::gin(frame, m_roi_list),
1392             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1393             cv::compile_args(cv::gapi::networks(pp)));
1394     validate();
1395 }
1396 
TEST_F(ROIListNV12,GenericInfer2MediaInputNV12)1397 TEST_F(ROIListNV12, GenericInfer2MediaInputNV12)
1398 {
1399     cv::GArray<cv::Rect> rr;
1400     cv::GFrame in;
1401     GInferListInputs inputs;
1402     inputs["data"] = rr;
1403 
1404     auto outputs = cv::gapi::infer2<cv::gapi::Generic>("age-gender-generic", in, inputs);
1405     auto age     = outputs.at("age_conv3");
1406     auto gender  = outputs.at("prob");
1407 
1408     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1409 
1410     cv::gapi::ie::Params<cv::gapi::Generic> pp{
1411         "age-gender-generic", params.model_path, params.weights_path, params.device_id
1412     };
1413     pp.cfgNumRequests(2u);
1414 
1415     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
1416     comp.apply(cv::gin(frame, m_roi_list),
1417             cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1418             cv::compile_args(cv::gapi::networks(pp)));
1419     validate();
1420 }
1421 
TEST(Infer,SetInvalidNumberOfRequests)1422 TEST(Infer, SetInvalidNumberOfRequests)
1423 {
1424     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1425     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1426 
1427     cv::gapi::ie::Params<AgeGender> pp{"model", "weights", "device"};
1428 
1429     EXPECT_ANY_THROW(pp.cfgNumRequests(0u));
1430 }
1431 
TEST(Infer,TestStreamingInfer)1432 TEST(Infer, TestStreamingInfer)
1433 {
1434     initTestDataPath();
1435     initDLDTDataPath();
1436 
1437     std::string filepath = findDataFile("cv/video/768x576.avi");
1438 
1439     cv::gapi::ie::detail::ParamDesc params;
1440     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1441     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1442     params.device_id = "CPU";
1443 
1444     // Load IE network, initialize input data using that.
1445     cv::Mat in_mat;
1446     cv::Mat gapi_age, gapi_gender;
1447 
1448     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1449     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1450 
1451     cv::GMat in;
1452     cv::GMat age, gender;
1453 
1454     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
1455     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
1456 
1457     auto pp = cv::gapi::ie::Params<AgeGender> {
1458         params.model_path, params.weights_path, params.device_id
1459     }.cfgOutputLayers({ "age_conv3", "prob" })
1460      .cfgNumRequests(4u);
1461 
1462 
1463     std::size_t num_frames = 0u;
1464     std::size_t max_frames = 10u;
1465 
1466     cv::VideoCapture cap;
1467     cap.open(filepath);
1468     if (!cap.isOpened())
1469         throw SkipTestException("Video file can not be opened");
1470 
1471     cap >> in_mat;
1472     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1473     pipeline.setSource<cv::gapi::wip::GCaptureSource>(filepath);
1474 
1475     pipeline.start();
1476     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_age, gapi_gender)))
1477     {
1478         IE::Blob::Ptr ie_age, ie_gender;
1479         {
1480             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1481             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1482             setNetParameters(net);
1483             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1484             auto infer_request = this_network.CreateInferRequest();
1485 
1486             infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
1487             infer_request.Infer();
1488             ie_age    = infer_request.GetBlob("age_conv3");
1489             ie_gender = infer_request.GetBlob("prob");
1490         }
1491         // Validate with IE itself (avoid DNN module dependency here)
1492         normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
1493         normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
1494         ++num_frames;
1495         cap >> in_mat;
1496     }
1497     pipeline.stop();
1498 }
1499 
TEST(InferROI,TestStreamingInfer)1500 TEST(InferROI, TestStreamingInfer)
1501 {
1502     initTestDataPath();
1503     initDLDTDataPath();
1504 
1505     std::string filepath = findDataFile("cv/video/768x576.avi");
1506 
1507     cv::gapi::ie::detail::ParamDesc params;
1508     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1509     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1510     params.device_id = "CPU";
1511 
1512     // Load IE network, initialize input data using that.
1513     cv::Mat in_mat;
1514     cv::Mat gapi_age, gapi_gender;
1515     cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
1516 
1517     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1518     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1519 
1520     cv::GMat in;
1521     cv::GOpaque<cv::Rect> roi;
1522     cv::GMat age, gender;
1523 
1524     std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
1525     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1526 
1527     auto pp = cv::gapi::ie::Params<AgeGender> {
1528         params.model_path, params.weights_path, params.device_id
1529     }.cfgOutputLayers({ "age_conv3", "prob" })
1530      .cfgNumRequests(4u);
1531 
1532 
1533     std::size_t num_frames = 0u;
1534     std::size_t max_frames = 10u;
1535 
1536     cv::VideoCapture cap;
1537     cap.open(filepath);
1538     if (!cap.isOpened())
1539         throw SkipTestException("Video file can not be opened");
1540 
1541     cap >> in_mat;
1542     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1543     pipeline.setSource(
1544             cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), rect));
1545 
1546     pipeline.start();
1547     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_age, gapi_gender)))
1548     {
1549         // Load & run IE network
1550         IE::Blob::Ptr ie_age, ie_gender;
1551         {
1552             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1553             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1554             setNetParameters(net);
1555             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1556             auto infer_request = this_network.CreateInferRequest();
1557             const auto ie_rc = IE::ROI {
1558                 0u
1559                 , static_cast<std::size_t>(rect.x)
1560                 , static_cast<std::size_t>(rect.y)
1561                 , static_cast<std::size_t>(rect.width)
1562                 , static_cast<std::size_t>(rect.height)
1563             };
1564             IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_mat), ie_rc);
1565             infer_request.SetBlob("data", roi_blob);
1566             infer_request.Infer();
1567             ie_age    = infer_request.GetBlob("age_conv3");
1568             ie_gender = infer_request.GetBlob("prob");
1569         }
1570         // Validate with IE itself (avoid DNN module dependency here)
1571         normAssert(cv::gapi::ie::util::to_ocv(ie_age),    gapi_age,    "Test age output"   );
1572         normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
1573         ++num_frames;
1574         cap >> in_mat;
1575     }
1576     pipeline.stop();
1577 }
1578 
TEST(InferList,TestStreamingInfer)1579 TEST(InferList, TestStreamingInfer)
1580 {
1581     initTestDataPath();
1582     initDLDTDataPath();
1583 
1584     std::string filepath = findDataFile("cv/video/768x576.avi");
1585 
1586     cv::gapi::ie::detail::ParamDesc params;
1587     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1588     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1589     params.device_id = "CPU";
1590 
1591     // Load IE network, initialize input data using that.
1592     cv::Mat in_mat;
1593     std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
1594 
1595     std::vector<cv::Rect> roi_list = {
1596         cv::Rect(cv::Point{64, 60}, cv::Size{ 96,  96}),
1597         cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
1598     };
1599 
1600     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1601     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1602 
1603     cv::GMat in;
1604     cv::GArray<cv::Rect> roi;
1605     cv::GArray<GMat> age, gender;
1606 
1607     std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
1608     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1609 
1610     auto pp = cv::gapi::ie::Params<AgeGender> {
1611         params.model_path, params.weights_path, params.device_id
1612     }.cfgOutputLayers({ "age_conv3", "prob" })
1613      .cfgNumRequests(4u);
1614 
1615     std::size_t num_frames = 0u;
1616     std::size_t max_frames = 10u;
1617 
1618     cv::VideoCapture cap;
1619     cap.open(filepath);
1620     if (!cap.isOpened())
1621         throw SkipTestException("Video file can not be opened");
1622 
1623     cap >> in_mat;
1624     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1625     pipeline.setSource(
1626             cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
1627 
1628     pipeline.start();
1629     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
1630     {
1631         {
1632             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1633             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1634             setNetParameters(net);
1635             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1636             auto infer_request = this_network.CreateInferRequest();
1637             auto frame_blob = cv::gapi::ie::util::to_ie(in_mat);
1638 
1639             for (auto &&rc : roi_list) {
1640                 const auto ie_rc = IE::ROI {
1641                     0u
1642                     , static_cast<std::size_t>(rc.x)
1643                     , static_cast<std::size_t>(rc.y)
1644                     , static_cast<std::size_t>(rc.width)
1645                     , static_cast<std::size_t>(rc.height)
1646                 };
1647                 infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
1648                 infer_request.Infer();
1649 
1650                 using namespace cv::gapi::ie::util;
1651                 ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
1652                 ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
1653             }
1654         } // namespace IE = ..
1655         // Validate with IE itself (avoid DNN module dependency here)
1656         normAssert(ie_ages   [0], gapi_ages   [0], "0: Test age output");
1657         normAssert(ie_genders[0], gapi_genders[0], "0: Test gender output");
1658         normAssert(ie_ages   [1], gapi_ages   [1], "1: Test age output");
1659         normAssert(ie_genders[1], gapi_genders[1], "1: Test gender output");
1660 
1661         ie_ages.clear();
1662         ie_genders.clear();
1663 
1664         ++num_frames;
1665         cap >> in_mat;
1666     }
1667 }
1668 
TEST(Infer2,TestStreamingInfer)1669 TEST(Infer2, TestStreamingInfer)
1670 {
1671     initTestDataPath();
1672     initDLDTDataPath();
1673 
1674     std::string filepath = findDataFile("cv/video/768x576.avi");
1675 
1676     cv::gapi::ie::detail::ParamDesc params;
1677     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1678     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1679     params.device_id = "CPU";
1680 
1681     // Load IE network, initialize input data using that.
1682     cv::Mat in_mat;
1683     std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
1684 
1685     std::vector<cv::Rect> roi_list = {
1686         cv::Rect(cv::Point{64, 60}, cv::Size{ 96,  96}),
1687         cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
1688     };
1689 
1690     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1691     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1692 
1693     cv::GArray<cv::Rect> rr;
1694     cv::GMat in;
1695     cv::GArray<cv::GMat> age, gender;
1696     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
1697 
1698     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1699 
1700     auto pp = cv::gapi::ie::Params<AgeGender> {
1701         params.model_path, params.weights_path, params.device_id
1702     }.cfgOutputLayers({ "age_conv3", "prob" })
1703      .cfgNumRequests(4u);
1704 
1705     std::size_t num_frames = 0u;
1706     std::size_t max_frames = 10u;
1707 
1708     cv::VideoCapture cap;
1709     cap.open(filepath);
1710     if (!cap.isOpened())
1711         throw SkipTestException("Video file can not be opened");
1712 
1713     cap >> in_mat;
1714     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1715     pipeline.setSource(
1716             cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
1717 
1718     pipeline.start();
1719     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
1720     {
1721         {
1722             auto plugin        = cv::gimpl::ie::wrap::getPlugin(params);
1723             auto net           = cv::gimpl::ie::wrap::readNetwork(params);
1724             setNetParameters(net);
1725             auto this_network  = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
1726             auto infer_request = this_network.CreateInferRequest();
1727             auto frame_blob = cv::gapi::ie::util::to_ie(in_mat);
1728 
1729             for (auto &&rc : roi_list) {
1730                 const auto ie_rc = IE::ROI {
1731                     0u
1732                     , static_cast<std::size_t>(rc.x)
1733                     , static_cast<std::size_t>(rc.y)
1734                     , static_cast<std::size_t>(rc.width)
1735                     , static_cast<std::size_t>(rc.height)
1736                 };
1737                 infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
1738                 infer_request.Infer();
1739 
1740                 using namespace cv::gapi::ie::util;
1741                 ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
1742                 ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
1743             }
1744         } // namespace IE = ..
1745         // Validate with IE itself (avoid DNN module dependency here)
1746         normAssert(ie_ages   [0], gapi_ages   [0], "0: Test age output");
1747         normAssert(ie_genders[0], gapi_genders[0], "0: Test gender output");
1748         normAssert(ie_ages   [1], gapi_ages   [1], "1: Test age output");
1749         normAssert(ie_genders[1], gapi_genders[1], "1: Test gender output");
1750 
1751         ie_ages.clear();
1752         ie_genders.clear();
1753 
1754         ++num_frames;
1755         cap >> in_mat;
1756     }
1757     pipeline.stop();
1758 }
1759 
TEST(InferEmptyList,TestStreamingInfer)1760 TEST(InferEmptyList, TestStreamingInfer)
1761 {
1762     initTestDataPath();
1763     initDLDTDataPath();
1764 
1765     std::string filepath = findDataFile("cv/video/768x576.avi");
1766 
1767     cv::gapi::ie::detail::ParamDesc params;
1768     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1769     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1770     params.device_id = "CPU";
1771 
1772     // Load IE network, initialize input data using that.
1773     cv::Mat in_mat;
1774     std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
1775 
1776     // NB: Empty list of roi
1777     std::vector<cv::Rect> roi_list;
1778 
1779     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1780     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1781 
1782     cv::GMat in;
1783     cv::GArray<cv::Rect> roi;
1784     cv::GArray<GMat> age, gender;
1785 
1786     std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
1787     cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
1788 
1789     auto pp = cv::gapi::ie::Params<AgeGender> {
1790         params.model_path, params.weights_path, params.device_id
1791     }.cfgOutputLayers({ "age_conv3", "prob" })
1792      .cfgNumRequests(4u);
1793 
1794     std::size_t num_frames = 0u;
1795     std::size_t max_frames = 1u;
1796 
1797     cv::VideoCapture cap;
1798     cap.open(filepath);
1799     if (!cap.isOpened())
1800         throw SkipTestException("Video file can not be opened");
1801 
1802     cap >> in_mat;
1803     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1804     pipeline.setSource(
1805             cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
1806 
1807     pipeline.start();
1808     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
1809     {
1810         EXPECT_TRUE(gapi_ages.empty());
1811         EXPECT_TRUE(gapi_genders.empty());
1812     }
1813 }
1814 
TEST(Infer2EmptyList,TestStreamingInfer)1815 TEST(Infer2EmptyList, TestStreamingInfer)
1816 {
1817     initTestDataPath();
1818     initDLDTDataPath();
1819 
1820     std::string filepath = findDataFile("cv/video/768x576.avi");
1821 
1822     cv::gapi::ie::detail::ParamDesc params;
1823     params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
1824     params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
1825     params.device_id = "CPU";
1826 
1827     // Load IE network, initialize input data using that.
1828     cv::Mat in_mat;
1829     std::vector<cv::Mat> ie_ages, ie_genders, gapi_ages, gapi_genders;
1830 
1831     // NB: Empty list of roi
1832     std::vector<cv::Rect> roi_list;
1833 
1834     using AGInfo = std::tuple<cv::GMat, cv::GMat>;
1835     G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
1836 
1837     cv::GArray<cv::Rect> rr;
1838     cv::GMat in;
1839     cv::GArray<cv::GMat> age, gender;
1840     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
1841 
1842     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1843 
1844     auto pp = cv::gapi::ie::Params<AgeGender> {
1845         params.model_path, params.weights_path, params.device_id
1846     }.cfgOutputLayers({ "age_conv3", "prob" })
1847      .cfgNumRequests(4u);
1848 
1849     std::size_t num_frames = 0u;
1850     std::size_t max_frames = 1u;
1851 
1852     cv::VideoCapture cap;
1853     cap.open(filepath);
1854     if (!cap.isOpened())
1855         throw SkipTestException("Video file can not be opened");
1856 
1857     cap >> in_mat;
1858     auto pipeline = comp.compileStreaming(cv::compile_args(cv::gapi::networks(pp)));
1859     pipeline.setSource(
1860             cv::gin(cv::gapi::wip::make_src<cv::gapi::wip::GCaptureSource>(filepath), roi_list));
1861 
1862     pipeline.start();
1863     while (num_frames < max_frames && pipeline.pull(cv::gout(gapi_ages, gapi_genders)))
1864     {
1865         EXPECT_TRUE(gapi_ages.empty());
1866         EXPECT_TRUE(gapi_genders.empty());
1867     }
1868 }
1869 
TEST_F(InferWithReshape,TestInfer)1870 TEST_F(InferWithReshape, TestInfer)
1871 {
1872     // IE code
1873     infer(m_in_mat);
1874     // G-API code
1875     cv::GMat in;
1876     cv::GMat age, gender;
1877     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
1878     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
1879 
1880     auto pp = cv::gapi::ie::Params<AgeGender> {
1881         params.model_path, params.weights_path, params.device_id
1882     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
1883     comp.apply(cv::gin(m_in_mat), cv::gout(m_out_gapi_ages.front(), m_out_gapi_genders.front()),
1884                cv::compile_args(cv::gapi::networks(pp)));
1885     // Validate
1886     validate();
1887 }
1888 
TEST_F(InferWithReshape,TestInferInImage)1889 TEST_F(InferWithReshape, TestInferInImage)
1890 {
1891     // Input image already has 70x70 size
1892     cv::Mat rsz;
1893     cv::resize(m_in_mat, rsz, cv::Size(70, 70));
1894     // IE code
1895     infer(rsz);
1896     // G-API code
1897     cv::GMat in;
1898     cv::GMat age, gender;
1899     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
1900     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
1901 
1902     auto pp = cv::gapi::ie::Params<AgeGender> {
1903         params.model_path, params.weights_path, params.device_id
1904     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({"data"});
1905     // Reshape CNN input by input image size
1906     comp.apply(cv::gin(rsz), cv::gout(m_out_gapi_ages.front(), m_out_gapi_genders.front()),
1907                cv::compile_args(cv::gapi::networks(pp)));
1908     // Validate
1909     validate();
1910 }
1911 
TEST_F(InferWithReshape,TestInferForSingleLayer)1912 TEST_F(InferWithReshape, TestInferForSingleLayer)
1913 {
1914     // IE code
1915     infer(m_in_mat);
1916     // G-API code
1917     cv::GMat in;
1918     cv::GMat age, gender;
1919     std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
1920     cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
1921 
1922     auto pp = cv::gapi::ie::Params<AgeGender> {
1923         params.model_path, params.weights_path, params.device_id
1924     }.cfgOutputLayers({ "age_conv3", "prob" })
1925      .cfgInputReshape("data", reshape_dims);
1926     comp.apply(cv::gin(m_in_mat), cv::gout(m_out_gapi_ages.front(), m_out_gapi_genders.front()),
1927                cv::compile_args(cv::gapi::networks(pp)));
1928     // Validate
1929     validate();
1930 }
1931 
TEST_F(InferWithReshape,TestInferList)1932 TEST_F(InferWithReshape, TestInferList)
1933 {
1934     // IE code
1935     infer(m_in_mat, true);
1936     // G-API code
1937     cv::GArray<cv::Rect> rr;
1938     cv::GMat in;
1939     cv::GArray<cv::GMat> age, gender;
1940     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
1941     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1942 
1943     auto pp = cv::gapi::ie::Params<AgeGender> {
1944         params.model_path, params.weights_path, params.device_id
1945     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
1946     comp.apply(cv::gin(m_in_mat, m_roi_list),
1947                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1948                cv::compile_args(cv::gapi::networks(pp)));
1949     // Validate
1950     validate();
1951 }
1952 
TEST_F(InferWithReshape,TestInferList2)1953 TEST_F(InferWithReshape, TestInferList2)
1954 {
1955     // IE code
1956     infer(m_in_mat, true);
1957     // G-API code
1958     cv::GArray<cv::Rect> rr;
1959     cv::GMat in;
1960     cv::GArray<cv::GMat> age, gender;
1961     std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
1962     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1963 
1964     auto pp = cv::gapi::ie::Params<AgeGender> {
1965         params.model_path, params.weights_path, params.device_id
1966     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
1967     comp.apply(cv::gin(m_in_mat, m_roi_list),
1968                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1969                cv::compile_args(cv::gapi::networks(pp)));
1970     // Validate
1971     validate();
1972 }
1973 
TEST_F(InferWithReshape,TestInferListBGR)1974 TEST_F(InferWithReshape, TestInferListBGR)
1975 {
1976     // IE code
1977     infer(m_in_mat, true);
1978     // G-API code
1979     cv::GArray<cv::Rect> rr;
1980     cv::GFrame in;
1981     cv::GArray<cv::GMat> age, gender;
1982     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
1983     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
1984 
1985     auto frame = MediaFrame::Create<TestMediaBGR>(m_in_mat);
1986 
1987     auto pp = cv::gapi::ie::Params<AgeGender> {
1988         params.model_path, params.weights_path, params.device_id
1989     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
1990     comp.apply(cv::gin(frame, m_roi_list),
1991                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
1992                cv::compile_args(cv::gapi::networks(pp)));
1993     // Validate
1994     validate();
1995 }
1996 
TEST_F(InferWithReshapeNV12,TestInferListYUV)1997 TEST_F(InferWithReshapeNV12, TestInferListYUV)
1998 {
1999     // G-API code
2000     cv::GFrame in;
2001     cv::GArray<cv::Rect> rr;
2002     cv::GArray<cv::GMat> age, gender;
2003     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
2004     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
2005 
2006     auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
2007 
2008     auto pp = cv::gapi::ie::Params<AgeGender> {
2009         params.model_path, params.weights_path, params.device_id
2010     }.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
2011     comp.apply(cv::gin(frame, m_roi_list),
2012                cv::gout(m_out_gapi_ages, m_out_gapi_genders),
2013                cv::compile_args(cv::gapi::networks(pp)));
2014     // Validate
2015     validate();
2016 }
2017 
TEST_F(ROIList,CallInferMultipleTimes)2018 TEST_F(ROIList, CallInferMultipleTimes)
2019 {
2020     cv::GArray<cv::Rect> rr;
2021     cv::GMat in;
2022     cv::GArray<cv::GMat> age, gender;
2023     std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
2024     cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
2025 
2026     auto pp = cv::gapi::ie::Params<AgeGender> {
2027         params.model_path, params.weights_path, params.device_id
2028     }.cfgOutputLayers({ "age_conv3", "prob" });
2029 
2030     auto cc = comp.compile(cv::descr_of(cv::gin(m_in_mat, m_roi_list)),
2031                            cv::compile_args(cv::gapi::networks(pp)));
2032 
2033     for (int i = 0; i < 10; ++i) {
2034         cc(cv::gin(m_in_mat, m_roi_list), cv::gout(m_out_gapi_ages, m_out_gapi_genders));
2035     }
2036 
2037     validate();
2038 }
2039 
TEST(IEFrameAdapter,blobParams)2040 TEST(IEFrameAdapter, blobParams)
2041 {
2042     cv::Mat bgr = cv::Mat::eye(240, 320, CV_8UC3);
2043     cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);
2044 
2045     auto expected = std::make_pair(IE::TensorDesc{IE::Precision::U8, {1, 3, 300, 300},
2046                                                   IE::Layout::NCHW},
2047                                    IE::ParamMap{{"HELLO", 42}, {"COLOR_FORMAT",
2048                                                                 IE::ColorFormat::NV12}});
2049 
2050     auto actual = cv::util::any_cast<decltype(expected)>(frame.blobParams());
2051 
2052     EXPECT_EQ(expected, actual);
2053 }
2054 
2055 } // namespace opencv_test
2056 
2057 #endif //  HAVE_INF_ENGINE
2058