Commit f6354fc2 authored by Tomasz Dołbniak's avatar Tomasz Dołbniak Committed by Scott Cyphers

[ONNX] ReverseSequence attributes validation [r0.26] (#3635)

* Validate ReverseSequence attributes according to the ONNX spec

* UT error message adjustment
parent d95745b9
......@@ -42,6 +42,18 @@ namespace ngraph
const auto batch_axis = node.get_attribute_value<int64_t>("batch_axis", 1);
const auto time_axis = node.get_attribute_value<int64_t>("time_axis", 0);
NGRAPH_CHECK(batch_axis == 0 || batch_axis == 1,
"Allowed values of the 'batch_axis' attribute for ReverseSequence "
"operator are 0 and 1");
NGRAPH_CHECK(time_axis == 0 || time_axis == 1,
"Allowed values of the 'time_axis' attribute for ReverseSequence "
"operator are 0 and 1");
NGRAPH_CHECK(batch_axis != time_axis,
"'batch_axis' and 'time_axis' attributes of the ReverseSequence "
"operator can't point to the same dimension");
return {std::make_shared<ngraph::op::ReverseSequence>(
data, sequence_lengths_i32, batch_axis, time_axis)};
}
......
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
input: "sequence_lengths"
output: "y"
op_type: "ReverseSequence"
attribute {
name: "batch_axis"
i: 2
type: INT
}
attribute {
name: "time_axis"
i: 0
type: INT
}
}
name: "reverse_sequence_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "sequence_lengths"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 10
}
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
input: "sequence_lengths"
output: "y"
op_type: "ReverseSequence"
attribute {
name: "batch_axis"
i: 0
type: INT
}
attribute {
name: "time_axis"
i: 2
type: INT
}
}
name: "reverse_sequence_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "sequence_lengths"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 10
}
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
input: "sequence_lengths"
output: "y"
op_type: "ReverseSequence"
attribute {
name: "batch_axis"
i: 1
type: INT
}
attribute {
name: "time_axis"
i: 1
type: INT
}
}
name: "reverse_sequence_graph"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "sequence_lengths"
type {
tensor_type {
elem_type: 6
shape {
dim {
dim_value: 4
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 4
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
}
opset_import {
version: 10
}
......@@ -1634,3 +1634,29 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_reverse_sequence_1_batch_0)
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_reverse_sequence_incorrect_batch_axis)
{
EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_batch_axis.prototxt")),
ngraph_error)
<< "ReverseSequence batch_axis attribute can only equal 0 or 1. Value of '2' is not "
"accepted.";
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_reverse_sequence_incorrect_time_axis)
{
EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_time_axis.prototxt")),
ngraph_error)
<< "ReverseSequence time_axis attribute can only equal 0 or 1. Value of '2' is not "
"accepted.";
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, model_reverse_sequence_time_and_batch_axis_equal)
{
EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
SERIALIZED_ZOO, "onnx/reverse_sequence_time_and_batch_axis_equal.prototxt")),
ngraph_error)
<< "ReverseSequence 'time_axis' and 'batch_axis' can't be equal.";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment