Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gapi: fix building wihout video module, fix infer test #18397

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion modules/gapi/test/cpu/gapi_ocv_stateful_kernel_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include <opencv2/core.hpp>
#include <opencv2/core/cvstd.hpp>
#ifdef HAVE_OPENCV_VIDEO
#include <opencv2/video.hpp>
#endif


namespace opencv_test
Expand Down Expand Up @@ -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 */,
Expand All @@ -140,6 +142,7 @@ namespace
state.apply(in, out, -1);
}
};
#endif
};

TEST(StatefulKernel, StateIsMutableInRuntime)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -340,6 +346,7 @@ TEST(StatefulKernel, StateIsInitViaCompArgsInStreaming)
// Allowing 5% difference of all pixels between G-API and reference OpenCV results
testBackSubInStreaming(gapiBackSub, 5);
}
#endif
//-------------------------------------------------------------------------------------------------------------


Expand Down
60 changes: 15 additions & 45 deletions modules/gapi/test/infer/gapi_infer_ie_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 /*= ""*/,
Expand All @@ -56,46 +62,6 @@ void normAssert(cv::InputArray ref, cv::InputArray test,
EXPECT_LE(normInf, lInf) << comment;
}

std::vector<std::string> modelPathByName(const std::string &model_name) {
// Handle OMZ model layout changes among OpenVINO versions here
static const std::unordered_multimap<std::string, std::string> 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<std::string> result;
for (auto it = range.first; it != range.second; ++it) {
result.emplace_back(it->second);
}
return result;
}

std::tuple<std::string, std::string> 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) {
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -221,9 +189,10 @@ struct ROIList: public ::testing::Test {
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "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));
Expand Down Expand Up @@ -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
Expand Down