gapi: fix building wihout video module, fix infer test

This commit is contained in:
Maksim Shabunin 2020-09-23 16:19:26 +03:00
parent 45ee8e2532
commit 7186c46377
2 changed files with 23 additions and 46 deletions

View File

@ -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
@ -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
//-------------------------------------------------------------------------------------------------------------

View File

@ -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<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) {
@ -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<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));
@ -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