From 1cb6bdc33c64c321a17b62c25c04bc9878d35ba9 Mon Sep 17 00:00:00 2001 From: Patrick Foley Date: Mon, 18 Nov 2019 15:57:27 -0800 Subject: [PATCH] Added support for Pad-2 operator in OpenVINO-EP (#2405) --- .../openvino/openvino_execution_provider.cc | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index a5b539a49d..2afba1d3d4 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -177,6 +177,7 @@ bool IsOpSupported(std::string name) { "Transpose", "Identity", "MatMul", + "Pad", "Unsqueeze", "ImageScaler", "LeakyRelu", @@ -244,6 +245,17 @@ void CheckGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::stri if (it == initializers.end() && node_inputs[i]->Shape() != nullptr) { if (node_inputs[i]->Shape()->dim_size() == 0) { throw "Node_input is zero dimension"; + } else { + auto num_dims = node_inputs[i]->Shape()->dim_size(); + int v = 0; + //Batch size for NCHW can be 0 + if (num_dims > 3) { + v = 1; + } + for (int j = v; j < num_dims; j++) { + if (node_inputs[i]->Shape()->dim(j).dim_value() == 0) + throw "Node_input has zero dimension"; + } } } } @@ -255,6 +267,29 @@ void CheckGraphSupported(const onnxruntime::GraphViewer& graph_viewer, std::stri } } + //Pad doesn't support negative values. + //If all pads are 0, the node gets removed + if (node->OpType() == "Pad") { + auto attributes = node->GetAttributes(); + auto it = attributes.find("pads"); + if (it != attributes.end()) { + auto pads_ints = attributes["pads"].ints(); + auto min_val = *std::min_element(pads_ints.begin(), pads_ints.end()); + auto max_val = *std::max_element(pads_ints.begin(), pads_ints.end()); + if (min_val < 0) { + throw "Pad: Negative values are not supported"; + } + if (min_val == 0 && max_val == 0) { + auto iter = node->OutputNodesBegin(); + if (iter == node->OutputNodesEnd()) { + throw "Pad: Must extend tensor in one or more dimensions"; + } + } + } else { + throw "Pad-1 and Pad (opset 11) operators are not supported"; + } + } + //Conv cannot take more than 1 input if (node->OpType() == "Conv") { if (GetInputCount(node, initializers) > 1) {