G-API: Get input model layout from the IR if possible in OV 2.0 backend#24658
Conversation
|
This PR fixes smart classroom G-API demo in OMZ: openvinotoolkit/open_model_zoo#3881 |
|
|
||
| auto f = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{data1}, "function_name"); | ||
|
|
||
| ov::serialize(f, model_path, weights_path, ov::pass::Serialize::Version::IR_V11); |
There was a problem hiding this comment.
Probably there's some general approach to producing temporary files in tests in OpenCV.. Like some specific folder or naming convention?
There was a problem hiding this comment.
btw maybe we in the future we need to extend our API to accept objects of ov::Model directly instead of xml/bin
There was a problem hiding this comment.
btw maybe we in the future we need to extend our API to accept objects of
ov::Modeldirectly instead of xml/bin
In that case it won't be ov::Model because headers will depend on OpenVINO
There was a problem hiding this comment.
Dude we did this with PlaidML already
There was a problem hiding this comment.
plaidml.hpp looks clear from framework details
|
@TolyaTalamanov do you have any comments here? |
| m_input_model_layout.emplace(input_name, default_layout); | ||
| const auto& input_layout = ::ov::layout::get_layout(m_model->input(input_name)); | ||
| if (!input_layout.empty()) { | ||
| input_info.model().set_layout(input_layout); |
There was a problem hiding this comment.
input_info.model() and m_model should refer to the same object, I'm wondering why this line is even needed.
Looks even though model has model layout it must be specified to PrePostProcessor as well.
There was a problem hiding this comment.
Worth a comment at least, since it's not clear why we need to specify model layout for the preprocessor created from exactly the same model.
PrePostProcessor ppp(model);
audo layout = ov::layout::get::layout(model->input(input_name));
if (!layout.empty()) {
ppp.input(input_name).model().set_layout(layout);
}
There was a problem hiding this comment.
Ok, looks we figured out it locally. Need to force model layout only if model doesn't have one otherwise keep it as-is.
There was a problem hiding this comment.
It works without this line. OV works fine
| ov::layout::set_layout(data1, ov::Layout("NHWC")); | ||
|
|
||
| auto sin = std::make_shared<ov::opset8::Sin>(data1); | ||
| sin->output(0).set_names({"sin_t"}); // tensor name |
There was a problem hiding this comment.
not necessarily needed to specify name there
|
|
||
| auto f = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{data1}, "function_name"); | ||
|
|
||
| ov::serialize(f, model_path, weights_path, ov::pass::Serialize::Version::IR_V11); |
There was a problem hiding this comment.
btw maybe we in the future we need to extend our API to accept objects of
ov::Modeldirectly instead of xml/bin
In that case it won't be ov::Model because headers will depend on OpenVINO
| model_path, | ||
| weights_path, | ||
| device_id); | ||
| EXPECT_NO_THROW(comp.apply(cv::gin(in_mat1), cv::gout(gapi_mat), |
There was a problem hiding this comment.
Tbh I didn't get the purpose of this test, the model has NHWC layout but you pass NCHW mat, so it won't throw any exceptions because ov backend doesn't validate either layouts match or not.
The test should be something like that:
- Model has
NHWClayout - Provide 4D mat and specify only
tensorlayout (e.g cfgInputTensorLayout('NCHW')) - Check if there is
NHWC->NCHWconversion is added to the model. (it won't be added without your changes, since model layout not specified therefore won't be propagated intoPrePostProcessor)
| m_input_model_layout.emplace(input_name, default_layout); | ||
| const auto& input_layout = ::ov::layout::get_layout(m_model->input(input_name)); | ||
| if (!input_layout.empty()) { | ||
| input_info.model().set_layout(input_layout); |
There was a problem hiding this comment.
Worth a comment at least, since it's not clear why we need to specify model layout for the preprocessor created from exactly the same model.
PrePostProcessor ppp(model);
audo layout = ov::layout::get::layout(model->input(input_name));
if (!layout.empty()) {
ppp.input(input_name).model().set_layout(layout);
}
| m_input_model_layout.emplace(input_name, default_layout); | ||
| const auto& input_layout = ::ov::layout::get_layout(m_model->input(input_name)); | ||
| if (!input_layout.empty()) { | ||
| input_info.model().set_layout(input_layout); |
There was a problem hiding this comment.
Looking at it on the second day, is this a valid change at all? Why we're setting whole model's layout based on some input layout?
There was a problem hiding this comment.
It's not for the whole model, it's set to input_info which refers to the particular input layer.
input_info = m_ppp.input(input_name);
...
input_info.model().set_layout(input_layout);
There was a problem hiding this comment.
This line will be removed, since OV does it in their PrePostProc
|
Please explain what is the issue and what is the change here. |
The issue is that user might not want to configure input model layout which is available in the network. So, they don't set |
18ed79e to
f6240db
Compare
|
@asmorkalov @mshabunin can we merge this please? |
|
@asmorkalov @mshabunin kind reminder |
|
@asmorkalov @mshabunin can we merge it this week pretty please? |
…del_layout G-API: Get input model layout from the IR if possible in OV 2.0 backend opencv#24658 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] 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 - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.