From 7186c463776fbec2129c2d3a6052fc29168cc393 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 23 Sep 2020 16:19:26 +0300 Subject: [PATCH] gapi: fix building wihout video module, fix infer test --- .../test/cpu/gapi_ocv_stateful_kernel_tests.cpp | 9 +++- modules/gapi/test/infer/gapi_infer_ie_test.cpp | 60 ++++++---------------- 2 files changed, 23 insertions(+), 46 deletions(-) diff --git a/modules/gapi/test/cpu/gapi_ocv_stateful_kernel_tests.cpp b/modules/gapi/test/cpu/gapi_ocv_stateful_kernel_tests.cpp index 53d85ce..75ca798 100644 --- a/modules/gapi/test/cpu/gapi_ocv_stateful_kernel_tests.cpp +++ b/modules/gapi/test/cpu/gapi_ocv_stateful_kernel_tests.cpp @@ -10,7 +10,9 @@ #include #include +#ifdef HAVE_OPENCV_VIDEO #include +#endif namespace opencv_test @@ -117,7 +119,7 @@ namespace { static GMatDesc outMeta(GMatDesc in) { return in.withType(CV_8U, 1); } }; - +#ifdef HAVE_OPENCV_VIDEO GAPI_OCV_KERNEL_ST(GOCVBackSub, GBackSub, cv::BackgroundSubtractor) { static void setup(const cv::GMatDesc &/* desc */, @@ -140,6 +142,7 @@ namespace state.apply(in, out, -1); } }; +#endif }; TEST(StatefulKernel, StateIsMutableInRuntime) @@ -224,6 +227,7 @@ TEST(StatefulKernel, InvalidReallocatingKernel) EXPECT_THROW(comp.apply(in_mat, out_mat, cv::compile_args(pkg)), std::logic_error); } +#ifdef HAVE_OPENCV_VIDEO namespace { void compareBackSubResults(const cv::Mat &actual, const cv::Mat &expected, @@ -284,7 +288,9 @@ TEST(StatefulKernel, StateIsInitViaCompArgs) pOcvBackSub->apply(frame, ocvForeground); compareBackSubResults(gapiForeground, ocvForeground, 1); } +#endif +#ifdef HAVE_OPENCV_VIDEO namespace { void testBackSubInStreaming(cv::GStreamingCompiled gapiBackSub, const int diffPercent) @@ -340,6 +346,7 @@ TEST(StatefulKernel, StateIsInitViaCompArgsInStreaming) // Allowing 5% difference of all pixels between G-API and reference OpenCV results testBackSubInStreaming(gapiBackSub, 5); } +#endif //------------------------------------------------------------------------------------------------------------- diff --git a/modules/gapi/test/infer/gapi_infer_ie_test.cpp b/modules/gapi/test/infer/gapi_infer_ie_test.cpp index b584f5b..74d8558 100644 --- a/modules/gapi/test/infer/gapi_infer_ie_test.cpp +++ b/modules/gapi/test/infer/gapi_infer_ie_test.cpp @@ -44,6 +44,12 @@ static void initDLDTDataPath() #endif // WINRT } +#if INF_ENGINE_RELEASE >= 2020010000 +static const std::string SUBDIR = "intel/age-gender-recognition-retail-0013/FP32/"; +#else +static const std::string SUBDIR = "Retail/object_attributes/age_gender/dldt/"; +#endif + // FIXME: taken from the DNN module void normAssert(cv::InputArray ref, cv::InputArray test, const char *comment /*= ""*/, @@ -56,46 +62,6 @@ void normAssert(cv::InputArray ref, cv::InputArray test, EXPECT_LE(normInf, lInf) << comment; } -std::vector modelPathByName(const std::string &model_name) { - // Handle OMZ model layout changes among OpenVINO versions here - static const std::unordered_multimap map = { -#if INF_ENGINE_RELEASE >= 2019040000 // >= 2019.R4 - {"age-gender-recognition-retail-0013", - "2020.3.0/intel/age-gender-recognition-retail-0013/FP32"}, -#endif // INF_ENGINE_RELEASE >= 2019040000 - {"age-gender-recognition-retail-0013", - "Retail/object_attributes/age_gender/dldt"}, - }; - const auto range = map.equal_range(model_name); - std::vector result; - for (auto it = range.first; it != range.second; ++it) { - result.emplace_back(it->second); - } - return result; -} - -std::tuple findModel(const std::string &model_name) { - const auto candidates = modelPathByName(model_name); - CV_Assert(!candidates.empty() && "No model path candidates found at all"); - - for (auto &&path : candidates) { - std::string model_xml, model_bin; - try { - model_xml = findDataFile(path + "/" + model_name + ".xml", false); - model_bin = findDataFile(path + "/" + model_name + ".bin", false); - // Return the first file which actually works - return std::make_tuple(model_xml, model_bin); - } catch (SkipTestException&) { - // This is quite ugly but it is a way for OpenCV to let us know - // this file wasn't found. - continue; - } - } - - // Default behavior if reached here. - throw SkipTestException("Files for " + model_name + " were not found"); -} - namespace IE = InferenceEngine; void setNetParameters(IE::CNNNetwork& net) { @@ -112,7 +78,8 @@ TEST(TestAgeGenderIE, InferBasicTensor) initDLDTDataPath(); cv::gapi::ie::detail::ParamDesc params; - std::tie(params.model_path, params.weights_path) = findModel("age-gender-recognition-retail-0013"); + 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. @@ -162,7 +129,8 @@ TEST(TestAgeGenderIE, InferBasicImage) initDLDTDataPath(); cv::gapi::ie::detail::ParamDesc params; - std::tie(params.model_path, params.weights_path) = findModel("age-gender-recognition-retail-0013"); + 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"; // FIXME: Ideally it should be an image from disk @@ -221,9 +189,10 @@ struct ROIList: public ::testing::Test { using AGInfo = std::tuple; G_API_NET(AgeGender, , "test-age-gender"); - ROIList() { + void SetUp() { initDLDTDataPath(); - std::tie(params.model_path, params.weights_path) = findModel("age-gender-recognition-retail-0013"); + 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"; // FIXME: it must be cv::imread(findDataFile("../dnn/grace_hopper_227.png", false)); @@ -316,7 +285,8 @@ TEST(DISABLED_TestTwoIENNPipeline, InferBasicImage) initDLDTDataPath(); cv::gapi::ie::detail::ParamDesc AGparams; - std::tie(AGparams.model_path, AGparams.weights_path) = findModel("age-gender-recognition-retail-0013"); + AGparams.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml", false); + AGparams.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin", false); AGparams.device_id = "MYRIAD"; // FIXME: Ideally it should be an image from disk -- 2.7.4