Skip to content

Commit

Permalink
[ONNX] don't set friendly names after processing Identity node (openv…
Browse files Browse the repository at this point in the history
…inotoolkit#8432)

unless the Identity node is connected to output

Ticket: 69827
  • Loading branch information
mateusztabaka authored and openvino-dev-samples committed Nov 24, 2021
1 parent c1ee5d2 commit 39d9a14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ngraph/frontend/onnx/frontend/src/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions ngraph/test/models/onnx/tensor_names.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 39d9a14

Please sign in to comment.