Properly reading parameters with whitespaces from IR (#12650)
* Add overrided method to generating vector of strings * Trim the value from the the left and right * Add test to verify that output names are correctly read from IR * Use spaces instead of tabs * Add C++ tests for read model contains outputs with whitespaces * Fix test for add output * Remove python test
This commit is contained in:
parent
5b3cc5514a
commit
caf547b5eb
@ -113,4 +113,15 @@ void str_to_set_of_strings(const std::string& value, std::set<std::string>& res)
|
||||
}
|
||||
}
|
||||
|
||||
void str_to_container(const std::string& value, std::vector<std::string>& res) {
|
||||
std::stringstream ss(value);
|
||||
std::string field;
|
||||
while (getline(ss, field, ',')) {
|
||||
field = ov::util::trim(field);
|
||||
if (!field.empty()) {
|
||||
res.emplace_back(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ov
|
||||
|
@ -19,6 +19,8 @@ PartialShape str_to_partial_shape(const std::string& value);
|
||||
bool get_dimension_from_attribute(const pugi::xml_node& node, const std::string& name, Dimension& value);
|
||||
bool get_partial_shape_from_attribute(const pugi::xml_node& node, const std::string& name, PartialShape& value);
|
||||
|
||||
void str_to_container(const std::string& value, std::vector<std::string>& res);
|
||||
|
||||
template <class T>
|
||||
void str_to_container(const std::string& value, T& res) {
|
||||
std::stringstream ss(value);
|
||||
@ -32,6 +34,7 @@ void str_to_container(const std::string& value, T& res) {
|
||||
res.insert(res.end(), val);
|
||||
}
|
||||
}
|
||||
|
||||
// separated function for set<string> to keep whitespaces in values
|
||||
// because stringstream splits its values with whitespace delimiter
|
||||
void str_to_set_of_strings(const std::string& value, std::set<std::string>& res);
|
||||
|
@ -2,10 +2,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <ngraph/function.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "ngraph_reader_tests.hpp"
|
||||
#include "openvino/openvino.hpp"
|
||||
|
||||
TEST_F(NGraphReaderTests, ReadNetworkWithTensorNames) {
|
||||
std::string model = R"V0G0N(
|
||||
@ -88,3 +89,170 @@ TEST_F(NGraphReaderTests, ReadNetworkWithTensorNames) {
|
||||
}
|
||||
ASSERT_NO_THROW(network.getOVNameForTensor("relu,t"));
|
||||
}
|
||||
|
||||
TEST_F(NGraphReaderTests, ReadModelWithTensorNamesWithSpaces) {
|
||||
std::string model_str = R"V0G0N(
|
||||
<net name="graph" version="11">
|
||||
<layers>
|
||||
<layer id="1" name="input1" type="Parameter" version="opset1">
|
||||
<data shape="1,4,512" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32" names="input1">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="0" name="input2" type="Parameter" version="opset1">
|
||||
<data shape="1,4,512" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32" names="input2">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="2" name="output 0([1 4 512])" type="Add" version="opset1">
|
||||
<data auto_broadcast="numpy"/>
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
<port id="1" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</input>
|
||||
<output>
|
||||
<port id="2" precision="FP32" names="output 0([1 4 512])">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="3" name="output 0([1 4 512])/sink_port_0" type="Result" version="opset1">
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</input>
|
||||
</layer>
|
||||
</layers>
|
||||
<edges>
|
||||
<edge from-layer="0" from-port="0" to-layer="2" to-port="1"/>
|
||||
<edge from-layer="1" from-port="0" to-layer="2" to-port="0"/>
|
||||
<edge from-layer="2" from-port="2" to-layer="3" to-port="0"/>
|
||||
</edges>
|
||||
</net>
|
||||
)V0G0N";
|
||||
ov::Core core;
|
||||
auto model = core.read_model(model_str, ov::Tensor{});
|
||||
auto outputs = model->outputs();
|
||||
EXPECT_EQ(outputs.size(), 1);
|
||||
auto names = outputs.at(0).get_names();
|
||||
EXPECT_EQ(names.size(), 1);
|
||||
auto it = names.find("output 0([1 4 512])");
|
||||
EXPECT_NE(it, names.end());
|
||||
}
|
||||
|
||||
TEST_F(NGraphReaderTests, ReadModelWithTensorNamesAddOutput) {
|
||||
std::string model_str = R"V0G0N(
|
||||
<net name="graph" version="11">
|
||||
<layers>
|
||||
<layer id="1" name="input1" type="Parameter" version="opset1">
|
||||
<data shape="1,4,512" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32" names="input1">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="0" name="input2" type="Parameter" version="opset1">
|
||||
<data shape="1,4,512" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32" names="input2">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="2" name="Add 221" type="Add" version="opset1">
|
||||
<data auto_broadcast="numpy"/>
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
<port id="1" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</input>
|
||||
<output>
|
||||
<port id="2" precision="FP32" names="output add">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="3" name="output 0([1 4 512])" type="ReLU" version="opset1">
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</input>
|
||||
<output>
|
||||
<port id="1" precision="FP32" names="output 0([1 4 512])">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="4" name="output 0([1 4 512])/sink_port_0" type="Result" version="opset1">
|
||||
<rt_info>
|
||||
<attribute name="fused_names" version="0" value="output 0([1 4 512])/sink_port_0"/>
|
||||
</rt_info>
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1</dim>
|
||||
<dim>4</dim>
|
||||
<dim>512</dim>
|
||||
</port>
|
||||
</input>
|
||||
</layer>
|
||||
</layers>
|
||||
<edges>
|
||||
<edge from-layer="0" from-port="0" to-layer="2" to-port="1"/>
|
||||
<edge from-layer="1" from-port="0" to-layer="2" to-port="0"/>
|
||||
<edge from-layer="2" from-port="2" to-layer="3" to-port="0"/>
|
||||
<edge from-layer="3" from-port="1" to-layer="4" to-port="0"/>
|
||||
</edges>
|
||||
</net>)V0G0N";
|
||||
ov::Core core;
|
||||
std::string tensor_name = "output add";
|
||||
auto model = core.read_model(model_str, ov::Tensor{});
|
||||
model->add_output(tensor_name);
|
||||
auto outputs = model->outputs();
|
||||
EXPECT_EQ(outputs.size(), 2);
|
||||
auto names = outputs.at(1).get_names();
|
||||
EXPECT_EQ(names.size(), 1);
|
||||
auto it = names.find(tensor_name);
|
||||
EXPECT_NE(it, names.end());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user