Skip to content

Commit

Permalink
[ONNX] Added support and test cases for Shape-15 (#23492)
Browse files Browse the repository at this point in the history
related issue : #20194
  • Loading branch information
MeeCreeps authored Mar 29, 2024
1 parent 6d3aa37 commit dbf87c1
Show file tree
Hide file tree
Showing 14 changed files with 584 additions and 11 deletions.
31 changes: 31 additions & 0 deletions src/frontends/onnx/frontend/src/op/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@

#include "op/shape.hpp"

#include <cstdint>

#include "core/null_node.hpp"
#include "openvino/core/node_vector.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/slice.hpp"

using namespace ov::op;

namespace ov {
namespace frontend {
namespace onnx {
namespace op {

namespace set_15 {

ov::OutputVector shape(const ov::frontend::onnx::Node& node) {
using ov::op::util::is_null;

const auto data = node.get_ov_inputs().at(0);
const auto input_shape = std::make_shared<v3::ShapeOf>(data);

const auto start_val = node.get_attribute_value<int64_t>("start", 0);
const auto end_val = node.get_attribute_value<int64_t>("end", std::numeric_limits<int64_t>::max());

if (start_val == 0 && end_val == INT64_MAX) {
return {input_shape};
}

const auto start = v0::Constant::create(element::i64, ov::Shape{1}, {start_val});
const auto end = v0::Constant::create(element::i64, ov::Shape{1}, {end_val});
const auto default_step = v0::Constant::create(element::i64, {1}, {1});

return {std::make_shared<v8::Slice>(input_shape, start, end, default_step)};
}

} // namespace set_15

namespace set_1 {

ov::OutputVector shape(const ov::frontend::onnx::Node& node) {
Expand Down
6 changes: 6 additions & 0 deletions src/frontends/onnx/frontend/src/op/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ namespace ov {
namespace frontend {
namespace onnx {
namespace op {
namespace set_15 {

ov::OutputVector shape(const ov::frontend::onnx::Node& node);

} // namespace set_15

namespace set_1 {

ov::OutputVector shape(const ov::frontend::onnx::Node& node);
Expand Down
1 change: 1 addition & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("ScatterND", 1, scatter_nd);
REGISTER_OPERATOR("Selu", 1, selu);
REGISTER_OPERATOR("Shape", 1, shape);
REGISTER_OPERATOR("Shape", 15, shape)
REGISTER_OPERATOR("Shrink", 1, shrink);
REGISTER_OPERATOR("Sigmoid", 1, sigmoid);
REGISTER_OPERATOR("Sign", 1, sign);
Expand Down
1 change: 0 additions & 1 deletion src/frontends/onnx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):

skip_rng_tests = pytest.mark.skip(reason="Tests use random number generator with no seed.")
xfail_issue_63137 = xfail_test(reason="Unsupported operations: OptionalHasElement, OptionalGetElement")
xfail_issue_63138 = xfail_test(reason="Missing ONNX Shape-15 support")
xfail_issue_68212 = xfail_test(reason="Unsupported reading model with bytes streams")

xfail_issue_78843 = xfail_test(reason="Missing reference output files for ssd mobilenet models")
Expand Down
50 changes: 50 additions & 0 deletions src/frontends/onnx/tests/models/shape_opset15_end_1.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "end"
type: INT
i: 1
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "end"
type: INT
i: -1
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "end"
type: INT
i: -2
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
50 changes: 50 additions & 0 deletions src/frontends/onnx/tests/models/shape_opset15_start_1.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "start"
type: INT
i: 1
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "end"
type: INT
i: 2
}
attribute {
name: "start"
type: INT
i: 1
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
name: "test_shape15"
node {
input: "tensor"
output: "shape_output"
op_type: "Shape"
attribute {
name: "end"
type: INT
i: -1
}
attribute {
name: "start"
type: INT
i: 1
}
}
input {
name: "tensor"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "shape_output"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 15
}
Loading

0 comments on commit dbf87c1

Please sign in to comment.