From 39d9a143805fb1d78bec8b6897539117245ea181 Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Fri, 12 Nov 2021 16:10:50 +0100 Subject: [PATCH] [ONNX] don't set friendly names after processing Identity node (#8432) unless the Identity node is connected to output Ticket: 69827 --- ngraph/frontend/onnx/frontend/src/core/graph.cpp | 16 ++++++++++++++++ ngraph/test/models/onnx/tensor_names.prototxt | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/ngraph/frontend/onnx/frontend/src/core/graph.cpp b/ngraph/frontend/onnx/frontend/src/core/graph.cpp index bf4cb53d32e613..51d1d3772b5f52 100644 --- a/ngraph/frontend/onnx/frontend/src/core/graph.cpp +++ b/ngraph/frontend/onnx/frontend/src/core/graph.cpp @@ -260,6 +260,22 @@ OutputVector Graph::make_ng_nodes(const Node& onnx_node) const { } void Graph::set_friendly_names(const Node& onnx_node, const OutputVector& ng_node_vector) const { + if (onnx_node.op_type() == "Identity") { + // we eliminate Identity op (since it's a no-op) and therefore + // we must preserve its input name, unless Identity is connected + // to a graph's output - in that case Identity's input gets + // a new name + const auto& graph_outputs = m_model->get_graph().output(); + const auto& name = onnx_node.output(0); + bool is_identity_on_output = std::find_if(graph_outputs.begin(), + graph_outputs.end(), + [&name](const ONNX_NAMESPACE::ValueInfoProto& output) -> bool { + return output.name() == name; + }) != graph_outputs.end(); + if (!is_identity_on_output) { + return; + } + } for (size_t i = 0; i < ng_node_vector.size(); ++i) { // Trailing optional outputs may not be specified in the ONNX model. // Other optional outputs should have name set to an empty string. diff --git a/ngraph/test/models/onnx/tensor_names.prototxt b/ngraph/test/models/onnx/tensor_names.prototxt index 784beb19916e04..6b5b521220e375 100644 --- a/ngraph/test/models/onnx/tensor_names.prototxt +++ b/ngraph/test/models/onnx/tensor_names.prototxt @@ -3,6 +3,12 @@ producer_name: "test_model" graph { node { input: "input" + output: "identity_on_input" + name: "identity_node_on_input" + op_type: "Identity" + } + node { + input: "identity_on_input" output: "relu_t" op_type: "Relu" name: "relu"