Skip to content

[G-API] Fix bugs in GIEBackend #20918

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

Merged
merged 24 commits into from
Nov 15, 2021

Conversation

TolyaTalamanov
Copy link
Contributor

@TolyaTalamanov TolyaTalamanov commented Oct 21, 2021

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

Bugs overview

  1. Outputs map are filled only for LoadNetwork case.
    These maps: https://github.com/opencv/opencv/blob/master/modules/gapi/src/backends/ie/giebackend.cpp#L221-L222 are filled only in case LoadNetwork: https://github.com/opencv/opencv/blob/master/modules/gapi/src/backends/ie/giebackend.cpp#L241-L242, but are used by both of them:
    https://github.com/opencv/opencv/blob/master/modules/gapi/src/backends/ie/giebackend.cpp#L953
  2. cv::gapi::ie::Params::pluginConfig(IEConfig) set config globally to IE::Core, but should be set locally within ExecutableNetwork: https://github.com/opencv/opencv/blob/master/modules/gapi/src/backends/ie/giebackend.cpp#L244-L245
  3. In case ImportNetwork preprocessing should be passed as ExecutableNetwork::SetBlob argument, now preprocessing for NV12 color format is missed.

Build configuration

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.4.1:20.04
build_image:Custom Win=openvino-2021.4.1
build_image:Custom Mac=openvino-2021.4.1

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@@ -218,8 +218,6 @@ struct IEUnit {

cv::gapi::ie::detail::ParamDesc params;
IE::CNNNetwork net;
IE::InputsDataMap inputs;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's better to removed them not get confused because they're relevant only in case LoadNetwork


IE::ExecutableNetwork this_network;
cv::gimpl::ie::wrap::Plugin this_plugin;

InferenceEngine::RemoteContext::Ptr rctx = nullptr;
using PreProcMap = std::unordered_map<std::string, IE::PreProcessInfo>;
mutable cv::util::optional<PreProcMap> preproc_map;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, relevant only for ImportNetwork case, but should be stored anywhere after it's collected in outMeta method.

@TolyaTalamanov TolyaTalamanov changed the title [G-API] Fix bug with empty map for importNetwork [G-API] Fix bugs in GIEBackend Oct 26, 2021
static IE::PreProcessInfo configurePreProcInfo(const IE::InputInfo::CPtr& ii,
const cv::GMetaArg& mm) {

IE::PreProcessInfo info;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case code won't go to none of these if's, IE::PreProcessInfo is empty, I believe that passing that to ExecutableNetwork::SetBlob is OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't IE find preprocessing by name because info is empty?

Looks like code comment. API may be changed in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant for some inputs preprocessing isn't needed, in that case map will contain empty IE::PreProcessInfo.

Copy link
Contributor

@mpashchenkov mpashchenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be back bit later.

initDLDTDataPath();

cv::gapi::ie::detail::ParamDesc params;
params.model_path= compileAgeGenderBlob();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params.model_path= compileAgeGenderBlob();
params.model_path = compileAgeGenderBlob();

static IE::PreProcessInfo configurePreProcInfo(const IE::InputInfo::CPtr& ii,
const cv::GMetaArg& mm) {

IE::PreProcessInfo info;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't IE find preprocessing by name because info is empty?

Looks like code comment. API may be changed in the future.

TolyaTalamanov and others added 2 commits October 26, 2021 18:03
Co-authored-by: Maxim Pashchenkov <maxim.pashchenkov@intel.com>
Co-authored-by: Maxim Pashchenkov <maxim.pashchenkov@intel.com>
const IE::DataPtr& ie_out = uu.outputs.at(out_name);
const IE::SizeVector dims = ie_out->getTensorDesc().getDims();
const auto& desc =
uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly speaking looks awful, does anyone know how these different interfaces can be hidden? Should it be hidden at all?

} else if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import) {
this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
this_plugin.SetConfig(params.config);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config shouldn't be set to global IECore object, moved this part to loadNetwork and importNetwork

@@ -2239,6 +2267,141 @@ TEST(TestAgeGenderIE, InferWithBatch)
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}


TEST(ImportNetwork, Infer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImportNetwork only tested for Infer kernel for BGR & NV12 format, testing other kernels on both of formats cause a huge code duplication I'd scope tests refactoring firstly, @dmatveev what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImportNetwork only tested for Infer kernel for BGR & NV12 format, testing other kernels on both of formats cause a huge code duplication I'd scope tests refactoring firstly, @dmatveev what do you think?

Added 8 tests: [Infer, InferROI, InferList, InferList2] x [BGR, NV12]

Didn't test InferList2 on raw inputs


IE::ExecutableNetwork this_network;
cv::gimpl::ie::wrap::Plugin this_plugin;

InferenceEngine::RemoteContext::Ptr rctx = nullptr;

// FIXME: This map contains preprocessing information
// for input layers in case ImportNetwork. Since this map is collected in
// outMeta which is const, need to mark map as mutable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preproc_map isn't mutable already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thanks!

@@ -822,6 +818,24 @@ static void configureInputInfo(const IE::InputInfo::Ptr& ii, const cv::GMetaArg
}
}

static IE::PreProcessInfo configurePreProcInfo(const IE::InputInfo::CPtr& ii,
const cv::GMetaArg& mm) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

for (auto &&it : ade::util::zip(ade::util::toRange(uu.params.input_names),
ade::util::toRange(in_metas))) {
const auto &input_name = std::get<0>(it);
auto &&ii = uu.inputs.at(input_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused warning on Mac build

@TolyaTalamanov TolyaTalamanov force-pushed the at/fix-empty-map-importNetwork branch from 5a3268f to 782abb2 Compare October 29, 2021 12:42
static IE::Core core;
return core;
}

IE::Core giewrap::getCore() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#16356

static InferenceEngine::Core* init_core = new InferenceEngine::Core(); // 'delete' is never called

cv::Mat m_mat;
Sync& m_sync;
cv::Mat m_mat;
std::shared_ptr<Sync> m_sync;
Copy link
Contributor Author

@TolyaTalamanov TolyaTalamanov Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just handled the case where GMockMediaAdapter live more than GMockSource

Copy link
Contributor

@mpashchenkov mpashchenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TolyaTalamanov
Copy link
Contributor Author

@alalek Could you have a look, please?

@dmatveev dmatveev self-assigned this Nov 10, 2021
Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , thanks!

@@ -2239,6 +2282,582 @@ TEST(TestAgeGenderIE, InferWithBatch)
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}

TEST(ImportNetwork, Infer)
{
const std::string device = "MYRIAD";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed task to avoid code duplication in tests

@TolyaTalamanov
Copy link
Contributor Author

@alalek Could you merge it?

@TolyaTalamanov
Copy link
Contributor Author

@alalek it seems to be ready for merge

@alalek alalek merged commit 2b2e515 into opencv:4.x Nov 15, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…importNetwork

[G-API] Fix bugs in GIEBackend

* Remove inputs/outputs map from IEUnit

* Add test

* Add NV12 test

* Reorganize setBlob function

* Check that backend don't overwrite blob precision

* Stop setting config to global IE::Core

* Replace mutable to const_cast

* Update modules/gapi/test/infer/gapi_infer_ie_test.cpp

* Update modules/gapi/test/infer/gapi_infer_ie_test.cpp

* Make blob parameter as const ref

* Cosmetic fixes

* Fix failed test on inferROI

* Removed double ref for ii

* Disable tests

* Skip tests if device not available

* Use Sync prim under shared_ptr to avoid issue on MAC

* Apply WA for IE::Core

* Apply WA for MAC build

* Try to apply another WA

* Not release IE::Core for apple

* Put comment

* Support PreprocInfo for

* InferROI
* InferList
* InferList2

* Remove empty line

* Fix alignment

Co-authored-by: Maxim Pashchenkov <maxim.pashchenkov@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants