Skip to content

[G-API] Pipeline modeling tool - support local infer node config#22518

Merged
asmorkalov merged 3 commits intoopencv:4.xfrom
TolyaTalamanov:at/expand-modeling-tool-to-support-config-in-yml
Sep 27, 2022
Merged

[G-API] Pipeline modeling tool - support local infer node config#22518
asmorkalov merged 3 commits intoopencv:4.xfrom
TolyaTalamanov:at/expand-modeling-tool-to-support-config-in-yml

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov commented Sep 15, 2022

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

Overview

The motivation of this PR is the following:

  1. Some NN models might require individual config
  2. Specifying config in .yml config file once is more convenient if it isn't supposed to be changed according user scenario.

The logic is following:

  • User can specify configuration parameters for every Infer node locally via .yml config file.
  • local config might be combined with global (in case it's specified via --load_config) until they have key conflicts.
  • In case "key conflict" app reports the problem and crash.
build_image:Custom=centos:7
buildworker:Custom=linux-1

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@smirnov-alexey @dmatveev Hi folks! Could you have a look?

@smirnov-alexey smirnov-alexey self-requested a review September 15, 2022 13:23
Copy link
Copy Markdown
Contributor

@smirnov-alexey smirnov-alexey left a comment

Choose a reason for hiding this comment

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

Looks good

@dmatveev dmatveev self-assigned this Sep 15, 2022
@dmatveev dmatveev added this to the 4.7.0 milestone Sep 15, 2022
} else if (node_type == "Infer") {
auto infer_params = read<InferParams>(node_fn);
infer_params.config = config;
RETHROW_WITH_MSG_IF_FAILED(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally, macros are evil /=

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll remove this macro and leave just try-catch there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

infer_params.config = config;
RETHROW_WITH_MSG_IF_FAILED(
utils::intersectMapWith(infer_params.config, gconfig),
"Failed to combine global and local configs for Infer node: "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why it could fail? How user could deal with it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If user provides global and local configs that have intersection app fails with: Met dublicated key which is not descriptive. It would be great to see something like: Failed to merge global & local configs for model <model.xml>, but utils::intersectMapWith knows nothing about modes & configs it just merges map's

std::stringstream ss; \
ss << msg << "\n caused by: " << e.what(); \
throw std::logic_error(ss.str()); \
} \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the reason to do this? Maybe @sivanov-work have more to say here? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Answered above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed ugly macro

if (it != target.end()) {
throw std::logic_error("Met already existing key: " + item.first);
}
target.insert(item);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In set theory, intersection is something different from this, isn't it?

Don't you just merge two maps into one with handling the "overwrites"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point!

Copy link
Copy Markdown
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&& item : second) {
auto it = target.find(item.first);
if (it != target.end()) {
throw std::logic_error("Met already existing key: " + item.first);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Error: key X already exists in Y" is better IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but X & Y are nameless.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

X is the value of your item.first.

Y is the map you're merging into.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This Y doesn't have a name. Done

* Rename intersectMapWith -> mergeMapWith
* Remove macro
* Add r-value ref
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

Is everybody OK to merge it?


template <typename K, typename V>
void mergeMapWith(std::map<K, V>& target, const std::map<K, V>& second) {
for (auto&& item : second) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

/build/precommit_linux64/4.x/opencv/modules/gapi/samples/pipeline_modeling_tool.cpp:196:5: error: invalid initialization of non-const reference of type 'cv::FileNode&' from an rvalue of type 'cv::FileNode

Reverted back

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek @asmorkalov Can it be merged?

@TolyaTalamanov TolyaTalamanov force-pushed the at/expand-modeling-tool-to-support-config-in-yml branch from 6a5f68c to 4521d66 Compare September 26, 2022 11:54
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

default job has passed

@asmorkalov asmorkalov merged commit 3a64607 into opencv:4.x Sep 27, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
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.

4 participants