mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #27549 from atamas19:tensor_naming_functionality
G-API: Implement cfgEnsureNamedTensors option to OpenVINO Params #27549 Added the option cfgEnsureNamedTensors to be applied on OpenVINO models with nameless tensors. If a tensor doesn't have a name, it sets a default one. The default name is created using OpenVINO's standard `make_default_tensor_name` . `make_default_tensor_name` had to be rewritten because it is only available in OpenVINO's dev_api. ### 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 - [ ] 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
This commit is contained in:
@@ -69,6 +69,27 @@ ov::Core cv::gapi::ov::wrap::getCore() {
|
||||
? create_OV_Core_pointer() : create_OV_Core_instance();
|
||||
}
|
||||
|
||||
static std::string make_default_tensor_name(const ov::Output<const ov::Node>& output) {
|
||||
auto default_name = output.get_node()->get_friendly_name();
|
||||
if (output.get_node()->get_output_size() > 1) {
|
||||
default_name += ':' + std::to_string(output.get_index());
|
||||
}
|
||||
return default_name;
|
||||
}
|
||||
|
||||
static void ensureNamedTensors(std::shared_ptr<ov::Model> model) {
|
||||
for (auto& input : model->inputs()) {
|
||||
if (input.get_names().empty()) {
|
||||
input.set_names({make_default_tensor_name(input)});
|
||||
}
|
||||
}
|
||||
for (auto& output : model->outputs()) {
|
||||
if (output.get_names().empty()) {
|
||||
output.set_names({make_default_tensor_name(output)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ov::AnyMap toOV(const ParamDesc::PluginConfigT &config) {
|
||||
return {config.begin(), config.end()};
|
||||
}
|
||||
@@ -236,6 +257,10 @@ struct OVUnit {
|
||||
.read_model(desc.model_path, desc.bin_path);
|
||||
GAPI_Assert(model);
|
||||
|
||||
if (params.ensure_named_tensors) {
|
||||
ensureNamedTensors(model);
|
||||
}
|
||||
|
||||
if (params.num_in == 1u && params.input_names.empty()) {
|
||||
params.input_names = { model->inputs().begin()->get_any_name() };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user