未验证 提交 0cf45b89 编写于 作者: A Anatoliy Talamanov 提交者: GitHub

Merge pull request #23796 from TolyaTalamanov:at/align-ie-backend-with-latest-openvino

G-API: Align IE Backend with the latest OpenVINO version #23796

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
上级 004801f1
......@@ -949,7 +949,11 @@ inline IE::Blob::Ptr extractBlob(IECallContext& ctx,
auto y_blob = ctx.uu.rctx->CreateBlob(blob_params->first.first, blob_params->first.second);
auto uv_blob = ctx.uu.rctx->CreateBlob(blob_params->second.first, blob_params->second.second);
#if INF_ENGINE_RELEASE >= 2021010000
#if INF_ENGINE_RELEASE > 2023000000
cv::util::throw_error(std::logic_error(
"IE Backend: NV12 feature has been deprecated in OpenVINO 1.0 API."
" The last version which supports this is 2023.0"));
#elif INF_ENGINE_RELEASE >= 2021010000
return IE::make_shared_blob<IE::NV12Blob>(y_blob, uv_blob);
#else
return IE::make_shared_blob<InferenceEngine::NV12Blob>(y_blob, uv_blob);
......@@ -982,7 +986,14 @@ static void setBlob(InferenceEngine::InferRequest& req,
req.SetBlob(layer_name, blob);
} else {
GAPI_Assert(ctx.uu.params.kind == ParamDesc::Kind::Import);
#if INF_ENGINE_RELEASE > 2023000000
// NB: SetBlob overload which accepts IE::PreProcessInfo
// has been deprecated - preprocessing can't be configured
// for "Import" networks anymore.
req.SetBlob(layer_name, blob);
#else
req.SetBlob(layer_name, blob, ctx.uu.preproc_map.at(layer_name));
#endif
}
}
......@@ -1370,7 +1381,14 @@ static void cfgImagePreprocessing(const IE::InputInfo::Ptr &ii,
if (cv::util::holds_alternative<cv::GFrameDesc>(mm)) {
const auto &meta = util::get<cv::GFrameDesc>(mm);
if (meta.fmt == cv::MediaFormat::NV12) {
#if INF_ENGINE_RELEASE > 2023000000
cv::util::throw_error(std::logic_error(
"IE Backend: cv::MediaFrame with NV12 format is no longer supported"
" because NV12 feature has been deprecated in OpenVINO 1.0 API."
" The last version which supports this is 2023.0"));
#else
ii->getPreProcess().setColorFormat(IE::ColorFormat::NV12);
#endif
}
}
}
......@@ -1426,7 +1444,14 @@ static IE::PreProcessInfo createImagePreProcInfo(const cv::GMetaArg &mm,
if (cv::util::holds_alternative<cv::GFrameDesc>(mm)) {
const auto &meta = util::get<cv::GFrameDesc>(mm);
if (meta.fmt == cv::MediaFormat::NV12) {
#if INF_ENGINE_RELEASE > 2023000000
cv::util::throw_error(std::logic_error(
"IE Backend: cv::MediaFrame with NV12 format is no longer supported"
" because NV12 feature has been deprecated in OpenVINO 1.0 API."
" The last version which supports this is 2023.0"));
#else
info.setColorFormat(IE::ColorFormat::NV12);
#endif
}
}
return info;
......@@ -2299,7 +2324,11 @@ IE::Blob::Ptr cv::gapi::ie::util::to_ie(const cv::Mat &blob) {
IE::Blob::Ptr cv::gapi::ie::util::to_ie(const cv::Mat &y_plane, const cv::Mat &uv_plane) {
auto y_blob = wrapIE(y_plane, cv::gapi::ie::TraitAs::IMAGE);
auto uv_blob = wrapIE(uv_plane, cv::gapi::ie::TraitAs::IMAGE);
#if INF_ENGINE_RELEASE >= 2021010000
#if INF_ENGINE_RELEASE > 2023000000
cv::util::throw_error(std::logic_error(
"IE Backend: NV12 feature has been deprecated in OpenVINO 1.0 API."
" The last version which supports this is 2023.0"));
#elif INF_ENGINE_RELEASE >= 2021010000
return IE::make_shared_blob<IE::NV12Blob>(y_blob, uv_blob);
#else
return IE::make_shared_blob<InferenceEngine::NV12Blob>(y_blob, uv_blob);
......
......@@ -62,6 +62,11 @@ public:
return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
}
cv::util::any blobParams() const override {
#if INF_ENGINE_RELEASE > 2023000000
// NB: blobParams() shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
GAPI_Assert(false && "NV12 feature has been deprecated in OpenVINO 1.0 API.");
#else
return std::make_pair<InferenceEngine::TensorDesc,
InferenceEngine::ParamMap>({IE::Precision::U8,
{1, 3, 300, 300},
......@@ -69,6 +74,7 @@ public:
{{"HELLO", 42},
{"COLOR_FORMAT",
InferenceEngine::ColorFormat::NV12}});
#endif // INF_ENGINE_RELEASE > 2023000000
}
};
......@@ -138,7 +144,13 @@ void setNetParameters(IE::CNNNetwork& net, bool is_nv12 = false) {
ii->setPrecision(IE::Precision::U8);
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
if (is_nv12) {
#if INF_ENGINE_RELEASE > 2023000000
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
GAPI_Assert(false && "NV12 feature has been deprecated in OpenVINO 1.0 API.");
#else
ii->getPreProcess().setColorFormat(IE::ColorFormat::NV12);
#endif // INF_ENGINE_RELEASE > 2023000000
}
}
......@@ -392,10 +404,14 @@ struct InferWithReshapeNV12: public InferWithReshape {
cv::randu(m_in_y, 0, 255);
m_in_uv = cv::Mat{sz / 2, CV_8UC2};
cv::randu(m_in_uv, 0, 255);
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
#if INF_ENGINE_RELEASE <= 2023000000
setNetParameters(net, true);
net.reshape({{"data", reshape_dims}});
auto frame_blob = cv::gapi::ie::util::to_ie(m_in_y, m_in_uv);
inferROIs(frame_blob);
#endif // INF_ENGINE_RELEASE <= 2023000000
}
};
......@@ -505,8 +521,11 @@ struct ROIListNV12: public ::testing::Test {
cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
};
// Load & run IE network
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
#if INF_ENGINE_RELEASE <= 2023000000
{
// Load & run IE network
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto net = cv::gimpl::ie::wrap::readNetwork(params);
setNetParameters(net, true);
......@@ -530,9 +549,11 @@ struct ROIListNV12: public ::testing::Test {
m_out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
} // namespace IE = ..
#endif // INF_ENGINE_RELEASE <= 2023000000
} // ROIList()
void validate() {
#if INF_ENGINE_RELEASE <= 2023000000
// Validate with IE itself (avoid DNN module dependency here)
ASSERT_EQ(2u, m_out_ie_ages.size());
ASSERT_EQ(2u, m_out_ie_genders.size());
......@@ -543,6 +564,10 @@ struct ROIListNV12: public ::testing::Test {
normAssert(m_out_ie_genders[0], m_out_gapi_genders[0], "0: Test gender output");
normAssert(m_out_ie_ages [1], m_out_gapi_ages [1], "1: Test age output");
normAssert(m_out_ie_genders[1], m_out_gapi_genders[1], "1: Test gender output");
#else
GAPI_Assert(false && "Reference hasn't been calculated because"
" NV12 feature has been deprecated.");
#endif // INF_ENGINE_RELEASE <= 2023000000
}
};
......@@ -631,6 +656,9 @@ struct SingleROINV12: public ::testing::Test {
m_roi = cv::Rect(cv::Point{64, 60}, cv::Size{96, 96});
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
#if INF_ENGINE_RELEASE <= 2023000000
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
......@@ -657,12 +685,18 @@ struct SingleROINV12: public ::testing::Test {
m_out_ie_age = to_ocv(infer_request.GetBlob("age_conv3")).clone();
m_out_ie_gender = to_ocv(infer_request.GetBlob("prob")).clone();
}
#endif // INF_ENGINE_RELEASE <= 2023000000
}
void validate() {
#if INF_ENGINE_RELEASE <= 2023000000
// Validate with IE itself (avoid DNN module dependency here)
normAssert(m_out_ie_age , m_out_gapi_age , "Test age output");
normAssert(m_out_ie_gender, m_out_gapi_gender, "Test gender output");
#else
GAPI_Assert(false && "Reference hasn't been calculated because"
" NV12 feature has been deprecated.");
#endif
}
};
......@@ -962,11 +996,20 @@ TEST_F(ROIListNV12, MediaInputNV12)
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST(TestAgeGenderIE, MediaInputNV12)
......@@ -986,6 +1029,9 @@ TEST(TestAgeGenderIE, MediaInputNV12)
cv::Mat gapi_age, gapi_gender;
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
#if INF_ENGINE_RELEASE <= 2023000000
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
......@@ -999,6 +1045,7 @@ TEST(TestAgeGenderIE, MediaInputNV12)
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
#endif
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
......@@ -1014,13 +1061,20 @@ TEST(TestAgeGenderIE, MediaInputNV12)
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST(TestAgeGenderIE, MediaInputBGR)
......@@ -1155,6 +1209,9 @@ TEST(InferROI, MediaInputNV12)
cv::Mat gapi_age, gapi_gender;
cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
// NB: NV12 feature shouldn't be used in tests
// if OpenVINO versions is higher than 2023.0
#if INF_ENGINE_RELEASE <= 2023000000
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
......@@ -1176,6 +1233,7 @@ TEST(InferROI, MediaInputNV12)
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
#endif
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
......@@ -1192,13 +1250,20 @@ TEST(InferROI, MediaInputNV12)
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, rect), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, rect), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST_F(ROIList, Infer2MediaInputBGR)
......@@ -1233,10 +1298,20 @@ TEST_F(ROIListNV12, Infer2MediaInputNV12)
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST_F(SingleROI, GenericInfer)
......@@ -1310,10 +1385,19 @@ TEST_F(SingleROINV12, GenericInferMediaNV12)
pp.cfgNumRequests(2u);
auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi), cv::gout(m_out_gapi_age, m_out_gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi),
cv::gout(m_out_gapi_age, m_out_gapi_gender),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST_F(ROIList, GenericInfer)
......@@ -1386,11 +1470,20 @@ TEST_F(ROIListNV12, GenericInferMediaNV12)
pp.cfgNumRequests(2u);
auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST_F(ROIList, GenericInfer2)
......@@ -1461,10 +1554,20 @@ TEST_F(ROIListNV12, GenericInfer2MediaInputNV12)
pp.cfgNumRequests(2u);
auto frame = MediaFrame::Create<TestMediaNV12>(m_in_y, m_in_uv);
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST(Infer, SetInvalidNumberOfRequests)
......@@ -2050,11 +2153,20 @@ TEST_F(InferWithReshapeNV12, TestInferListYUV)
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" }).cfgInputReshape({{"data", reshape_dims}});
// NB: NV12 feature has been deprecated in OpenVINO versions higher
// than 2023.0 so G-API must throw error in that case.
#if INF_ENGINE_RELEASE <= 2023000000
comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
// Validate
validate();
#else
EXPECT_ANY_THROW(comp.apply(cv::gin(frame, m_roi_list),
cv::gout(m_out_gapi_ages, m_out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp))));
#endif
}
TEST_F(ROIList, CallInferMultipleTimes)
......@@ -2079,6 +2191,7 @@ TEST_F(ROIList, CallInferMultipleTimes)
validate();
}
#if INF_ENGINE_RELEASE <= 2023000000
TEST(IEFrameAdapter, blobParams)
{
cv::Mat bgr = cv::Mat::eye(240, 320, CV_8UC3);
......@@ -2093,6 +2206,7 @@ TEST(IEFrameAdapter, blobParams)
EXPECT_EQ(expected, actual);
}
#endif
namespace
{
......@@ -2281,6 +2395,10 @@ TEST(TestAgeGenderIE, InferWithBatch)
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
// NB: All tests below use preprocessing for "Import" networks
// passed as the last argument to SetBLob. This overload has
// been deprecated in OpenVINO 1.0 API.
#if INF_ENGINE_RELEASE <= 2023000000
TEST(ImportNetwork, Infer)
{
const std::string device = "MYRIAD";
......@@ -2820,6 +2938,7 @@ TEST(ImportNetwork, InferList2NV12)
normAssert(out_ie_genders[i], out_gapi_genders[i], "Test gender output");
}
}
#endif
TEST(TestAgeGender, ThrowBlobAndInputPrecisionMismatch)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册