Skip to content

Commit

Permalink
Tests failed without reshape paramter due to uninitilized value (open…
Browse files Browse the repository at this point in the history
…vinotoolkit#27814)

### Details:
Fixed problem in protopipe 
- if the "reshape" parameter was not set and not needed application
would fail with bad variant access

---------

Co-authored-by: Anastasiya(Asya) Pronina <[email protected]>
  • Loading branch information
SeptimiuIoachimNeagaIntel and AsyaPronina authored Dec 12, 2024
1 parent eb05746 commit e2fce1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/intel_npu/tools/protopipe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ log_level: INFO
- `ol` - **Optional**. Output layer layout.
- `iml` - **Optional**. Input model layout.
- `oml` - **Optional**. Output model layout.
- `reshape` - **Optional**. Set shape for input layers. For example, "input1: [1,3,224,224], input2: [1,4]" or "[1,3,224,224]" in case of one input layer.

Examples:
```
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ struct convert<OpenVINOParams> {
params.output_model_layout = node["oml"].as<LayerVariantAttr<std::string>>();
}

if (node["reshape"]) {
params.reshape = node["reshape"].as<LayerVariantAttr<std::vector<size_t>>> ();
}

if (node["config"]) {
params.config = node["config"].as<std::map<std::string, std::string>>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct OpenVINOParams {
LayerVariantAttr<std::string> output_layout;
LayerVariantAttr<std::string> input_model_layout;
LayerVariantAttr<std::string> output_model_layout;
LayerVariantAttr<std::vector<size_t>> reshape;
std::map<std::string, std::string> config;
size_t nireq = 1u;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ static void cfgOutputPostproc(ov::preprocess::PrePostProcessor& ppp, const std::
}
}

static void cfgReshape(const std::shared_ptr<ov::Model>& model,
const AttrMap<std::vector<size_t>> reshape_map) {
std::map<std::string, ov::PartialShape> partial_shapes;
for (const auto& [layer_name, shape] : reshape_map) {
partial_shapes.emplace(layer_name, shape);
}
model->reshape(partial_shapes);
}

static std::vector<std::string> extractLayerNames(const std::vector<ov::Output<ov::Node>>& nodes) {
std::vector<std::string> names;
std::transform(nodes.begin(), nodes.end(), std::back_inserter(names), [](const auto& node) {
Expand All @@ -148,6 +157,9 @@ InOutLayers OpenVINOLayersReader::Impl::readFromModel(const std::string& model_p
const auto iml_map = unpackLayerAttr(params.input_model_layout, input_names, "input model layout");
cfgInputPreproc(ppp, model, ip_map, il_map, iml_map);

const auto reshape_map = unpackLayerAttr(params.reshape, input_names, "reshape");
cfgReshape(model, reshape_map);

const auto& output_names = extractLayerNames(model->outputs());
const auto op_map = unpackLayerAttr(params.output_precision, output_names, "output precision");
const auto ol_map = unpackLayerAttr(params.output_layout, output_names, "output layout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ static cv::gapi::GNetPackage getNetPackage(const std::string& tag, const OpenVIN
} else if (std::holds_alternative<AttrMap<std::string>>(params.output_model_layout)) {
network->cfgOutputModelLayout(std::get<AttrMap<std::string>>(params.output_model_layout));
}

if (std::holds_alternative<AttrMap<std::vector<size_t>>>(params.reshape)) {
network->cfgReshape(std::get<AttrMap<std::vector<size_t>>>(params.reshape));
} else if (std::holds_alternative<std::vector<size_t>>(params.reshape)) {
network->cfgReshape(std::get<std::vector<size_t>>(params.reshape));
}
}
return cv::gapi::networks(*network);
}
Expand Down

0 comments on commit e2fce1a

Please sign in to comment.