ONNX pooling - extended auto_pad attribute support (#10092)

This commit is contained in:
Tomasz Dołbniak 2022-02-04 10:23:31 +01:00 committed by GitHub
parent 7478915ef3
commit 797b2221be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,81 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "AveragePool"
attribute {
name: "kernel_shape"
ints: 3
ints: 3
type: INTS
}
attribute {
name: "pads"
ints: 1
ints: 1
ints: 1
ints: 1
type: INTS
}
attribute {
name: "auto_pad"
s: ""
type: STRING
}
attribute {
name: "count_include_pad"
i: 1
type: INT
}
}
name: "compute_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 13
}

View File

@ -0,0 +1,76 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "MaxPool"
attribute {
name: "kernel_shape"
ints: 3
ints: 3
type: INTS
}
attribute {
name: "pads"
ints: 1
ints: 1
ints: 1
ints: 1
type: INTS
}
attribute {
name: "auto_pad"
s: ""
type: STRING
}
}
name: "compute_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 13
}

View File

@ -324,6 +324,32 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_average_pool_2d_pads) {
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_average_pool_empty_auto_pad) {
const auto function =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/average_pool_empty_auto_pad.onnx"));
auto test_case = test::TestCase(function, s_device);
test_case.add_input<float>({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f});
test_case.add_expected_output<float>(
Shape{1, 1, 3, 3},
{1.3333333f, 2.3333333f, 1.7777777f, 3.0f, 5.0f, 3.6666666f, 2.6666666f, 4.3333333f, 3.1111111f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max_pool_empty_auto_pad) {
const auto model =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/max_pool_empty_auto_pad.onnx"));
for (const auto& op : model->get_ops()) {
if (const auto max_pool = std::dynamic_pointer_cast<op::v8::MaxPool>(op)) {
EXPECT_EQ(max_pool->get_auto_pad(), op::PadType::EXPLICIT);
return;
}
}
FAIL() << "MaxPool op not found in the imported model";
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max_pool_2d_pads) {
// Pooling with strides=2 and padding=1
auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/max_pool_2d_pads.onnx"));

View File

@ -82,6 +82,7 @@ ngraph::op::PadType get_auto_pad(const Node& node) {
{"SAME_UPPER", ngraph::op::PadType::SAME_UPPER},
{"SAME_LOWER", ngraph::op::PadType::SAME_LOWER},
{"NOTSET", ngraph::op::PadType::NOTSET},
{"", ngraph::op::PadType::NOTSET}, // empty string considered as undefined attribute
};
const std::string& pad_str{node.get_attribute_value<std::string>("auto_pad", "NOTSET")};