Fix preserving names of output layers after TopK NGraph transformation (#928)
* Fix preserving names of output layers after TopK NGraph transformation (#843) * Fix preserving names of output layers after TopK NGraph transformation It helps to infer semantic-segmentation-adas-0001 model. See CVS-31977. Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Fix a test for TopK Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Fix TopK NGraph transformation and its test Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com> * Disable smoke_LoadNetworkAccuracy due to sporadic failure Signed-off-by: Roman Kazantsev <roman.kazantsev@intel.com>
This commit is contained in:
@@ -42,22 +42,37 @@ void ngraph::pass::ConvertTopKToTopKIE::convert_topk_to_topk_ie() {
|
||||
topk->get_sort_type());
|
||||
new_ops.push_back(topk_ie);
|
||||
|
||||
Output<Node> element_output;
|
||||
Output<Node> index_output;
|
||||
// insert Convert if index element type not equal to i32
|
||||
if (topk->get_index_element_type() == element::i32) {
|
||||
// insert Convert if index element type not equal to i32 and output #1 of TopK has consumers
|
||||
if (topk->get_index_element_type() == element::i32 || topk->get_output_target_inputs(1).size() == 0) {
|
||||
element_output = topk_ie->output(0);
|
||||
index_output = topk_ie->output(1);
|
||||
} else {
|
||||
topk_ie->set_friendly_name(topk->get_friendly_name());
|
||||
} else if (topk->get_output_target_inputs(0).size() == 0) {
|
||||
index_output = std::make_shared<opset1::Convert>(topk_ie->output(1), topk->get_index_element_type());
|
||||
new_ops.push_back(index_output.get_node_shared_ptr());
|
||||
|
||||
// workaround for naming output #1 of TopK
|
||||
index_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1");
|
||||
} else {
|
||||
// create fake convert for 0 output, it is a workaround in purpose of correct output names preserving
|
||||
element_output = std::make_shared<opset1::Convert>(topk_ie->output(0), topk->get_output_element_type(0));
|
||||
index_output = std::make_shared<opset1::Convert>(topk_ie->output(1), topk->get_index_element_type());
|
||||
new_ops.push_back(element_output.get_node_shared_ptr());
|
||||
new_ops.push_back(index_output.get_node_shared_ptr());
|
||||
|
||||
// workaround for naming two outputs of TopK
|
||||
element_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".0");
|
||||
index_output.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1");
|
||||
}
|
||||
|
||||
topk_ie->set_friendly_name(topk->get_friendly_name());
|
||||
ngraph::copy_runtime_info(topk, new_ops);
|
||||
topk->output(0).replace(topk_ie->output(0));
|
||||
topk->output(0).replace(element_output);
|
||||
topk->output(1).replace(index_output);
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(topk, "ConvertTopKToTopKIE");
|
||||
this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,40 @@ void ngraph::pass::ConvertTopK3::convert_topk3() {
|
||||
if (!topk) {
|
||||
return false;
|
||||
}
|
||||
Output<Node> last;
|
||||
Output<Node> last0;
|
||||
Output<Node> last1;
|
||||
ngraph::NodeVector new_ops;
|
||||
|
||||
auto new_topk = std::make_shared<ngraph::opset2::TopK>(topk->input_value(0), topk->input_value(1),
|
||||
topk->get_axis(), topk->get_mode(), topk->get_sort_type(), element::i32);
|
||||
new_ops.push_back(new_topk);
|
||||
// if the output is the i32 then it matches behavior of the v1::TopK otherwise need to insert Convert
|
||||
if (topk->get_index_element_type() == element::i32) {
|
||||
last = new_topk->output(1);
|
||||
// if the output is the i32 or output #1 has no consumers
|
||||
// then it matches behavior of the v1::TopK otherwise need to insert Convert
|
||||
if (topk->get_index_element_type() == element::i32 || topk->get_output_target_inputs(1).size() == 0) {
|
||||
last0 = new_topk->output(0);
|
||||
last1 = new_topk->output(1);
|
||||
new_topk->set_friendly_name(topk->get_friendly_name());
|
||||
} else if (topk->get_output_target_inputs(0).size() == 0) {
|
||||
last1 = std::make_shared<ngraph::opset2::Convert>(new_topk->output(1), topk->get_index_element_type());
|
||||
new_ops.push_back(last1.get_node_shared_ptr());
|
||||
|
||||
// workaround for naming two outputs of TopK
|
||||
last1.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1");
|
||||
} else {
|
||||
last = std::make_shared<ngraph::opset2::Convert>(new_topk->output(1), topk->get_index_element_type());
|
||||
new_ops.push_back(last.get_node_shared_ptr());
|
||||
// create fake convert for 0 output, it is a workaround in purpose of correct output names preserving
|
||||
last0 = std::make_shared<ngraph::opset2::Convert>(new_topk->output(0), topk->get_output_element_type(0));
|
||||
last1 = std::make_shared<ngraph::opset2::Convert>(new_topk->output(1), topk->get_index_element_type());
|
||||
new_ops.push_back(last0.get_node_shared_ptr());
|
||||
new_ops.push_back(last1.get_node_shared_ptr());
|
||||
|
||||
// workaround for naming two outputs of TopK
|
||||
last0.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".0");
|
||||
last1.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1");
|
||||
}
|
||||
|
||||
new_topk->set_friendly_name(topk->get_friendly_name());
|
||||
ngraph::copy_runtime_info(topk, new_ops);
|
||||
topk->output(0).replace(new_topk->output(0));
|
||||
topk->output(1).replace(last);
|
||||
topk->output(0).replace(last0);
|
||||
topk->output(1).replace(last1);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@@ -157,5 +157,6 @@ TEST(TransformationTests, ConvertTopK3I64Output1) {
|
||||
ASSERT_TRUE(res.first) << res.second;
|
||||
|
||||
auto result_node_of_converted_f = f->get_output_op(0);
|
||||
auto topk_node = result_node_of_converted_f->input(0).get_source_output().get_node_shared_ptr();
|
||||
auto convert_node = result_node_of_converted_f->input(0).get_source_output().get_node_shared_ptr();
|
||||
ASSERT_TRUE(convert_node->get_friendly_name() == "topk.1") << "Transformation ConvertTopK3 should keep output names.\n";
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetwork) {
|
||||
}
|
||||
|
||||
// tested function: LoadNetwork accuracy
|
||||
TEST_P(CoreThreadingTestsWithIterations, smoke_LoadNetworkAccuracy) {
|
||||
TEST_P(CoreThreadingTestsWithIterations, DISABLED_smoke_LoadNetworkAccuracy) {
|
||||
InferenceEngine::Core ie;
|
||||
std::atomic<unsigned int> counter{0u};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user