1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
29 #ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
30 #define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
32 #ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
33 #define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
37 #include "gtest/gtest.h"
38 #include "onnx_import/core/null_node.hpp"
39 #include "onnx_import/onnx.hpp"
40 #include "onnx_import/onnx_utils.hpp"
41 #include "onnx_import/default_opset.hpp"
42 #include "ngraph/ngraph.hpp"
43 #include "ngraph/pass/manager.hpp"
44 #include "ngraph/pass/constant_folding.hpp"
45 #include "util/all_close.hpp"
46 #include "util/all_close_f.hpp"
47 #include "util/ndarray.hpp"
48 #include "util/test_case.hpp"
49 #include "util/test_control.hpp"
50 #include "util/engine/test_engines.hpp"
51 #include "util/test_tools.hpp"
52 #include "util/type_prop.hpp"
54 NGRAPH_SUPPRESS_DEPRECATED_START
56 using namespace ngraph;
58 static std::string s_manifest = "${MANIFEST}";
60 using Inputs = std::vector<std::vector<float>>;
61 using Outputs = std::vector<std::vector<float>>;
63 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
65 // ############################################################################ CORE TESTS
66 NGRAPH_TEST(${BACKEND_NAME}, onnx_test_test_case)
68 auto function = onnx_import::import_onnx_model(
69 file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
71 auto test_case = test::TestCase<TestEngine>(function);
72 test_case.add_input<float>({1});
73 test_case.add_input<float>({2});
74 test_case.add_input<float>({3});
75 test_case.add_expected_output<float>(Shape{1}, {6});
79 NGRAPH_TEST(${BACKEND_NAME}, onnx_test_test_case_mutliple_inputs)
81 auto function = onnx_import::import_onnx_model(
82 file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
84 auto test_case = test::TestCase<TestEngine>(function);
85 test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
86 test_case.add_expected_output(Shape{1}, std::vector<float>{6});
90 NGRAPH_TEST(${BACKEND_NAME}, onnx_output_names_check)
92 auto function = onnx_import::import_onnx_model(
93 file_util::path_join(SERIALIZED_ZOO, "onnx/split_equal_parts_default.prototxt"));
95 std::size_t size = function->get_output_size();
96 for (std::size_t i{0}; i < size; ++i)
98 std::shared_ptr<Node> node = function->get_output_op(i);
99 EXPECT_EQ(node->get_friendly_name(), "output_" + std::to_string(i + 1));
103 NGRAPH_TEST(${BACKEND_NAME}, onnx_node_names_check)
105 auto function = onnx_import::import_onnx_model(
106 file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
108 // Filter out Add nodes from the function graph
109 std::vector<std::shared_ptr<Node>> additions;
110 auto ordered_ops = function->get_ordered_ops();
114 std::back_inserter(additions),
115 [](std::shared_ptr<Node> op) { return std::string(op->get_type_name()) == "Add"; });
117 EXPECT_EQ(additions.size(), 2);
118 EXPECT_EQ(additions.at(0)->get_friendly_name(), "X");
119 EXPECT_EQ(additions.at(1)->get_friendly_name(), "Y");
122 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_abc)
124 auto function = onnx_import::import_onnx_model(
125 file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.prototxt"));
127 auto test_case = test::TestCase<TestEngine>(function);
128 test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
129 test_case.add_expected_output(Shape{1}, std::vector<float>{6});
133 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_binary_add_abc)
136 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc.onnx"));
138 auto test_case = test::TestCase<TestEngine>(function);
139 test_case.add_multiple_inputs(Inputs{{1}, {2}, {3}});
140 test_case.add_expected_output(Shape{1}, std::vector<float>{6});
144 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_const_op)
146 auto function = onnx_import::import_onnx_model(
147 file_util::path_join(SERIALIZED_ZOO, "onnx/bool_const_op.prototxt"));
149 auto test_case = test::TestCase<TestEngine>(function);
150 test_case.add_expected_output(std::vector<bool>{1, 0, 0, 1});
154 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_init_and)
156 auto function = onnx_import::import_onnx_model(
157 file_util::path_join(SERIALIZED_ZOO, "onnx/bool_init_and.prototxt"));
159 auto test_case = test::TestCase<TestEngine>(function);
160 test_case.add_expected_output(std::vector<bool>{1});
164 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_input_or)
166 auto function = onnx_import::import_onnx_model(
167 file_util::path_join(SERIALIZED_ZOO, "onnx/bool_input_or.prototxt"));
169 auto test_case = test::TestCase<TestEngine>(function);
170 test_case.add_input(std::vector<bool>{true, false, true, false});
171 test_case.add_input(std::vector<bool>{false, false, true, true});
172 test_case.add_expected_output(std::vector<bool>{1, 0, 1, 1});
176 NGRAPH_TEST(${BACKEND_NAME}, onnx_bool_init_raw)
178 auto function = onnx_import::import_onnx_model(
179 file_util::path_join(SERIALIZED_ZOO, "onnx/bool_init_raw.prototxt"));
181 auto test_case = test::TestCase<TestEngine>(function);
182 test_case.add_expected_output(std::vector<bool>{true, false, true});
186 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_abc_initializers)
188 auto function = onnx_import::import_onnx_model(
189 file_util::path_join(SERIALIZED_ZOO, "onnx/add_abc_initializers.prototxt"));
191 auto test_case = test::TestCase<TestEngine>(function);
192 test_case.add_input<float>({1, 2, 3, 4});
193 test_case.add_expected_output<float>({3, 6, 9, 12});
197 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_override_op)
199 onnx_import::register_operator(
200 "FalseAdd", 1, "", [](const onnx_import::Node& node) -> OutputVector {
201 OutputVector ng_inputs{node.get_ng_inputs()};
202 return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
205 onnx_import::register_operator(
206 "FalseAdd", 1, "", [](const onnx_import::Node& node) -> OutputVector {
207 OutputVector ng_inputs{node.get_ng_inputs()};
208 return {std::make_shared<ngraph::op::Subtract>(ng_inputs.at(0), ng_inputs.at(1))};
211 auto function = onnx_import::import_onnx_model(
212 file_util::path_join(SERIALIZED_ZOO, "onnx/override_op.prototxt"));
215 inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
216 inputs.emplace_back(std::vector<float>{3.f, 2.f, 1.f, 0.f});
218 auto test_case = test::TestCase<TestEngine>(function);
219 test_case.add_multiple_inputs(inputs);
220 test_case.add_expected_output<float>({-3.f, -1.f, 1.f, 3.f});
224 NGRAPH_TEST(${BACKEND_NAME}, onnx_import_non_existing_file)
228 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/i.dont.exist"));
230 catch (const std::runtime_error& exc)
232 // asserts that an exception was thrown and that the error message contains the file name
233 std::string msg{exc.what()};
234 EXPECT_TRUE(msg.find("i.dont.exist") != std::string::npos);
238 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unsupported_op)
242 onnx_import::import_onnx_model(
243 file_util::path_join(SERIALIZED_ZOO, "onnx/unsupported_op.prototxt"));
244 FAIL() << "Expected ngraph::ngraph_error";
246 catch (ngraph::ngraph_error const& err)
248 std::string what{err.what()};
249 EXPECT_NE(what.find("nGraph does not support"), std::string::npos);
250 EXPECT_NE(what.find("FakeOpName"), std::string::npos);
251 EXPECT_NE(what.find("AnotherFakeOpName"), std::string::npos);
255 FAIL() << "Expected ngraph::ngraph_error";
259 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_custom_op)
261 onnx_import::register_operator(
262 "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
263 OutputVector ng_inputs{node.get_ng_inputs()};
264 return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
267 auto function = onnx_import::import_onnx_model(
268 file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator.prototxt"));
270 auto test_case = test::TestCase<TestEngine>(function);
271 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f});
272 test_case.add_expected_output<float>({3.f, 6.f, 9.f, 12.f});
276 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_custom_op_default_domain)
278 onnx_import::register_operator(
279 "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
280 OutputVector ng_inputs{node.get_ng_inputs()};
281 return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
284 auto function = onnx_import::import_onnx_model(
285 file_util::path_join(SERIALIZED_ZOO, "onnx/custom_operator_default_domain.prototxt"));
287 auto test_case = test::TestCase<TestEngine>(function);
288 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f});
289 test_case.add_expected_output<float>({3.f, 6.f, 9.f, 12.f});
293 NGRAPH_TEST(${BACKEND_NAME}, onnx_is_op_supported)
296 EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 1, "ai.onnx"));
298 EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 100, "ai.onnx"));
300 // Different opset versions
301 EXPECT_TRUE(onnx_import::is_operator_supported("Add", 1, "ai.onnx"));
302 EXPECT_TRUE(onnx_import::is_operator_supported("Add", 7, "ai.onnx"));
304 // Default domain name
305 EXPECT_TRUE(onnx_import::is_operator_supported("Sum", 1));
307 // Unregistered operator
308 EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 1));
309 EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 1, "ai.onnx"));
310 EXPECT_FALSE(onnx_import::is_operator_supported("DummyOp", 10, "ai.onnx"));
312 // Operator with bad domain name
313 EXPECT_FALSE(onnx_import::is_operator_supported("Sum", 1, "bad.domain"));
315 // Registered custom operator
316 onnx_import::register_operator(
317 "AddQ", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
318 OutputVector ng_inputs{node.get_ng_inputs()};
319 return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
321 EXPECT_TRUE(onnx_import::is_operator_supported("AddQ", 1, "com.intel.ai"));
324 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_missing_op_domain)
326 onnx_import::register_operator(
327 "CustomAdd", 1, "custom.op", [](const onnx_import::Node& node) -> OutputVector {
328 OutputVector ng_inputs{node.get_ng_inputs()};
329 return {std::make_shared<ngraph::op::Add>(ng_inputs.at(0), ng_inputs.at(1))};
332 EXPECT_TRUE(onnx_import::is_operator_supported("CustomAdd", 1, "custom.op"));
334 auto function = onnx_import::import_onnx_model(
335 file_util::path_join(SERIALIZED_ZOO, "onnx/missing_op_domain.prototxt"));
338 inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
339 inputs.emplace_back(std::vector<float>{0.f, 1.f, 2.f, 3.f});
341 auto test_case = test::TestCase<TestEngine>(function);
342 test_case.add_multiple_inputs(inputs);
343 test_case.add_expected_output<float>({0.f, 2.f, 4.f, 6.f});
347 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_unknown_domain)
349 // the importer should not throw when it encounters an unknown domain in the model
350 EXPECT_NO_THROW(onnx_import::import_onnx_model(
351 file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain.prototxt")));
354 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_op_in_unknown_domain)
358 onnx_import::import_onnx_model(
359 file_util::path_join(SERIALIZED_ZOO, "onnx/unknown_domain_add.prototxt"));
361 FAIL() << "The onnx_importer did not throw for unknown domain and op";
363 catch (const ngraph::ngraph_error& e)
365 const std::string msg = e.what();
367 EXPECT_NE(msg.find("unknown.domain.Add"), std::string::npos)
368 << "The error message should contain domain and op name: unknown.domain.Add";
372 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_missing_input)
374 onnx_import::register_operator(
375 "TestMissingInOut", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
376 OutputVector ng_inputs{node.get_ng_inputs()};
377 Output<ngraph::Node> A = ng_inputs.at(0);
378 Output<ngraph::Node> B = ng_inputs.at(1);
379 Output<ngraph::Node> C = ng_inputs.at(2);
382 if (!ngraph::op::is_null(B))
391 onnx_import::register_operator(
392 "TestMissingIn", 1, "com.intel.ai", [](const onnx_import::Node& node) -> OutputVector {
393 OutputVector ng_inputs{node.get_ng_inputs()};
394 std::shared_ptr<ngraph::Node> result = std::make_shared<ngraph::op::Constant>(
395 element::f32, ngraph::Shape{2, 2}, std::vector<float>{1, 1, 1, 1});
397 for (const auto& ng_input : ng_inputs)
399 if (!ngraph::op::is_null(ng_input))
401 result = ng_input * result;
408 auto function = onnx_import::import_onnx_model(
409 file_util::path_join(SERIALIZED_ZOO, "onnx/missing_input.prototxt"));
411 Inputs inputs{{1, 2, 3, 4}, {5, 6, 7, 8}};
413 auto test_case = test::TestCase<TestEngine>(function);
414 test_case.add_multiple_inputs(inputs);
415 test_case.add_expected_output<float>({50, 144, 294, 512});
419 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_initializer_wo_input)
421 // This test checks a model which has an initializer, but no input with the same name
422 auto function = onnx_import::import_onnx_model(
423 file_util::path_join(SERIALIZED_ZOO, "onnx/initializer_wo_input.prototxt"));
425 auto test_case = test::TestCase<TestEngine>(function);
426 test_case.add_input<float>({0, 1, 2, 3, 4, 5});
427 test_case.add_expected_output<float>({0, 2, 6, 12, 20, 30});
431 // ############################################################################ OPERATOR TESTS
432 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_addmul_abc)
434 auto function = onnx_import::import_onnx_model(
435 file_util::path_join(SERIALIZED_ZOO, "onnx/addmul_abc.prototxt"));
437 auto test_case = test::TestCase<TestEngine>(function);
438 test_case.add_input<float>({9, 10, 11, 12});
439 test_case.add_input<float>({5, 6, 7, 8});
440 test_case.add_input<float>({1, 2, 3, 4});
441 test_case.add_expected_output<float>(Shape{1, 2, 2}, {46, 62, 80, 100});
445 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_no_keepdims)
447 auto function = onnx_import::import_onnx_model(
448 file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_no_keepdims.prototxt"));
450 auto test_case = test::TestCase<TestEngine>(function);
451 test_case.add_input<float>({2, 1, 3, 10});
452 test_case.add_expected_output<float>(Shape{2}, {1, 0});
456 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_batch_norm_default)
458 // Batch Normalization with default parameters
459 auto function = onnx_import::import_onnx_model(
460 file_util::path_join(SERIALIZED_ZOO, "onnx/batchnorm_default.prototxt"));
462 auto test_case = test::TestCase<TestEngine>(function);
463 test_case.add_input<float>({-1.f, 0.f, 1.f, 2.f, 3.f, 4.f}); // data {1, 2, 1, 3}
464 test_case.add_input<float>({1.f, 1.5f}); // scale
465 test_case.add_input<float>({0.f, 1.f}); // bias
466 test_case.add_input<float>({0.f, 3.f}); // mean
467 test_case.add_input<float>({1.f, 1.5f}); // var
468 test_case.add_expected_output<float>(
469 Shape{1, 2, 1, 3}, {-0.999995f, 0.f, 0.999995f, -0.22474074f, 1.f, 2.2247407f});
473 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_relu)
477 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/relu.prototxt"));
479 auto test_case = test::TestCase<TestEngine>(function);
480 test_case.add_input<float>({-1, -2, 0, 1, 2, 3});
481 test_case.add_expected_output<float>({0, 0, 0, 1, 2, 3});
485 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_opset1)
487 // Simple Sum test for opset1.
488 auto function = onnx_import::import_onnx_model(
489 file_util::path_join(SERIALIZED_ZOO, "onnx/sum_opset1.prototxt"));
491 auto test_case = test::TestCase<TestEngine>(function);
492 test_case.add_input<float>({3.f, 0.f, 2.f});
493 test_case.add_input<float>({1.f, 3.f, 4.f});
494 test_case.add_input<float>({2.f, 6.f, 6.f});
495 test_case.add_expected_output<float>(Shape{3}, {6.f, 9.f, 12.f});
499 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum)
501 // Simple Sum test for opset8.
503 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sum.prototxt"));
505 auto test_case = test::TestCase<TestEngine>(function);
506 test_case.add_input<float>({3.f});
507 test_case.add_input<float>({1.f, 3.f, 4.f});
508 test_case.add_input<float>({2.f, 6.f, 6.f});
509 test_case.add_expected_output<float>(Shape{3}, {6.f, 12.f, 13.f});
513 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_one_input)
515 auto function = onnx_import::import_onnx_model(
516 file_util::path_join(SERIALIZED_ZOO, "onnx/sum_one_input.prototxt"));
518 // input data shape (3, )
519 auto test_case = test::TestCase<TestEngine>(function);
520 test_case.add_input<float>({3.f, 0.f, 2.f});
521 test_case.add_expected_output<float>({3.f, 0.f, 2.f});
525 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_1d)
527 auto function = onnx_import::import_onnx_model(
528 file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_1d.prototxt"));
530 auto test_case = test::TestCase<TestEngine>(function);
531 test_case.add_input<float>({1.f, 2.f, 3.f});
532 test_case.add_expected_output<float>(Shape{3}, {1.f, 3.f, 6.f});
536 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_2d_axis_input)
538 auto function = onnx_import::import_onnx_model(
539 file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_2d_axis_input.prototxt"));
541 auto test_case = test::TestCase<TestEngine>(function);
542 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
543 test_case.add_expected_output<float>(Shape{2, 3}, {1.f, 3.f, 6.f, 4.f, 9.f, 15.f});
547 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_2d_dynamic_axis_input)
549 auto function = onnx_import::import_onnx_model(
550 file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_2d_dynamic_axis_input.prototxt"));
552 auto test_case = test::TestCase<TestEngine>(function);
553 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
554 test_case.add_input<std::int32_t>({1});
555 test_case.add_expected_output<float>(Shape{2, 3}, {1.f, 3.f, 6.f, 4.f, 9.f, 15.f});
559 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cum_sum_3d_exclusive_reverse)
561 auto function = onnx_import::import_onnx_model(
562 file_util::path_join(SERIALIZED_ZOO, "onnx/cum_sum_3d_exclusive_reverse.prototxt"));
564 auto test_case = test::TestCase<TestEngine>(function);
565 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f,
566 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f,
567 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f});
568 test_case.add_expected_output<float>(
569 Shape{2, 3, 4}, {13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f,
570 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f});
574 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_min_two_inputs_opset1)
576 auto function = onnx_import::import_onnx_model(
577 file_util::path_join(SERIALIZED_ZOO, "onnx/min_two_inputs_opset1.prototxt"));
579 // input data shape (3, )
580 auto test_case = test::TestCase<TestEngine>(function);
581 test_case.add_input<float>({1.f, 2.f, 1.f});
582 test_case.add_input<float>({1.f, 4.f, 4.f});
583 test_case.add_expected_output<float>({1.f, 2.f, 1.f});
587 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_min_two_inputs)
589 auto function = onnx_import::import_onnx_model(
590 file_util::path_join(SERIALIZED_ZOO, "onnx/min_two_inputs.prototxt"));
592 // input data shape (3, )
593 auto test_case = test::TestCase<TestEngine>(function);
594 test_case.add_input<float>({2.f});
595 test_case.add_input<float>({1.f, 4.f, 4.f});
596 test_case.add_expected_output<float>({1.f, 2.f, 2.f});
600 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max_opset1)
602 auto function = onnx_import::import_onnx_model(
603 file_util::path_join(SERIALIZED_ZOO, "onnx/max_opset1.prototxt"));
605 // input data shape (3, )
606 auto test_case = test::TestCase<TestEngine>(function);
607 test_case.add_input<float>({3.f, 2.f, 1.f});
608 test_case.add_input<float>({1.f, 4.f, 4.f});
609 test_case.add_input<float>({2.f, 5.f, 3.f});
611 test_case.add_expected_output<float>({3.f, 5.f, 4.f});
615 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max)
618 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/max.prototxt"));
620 // input data shape (3, )
621 auto test_case = test::TestCase<TestEngine>(function);
622 test_case.add_input<float>({1.f, 4.f, 4.f});
623 test_case.add_input<float>({3.f});
624 test_case.add_input<float>({2.f, 5.f, 3.f});
626 test_case.add_expected_output<float>({3.f, 5.f, 4.f});
630 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mean_opset1)
632 auto function = onnx_import::import_onnx_model(
633 file_util::path_join(SERIALIZED_ZOO, "onnx/mean_opset1.prototxt"));
635 // input data shape (3, )
636 auto test_case = test::TestCase<TestEngine>(function);
637 test_case.add_input<float>({3.f, 0.f, 2.f});
638 test_case.add_input<float>({1.f, 3.f, 4.f});
639 test_case.add_input<float>({2.f, 6.f, 6.f});
641 test_case.add_expected_output<float>({2.f, 3.f, 4.f});
645 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mean)
648 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/mean.prototxt"));
650 // input data shape (3, )
651 auto test_case = test::TestCase<TestEngine>(function);
652 test_case.add_input<float>({3.f});
653 test_case.add_input<float>({1.f, 2.f, 5.f});
654 test_case.add_input<float>({2.f, 7.f, 7.f});
656 test_case.add_expected_output<float>({2.f, 4.f, 5.f});
660 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gemm_abc)
662 auto function = onnx_import::import_onnx_model(
663 file_util::path_join(SERIALIZED_ZOO, "onnx/gemm_abc.prototxt"));
666 inputs.emplace_back(test::NDArray<float, 2>(
667 {{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}})
670 inputs.emplace_back(test::NDArray<float, 2>({{19, 20, 21, 22},
679 test::NDArray<float, 2>({{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}).get_vector());
681 auto expected_output =
682 test::NDArray<float, 2>(
683 {{340, 350.5, 361, 371.5}, {862, 890.5, 919, 947.5}, {1384, 1430.5, 1477, 1523.5}})
686 auto test_case = test::TestCase<TestEngine>(function);
687 test_case.add_multiple_inputs(inputs);
688 test_case.add_expected_output(expected_output);
692 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_matmul)
694 auto function = onnx_import::import_onnx_model(
695 file_util::path_join(SERIALIZED_ZOO, "onnx/matmul.prototxt"));
697 std::vector<std::vector<float>> inputs;
700 test::NDArray<float, 2>({{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}).get_vector());
703 test::NDArray<float, 2>({{13, 14, 15}, {16, 17, 18}, {19, 20, 21}, {22, 23, 24}})
706 auto expected_output =
707 test::NDArray<float, 2>({{190, 200, 210}, {470, 496, 522}, {750, 792, 834}}).get_vector();
709 auto test_case = test::TestCase<TestEngine>(function);
710 test_case.add_multiple_inputs(inputs);
711 test_case.add_expected_output(expected_output);
715 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_0D)
717 auto function = onnx_import::import_onnx_model(
718 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_0D.prototxt"));
720 auto test_case = test::TestCase<TestEngine>(function);
721 test_case.add_input<float>({3.141592});
722 test_case.add_expected_output<float>({1.0});
726 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_1D)
728 auto function = onnx_import::import_onnx_model(
729 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_1D.prototxt"));
731 auto test_case = test::TestCase<TestEngine>(function);
732 test_case.add_input<float>({-1.0, 0.0, 1.0});
733 test_case.add_expected_output<float>({0.09003058, 0.24472848, 0.66524094});
738 // common input for all Softmax 3D test cases (Shape = {3,4,5})
739 const std::vector<float> SOFTMAX_INPUT = {
740 2.75793882, -0.50841322, 0.82013929, -0.62409912, -0.96136118, 0.21004745, 1.38337255,
741 1.19030397, 2.0940445, -0.03551657, -0.78686039, 1.992782, 0.04300319, -0.29230777,
742 -0.56797112, -1.26732165, -0.61935399, 0.57670432, 0.92844898, 2.82469233,
744 0.98721677, -0.05100663, -1.21178917, -0.17530157, 1.40051805, -0.13259761, -1.14313018,
745 0.2673723, -0.87996154, 1.29053106, 1.55, 0.8396538, 1.20729817, 0.23727845,
746 -0.89113606, -1.70909842, 0.26460363, -0.70566808, 2.383518, 1.07024615,
748 -1.21722605, 0.82919357, 0.55765697, 0.12657686, 0.63432172, 0.75425957, -2.43721014,
749 -1.24478184, 2.65316853, 1.19509542, -0.95523998, 0.5149006, -0.01151649, 0.68327026,
750 -0.4589638, -0.46554745, 0.21055324, 0.39266729, 2.05098086, 1.83207919};
753 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0)
755 auto function = onnx_import::import_onnx_model(
756 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_0.prototxt"));
758 auto test_case = test::TestCase<TestEngine>(function);
759 test_case.add_input<float>(SOFTMAX_INPUT);
761 test_case.add_expected_output<float>(
762 {0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823, 0.00757665, 0.02449322,
763 0.02019284, 0.04985249, 0.00592694, 0.00279593, 0.04505148, 0.00641108, 0.00458466,
764 0.00348007, 0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497,
766 0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679, 0.00537859, 0.00195794,
767 0.00802367, 0.00254737, 0.0223216, 0.02893419, 0.0142204, 0.02053893, 0.00778581,
768 0.00251907, 0.00111174, 0.00800149, 0.0030324, 0.06658917, 0.0179084,
770 0.00181811, 0.01407243, 0.01072611, 0.0069699, 0.01158077, 0.01305647, 0.00053677,
771 0.0017687, 0.08719896, 0.02028982, 0.00236265, 0.01027717, 0.0060709, 0.01216173,
772 0.00388087, 0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337});
777 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1)
779 auto function = onnx_import::import_onnx_model(
780 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_1.prototxt"));
782 auto test_case = test::TestCase<TestEngine>(function);
783 test_case.add_input<float>(SOFTMAX_INPUT);
785 test_case.add_expected_output<float>(
786 {0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188, 0.0178066, 0.05756383,
787 0.04745709, 0.11716303, 0.01392945, 0.00657097, 0.10587974, 0.01506727, 0.01077484,
788 0.00817884, 0.00406413, 0.00776921, 0.0256932, 0.03652405, 0.24328028,
790 0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488, 0.02028993, 0.00738604,
791 0.03026811, 0.00960958, 0.08420492, 0.10914991, 0.05364435, 0.07748005, 0.02937079,
792 0.0095028, 0.00419387, 0.03018442, 0.01143929, 0.2511977, 0.06755678,
794 0.00587593, 0.04548053, 0.0346656, 0.02252594, 0.03742775, 0.04219705, 0.00173478,
795 0.00571623, 0.2818174, 0.06557446, 0.00763582, 0.03321466, 0.01962049, 0.03930537,
796 0.01254255, 0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617});
801 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_1D)
803 ASSERT_THROW(onnx_import::import_onnx_model(
804 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_1D.prototxt")),
805 ngraph::ngraph_error)
806 << "Softmax model with invalid axis was successfully imported while it should have thrown.";
809 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_3D)
811 ASSERT_THROW(onnx_import::import_onnx_model(
812 file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_3D.prototxt")),
813 ngraph::ngraph_error)
814 << "Softmax model with invalid axis was successfully imported while it should have thrown.";
817 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sub)
820 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sub.prototxt"));
823 inputs.emplace_back(test::NDArray<float, 3>({{{1, 2, 3}}}).get_vector());
825 inputs.emplace_back(test::NDArray<float, 3>({{{4, 5, 7}}}).get_vector());
827 auto expected_output = test::NDArray<float, 3>({{{-3, -3, -4}}}).get_vector();
829 auto test_case = test::TestCase<TestEngine>(function);
830 test_case.add_multiple_inputs(inputs);
831 test_case.add_expected_output(expected_output);
835 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_div)
838 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/div.prototxt"));
841 inputs.emplace_back(test::NDArray<float, 3>({{{1, 2, 3}}}).get_vector());
842 inputs.emplace_back(test::NDArray<float, 3>({{{1, 4, 12}}}).get_vector());
844 auto expected_output = test::NDArray<float, 3>({{{1, 0.5, 0.25}}}).get_vector();
846 auto test_case = test::TestCase<TestEngine>(function);
847 test_case.add_multiple_inputs(inputs);
848 test_case.add_expected_output(expected_output);
852 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_add_bcast)
854 auto function = onnx_import::import_onnx_model(
855 file_util::path_join(SERIALIZED_ZOO, "onnx/add_bcast.prototxt"));
858 inputs.emplace_back(test::NDArray<float, 3>(
859 {{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
860 {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
861 {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
864 inputs.emplace_back(test::NDArray<float, 1>({1, 2, 3, 4, 5}).get_vector());
866 auto expected_output =
867 test::NDArray<float, 4>(
868 {{{{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}},
869 {{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}},
870 {{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}}}})
873 auto test_case = test::TestCase<TestEngine>(function);
874 test_case.add_multiple_inputs(inputs);
875 test_case.add_expected_output(expected_output);
879 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_log_sum)
881 auto function = onnx_import::import_onnx_model(
882 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum.prototxt"));
884 // input data shape (1, 1, 4, 4)
886 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
889 // output data shape (1,)
890 auto expected_output = test::NDArray<float, 4>({{{{2.77258872f}}}}).get_vector();
892 auto test_case = test::TestCase<TestEngine>(function);
893 test_case.add_multiple_inputs(inputs);
894 test_case.add_expected_output(expected_output);
898 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_log_sum_exp)
900 auto function = onnx_import::import_onnx_model(
901 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum_exp.prototxt"));
903 // input data shape (1, 1, 4, 4)
905 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
908 // output data shape (1,)
909 auto expected_output = test::NDArray<float, 4>({{{{3.77258872f}}}}).get_vector();
911 auto test_case = test::TestCase<TestEngine>(function);
912 test_case.add_multiple_inputs(inputs);
913 test_case.add_expected_output(expected_output);
917 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_l1)
919 auto function = onnx_import::import_onnx_model(
920 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l1.prototxt"));
922 // input data shape (1, 1, 4, 4)
924 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
927 // output data shape (1,)
928 auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
930 auto test_case = test::TestCase<TestEngine>(function);
931 test_case.add_multiple_inputs(inputs);
932 test_case.add_expected_output(expected_output);
936 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_l2)
938 auto function = onnx_import::import_onnx_model(
939 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l2.prototxt"));
941 // input data shape (1, 1, 4, 4)
943 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
946 // output data shape (1,)
947 auto expected_output = test::NDArray<float, 4>({{{{4}}}}).get_vector();
949 auto test_case = test::TestCase<TestEngine>(function);
950 test_case.add_multiple_inputs(inputs);
951 test_case.add_expected_output(expected_output);
955 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_max)
957 auto function = onnx_import::import_onnx_model(
958 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_max.prototxt"));
960 // input data shape (1, 1, 4, 4)
962 test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
965 // output data shape (1,)
966 auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
968 auto test_case = test::TestCase<TestEngine>(function);
969 test_case.add_multiple_inputs(inputs);
970 test_case.add_expected_output(expected_output);
974 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_mean)
976 auto function = onnx_import::import_onnx_model(
977 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_mean.prototxt"));
979 // input data shape (1, 1, 4, 4)
981 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
984 // output data shape (1,)
985 auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
987 auto test_case = test::TestCase<TestEngine>(function);
988 test_case.add_multiple_inputs(inputs);
989 test_case.add_expected_output(Shape{}, expected_output);
993 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_min)
995 auto function = onnx_import::import_onnx_model(
996 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_min.prototxt"));
998 // input data shape (1, 1, 4, 4)
1000 test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
1003 // output data shape (1,)
1004 auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
1006 auto test_case = test::TestCase<TestEngine>(function);
1007 test_case.add_multiple_inputs(inputs);
1008 test_case.add_expected_output(expected_output);
1012 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_prod)
1014 auto function = onnx_import::import_onnx_model(
1015 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_prod.prototxt"));
1017 // input data shape (1, 1, 4, 4)
1019 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1022 // output data shape (1,)
1023 auto expected_output = test::NDArray<float, 4>({{{{1}}}}).get_vector();
1025 auto test_case = test::TestCase<TestEngine>(function);
1026 test_case.add_multiple_inputs(inputs);
1027 test_case.add_expected_output(expected_output);
1031 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_sum)
1033 auto function = onnx_import::import_onnx_model(
1034 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum.prototxt"));
1036 // input data shape (1, 1, 4, 4)
1038 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1041 // output data shape (1,)
1042 auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
1044 auto test_case = test::TestCase<TestEngine>(function);
1045 test_case.add_multiple_inputs(inputs);
1046 test_case.add_expected_output(expected_output);
1050 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reduce_sum_square)
1052 auto function = onnx_import::import_onnx_model(
1053 file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum_square.prototxt"));
1055 // input data shape (1, 1, 4, 4)
1057 test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
1060 // output data shape (1,)
1061 auto expected_output = test::NDArray<float, 4>({{{{16}}}}).get_vector();
1063 auto test_case = test::TestCase<TestEngine>(function);
1064 test_case.add_multiple_inputs(inputs);
1065 test_case.add_expected_output(expected_output);
1069 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_resize10_import_only)
1071 const auto resize_fn = onnx_import::import_onnx_model(
1072 file_util::path_join(SERIALIZED_ZOO, "onnx/resize_opset10.prototxt"));
1074 // Input data shape (1, 2, 3, 4)
1075 // Scales input constant values {4, 3, 2, 1}
1077 Shape expected_output_shape{4, 6, 6, 4};
1078 EXPECT_EQ(resize_fn->get_output_size(), 1);
1079 EXPECT_EQ(resize_fn->get_output_shape(0), expected_output_shape);
1080 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Interpolate>(resize_fn), 1);
1081 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(resize_fn), 1);
1084 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_down_scales_const_linear)
1086 const auto function = onnx_import::import_onnx_model(
1087 file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_down_scales_const_linear.prototxt"));
1089 // Input data shape (1, 1, 2, 4)
1090 // Input const scales values {1.0, 1.0, 0.6, 0.6}
1093 Shape expected_output_shape{1, 1, 1, 2};
1094 auto test_case = test::TestCase<TestEngine>(function);
1095 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0});
1096 test_case.add_expected_output<float>(expected_output_shape, {1.0, 2.66666651});
1100 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_down_scales_const_nearest)
1102 const auto function = onnx_import::import_onnx_model(
1103 file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_down_scales_const_nearest.prototxt"));
1105 // Input data shape (1, 1, 2, 4)
1106 // Input const scales values {1.0, 1.0, 0.6, 0.6}
1109 Shape expected_output_shape{1, 1, 1, 2};
1110 auto test_case = test::TestCase<TestEngine>(function);
1111 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0});
1112 test_case.add_expected_output<float>(expected_output_shape, {1.0, 3.0});
1116 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_up_scales_const_linear)
1118 const auto function = onnx_import::import_onnx_model(
1119 file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_up_scales_const_linear.prototxt"));
1121 // Input data shape (1, 1, 2, 2)
1122 // Input const scales values {1.0, 1.0, 2.0, 2.0}
1125 Shape expected_output_shape{1, 1, 4, 4};
1126 auto test_case = test::TestCase<TestEngine>(function);
1127 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
1128 test_case.add_expected_output<float>(
1129 expected_output_shape,
1130 {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
1134 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_up_scales_const_nearest)
1136 const auto function = onnx_import::import_onnx_model(
1137 file_util::path_join(SERIALIZED_ZOO, "onnx/resize10_up_scales_const_nearest.prototxt"));
1139 // Input data shape (1, 1, 2, 2)
1140 // Input const scales values {1.0, 1.0, 2.0, 3.0}
1143 Shape expected_output_shape{1, 1, 4, 6};
1144 auto test_case = test::TestCase<TestEngine>(function);
1145 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
1146 test_case.add_expected_output<float>(
1147 expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
1148 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
1153 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_down_linear)
1155 const auto function = onnx_import::import_onnx_model(
1156 file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_down_linear.prototxt"));
1158 const Shape expected_output_shape{1, 1, 1, 2};
1159 auto test_case = test::TestCase<TestEngine>(function);
1160 const size_t input_size = 8;
1161 std::vector<float> input_data(input_size);
1162 std::iota(std::begin(input_data), std::end(input_data), 1.0f);
1163 test_case.add_input<float>(input_data);
1164 test_case.add_expected_output<float>(expected_output_shape, {1.0f, 2.66666651f});
1169 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_up_linear_asymmetric)
1171 const auto function = onnx_import::import_onnx_model(
1172 file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_up_linear_asymmetric.prototxt"));
1174 const Shape expected_output_shape{2, 1, 4, 8};
1175 auto test_case = test::TestCase<TestEngine>(function);
1176 const size_t input_size = 8;
1177 std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1178 test_case.add_input<float>(input_data);
1179 test_case.add_expected_output<float>(
1180 expected_output_shape,
1181 {1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 2.5f, 3.25f, 4.0f,
1182 4.75f, 5.5f, 5.5f, 5.5f, 5.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f,
1183 8.0f, 8.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f, 8.0f, 8.0f,
1185 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 2.0f, 2.0f, 2.0f, 6.5f, 6.5f, 6.5f,
1186 6.5f, 6.5f, 6.5f, 6.5f, 6.5f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f,
1187 11.0f, 11.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, 11.0f, 11.0f});
1192 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor)
1194 const auto function = onnx_import::import_onnx_model(file_util::path_join(
1195 SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor.prototxt"));
1197 const Shape expected_output_shape{2, 1, 4, 1};
1198 auto test_case = test::TestCase<TestEngine>(function);
1199 const std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1200 test_case.add_input<float>(input_data);
1201 test_case.add_expected_output<float>(expected_output_shape,
1202 {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1207 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes)
1209 const auto function = onnx_import::import_onnx_model(file_util::path_join(
1210 SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt"));
1212 const Shape expected_output_shape{2, 1, 4, 1};
1213 auto test_case = test::TestCase<TestEngine>(function);
1214 const std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1215 test_case.add_input<float>(input_data);
1216 test_case.add_input<float>(
1217 std::vector<float>{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); // roi
1218 test_case.add_input<float>(std::vector<float>{1.0f, 1.0f, 2.0f, 0.5f}); // scales
1219 test_case.add_expected_output<float>(expected_output_shape,
1220 {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1225 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_nearest_asymmetric_floor)
1227 const auto function = onnx_import::import_onnx_model(file_util::path_join(
1228 SERIALIZED_ZOO, "onnx/resize11_sizes_nearest_asymmetric_floor.prototxt"));
1230 const Shape expected_output_shape{2, 1, 4, 1};
1231 auto test_case = test::TestCase<TestEngine>(function);
1232 std::vector<float> input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f};
1233 test_case.add_input<float>(input_data);
1234 test_case.add_expected_output<float>(expected_output_shape,
1235 {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f});
1240 NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_linear)
1242 const auto function = onnx_import::import_onnx_model(
1243 file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_sizes_linear.prototxt"));
1245 const Shape expected_output_shape{2, 1, 4, 8};
1246 auto test_case = test::TestCase<TestEngine>(function);
1247 std::vector<float> input_data{2.0f, 4.0f, 1.0f, 3.0f, 7.0f, 8.0f, 9.0f, 6.0f};
1248 test_case.add_input<float>(input_data);
1249 test_case.add_expected_output<float>(
1250 expected_output_shape,
1251 {2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.0f, 4.0f, 4.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f,
1252 3.5f, 3.5f, 3.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 1.0f, 1.5f,
1253 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 7.0f, 7.25f, 7.5f, 7.75f, 8.0f, 8.0f, 8.0f,
1254 8.0f, 8.0f, 7.75f, 7.5f, 7.25f, 7.0f, 7.0f, 7.0f, 7.0f, 9.0f, 8.25f, 7.5f, 6.75f,
1255 6.0f, 6.0f, 6.0f, 6.0f, 9.0f, 8.25f, 7.5f, 6.75f, 6.0f, 6.0f, 6.0f, 6.0f});
1260 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shape)
1263 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/shape.prototxt"));
1266 inputs.emplace_back(test::NDArray<float, 3>(
1267 {{{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
1268 {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}},
1269 {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}})
1272 auto test_case = test::TestCase<TestEngine>(function);
1273 test_case.add_multiple_inputs(inputs);
1274 test_case.add_expected_output<int64_t>({3, 4, 5});
1278 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_elu)
1281 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/elu.prototxt"));
1284 inputs.emplace_back(
1285 test::NDArray<float, 3>(
1286 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1287 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1288 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1291 auto expected_output = test::NDArray<float, 3>({{{-1.999753180391830f,
1292 -1.999329074744190f,
1293 -1.998176236068890f,
1294 -1.995042495646670f,
1295 -1.986524106001830f},
1296 {-1.963368722222530f,
1297 -1.900425863264270f,
1298 -1.729329433526770f,
1299 -1.264241117657120f,
1303 {{-1.963368722222530f,
1304 -1.900425863264270f,
1305 -1.729329433526770f,
1306 -1.264241117657120f,
1310 {11, 12, 13, 14, 15}},
1312 {-1.264241117657120f,
1313 -1.264241117657120f,
1314 -1.264241117657120f,
1315 -1.264241117657120f,
1316 -1.264241117657120f},
1321 auto test_case = test::TestCase<TestEngine>(function);
1322 test_case.add_multiple_inputs(inputs);
1323 test_case.add_expected_output(expected_output);
1327 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_leaky_relu)
1329 auto function = onnx_import::import_onnx_model(
1330 file_util::path_join(SERIALIZED_ZOO, "onnx/leaky_relu.prototxt"));
1333 inputs.emplace_back(
1334 test::NDArray<float, 3>(
1335 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1336 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1337 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1340 auto expected_output = test::NDArray<float, 3>({{{-0.9f, -0.8f, -0.7f, -0.6f, -0.5f},
1341 {-0.4f, -0.3f, -0.2f, -0.1f, 0},
1344 {{-0.4f, -0.3f, -0.2f, -0.1f, 0},
1347 {11, 12, 13, 14, 15}},
1349 {-0.1f, -0.1f, -0.1f, -0.1f, -0.1f},
1354 auto test_case = test::TestCase<TestEngine>(function);
1355 test_case.add_multiple_inputs(inputs);
1356 test_case.add_expected_output(expected_output);
1360 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_prelu)
1363 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/prelu.prototxt"));
1366 inputs.emplace_back(
1367 test::NDArray<float, 3>(
1368 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1369 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1370 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1373 inputs.emplace_back(test::NDArray<float, 3>(
1374 {{{1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}},
1375 {{0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}},
1376 {{1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}}})
1379 auto expected_output =
1380 test::NDArray<float, 3>(
1381 {{{-9, 0, -7, 0, -5}, {0, -3, 0, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1382 {{0, -3, 0, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1383 {{1, 1, 1, 1, 1}, {0, -1, 0, -1, 0}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1386 auto test_case = test::TestCase<TestEngine>(function);
1387 test_case.add_multiple_inputs(inputs);
1388 test_case.add_expected_output(expected_output);
1392 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_selu)
1395 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/selu.prototxt"));
1398 inputs.emplace_back(
1399 test::NDArray<float, 3>(
1400 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1401 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1402 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1405 auto expected_output =
1406 test::NDArray<float, 3>(
1407 {{{-5.99925954117548f,
1411 -5.95957231800549f},
1412 {-5.89010616666759f, -5.70127758979282f, -5.18798830058032f, -3.79272335297135f, 0},
1414 {18, 21, 24, 27, 30}},
1415 {{-5.89010616666759f, -5.70127758979282f, -5.18798830058032f, -3.79272335297135f, 0},
1417 {18, 21, 24, 27, 30},
1418 {33, 36, 39, 42, 45}},
1420 {-3.79272335297135f,
1424 -3.79272335297135f},
1429 auto test_case = test::TestCase<TestEngine>(function);
1430 test_case.add_multiple_inputs(inputs);
1431 test_case.add_expected_output(expected_output);
1435 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sigmoid)
1437 auto function = onnx_import::import_onnx_model(
1438 file_util::path_join(SERIALIZED_ZOO, "onnx/sigmoid.prototxt"));
1441 inputs.emplace_back(
1442 test::NDArray<float, 3>(
1443 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1444 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1445 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1448 auto expected_output = test::NDArray<float, 3>({{{0.00012339457598623f,
1449 0.00033535013046648f,
1450 0.00091105119440065f,
1451 0.00247262315663477f,
1452 0.00669285092428486f},
1453 {0.01798620996209160f,
1454 0.04742587317756680f,
1458 {0.731058578630005f,
1462 0.993307149075715f},
1463 {0.997527376843365f,
1467 0.999954602131298f}},
1468 {{0.01798620996209160f,
1469 0.04742587317756680f,
1473 {0.731058578630005f,
1477 0.993307149075715f},
1478 {0.997527376843365f,
1482 0.999954602131298f},
1483 {0.999983298578152f,
1487 0.999999694097773f}},
1488 {{0.731058578630005f,
1492 0.731058578630005f},
1493 {0.268941421369995f,
1497 0.268941421369995f},
1498 {0.5f, 0.5f, 0.5f, 0.5f, 0.5f},
1499 {0.880797077977882f,
1503 0.880797077977882f}}})
1506 auto test_case = test::TestCase<TestEngine>(function);
1507 test_case.add_multiple_inputs(inputs);
1508 test_case.add_expected_output(expected_output);
1512 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_tanh)
1515 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/tanh.prototxt"));
1518 inputs.emplace_back(
1519 test::NDArray<float, 3>(
1520 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1521 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1522 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1525 auto expected_output = test::NDArray<float, 3>({{{-0.999999969540041f,
1526 -0.999999774929676f,
1527 -0.999998336943945f,
1528 -0.999987711650796f,
1529 -0.999909204262595f},
1530 {-0.999329299739067f,
1531 -0.995054753686731f,
1532 -0.964027580075817f,
1533 -0.761594155955765f,
1535 {0.761594155955765f,
1539 0.999909204262595f},
1540 {0.999987711650796f,
1544 0.999999995877693f}},
1545 {{-0.999329299739067f,
1546 -0.995054753686731f,
1547 -0.964027580075817f,
1548 -0.761594155955765f,
1550 {0.761594155955765f,
1554 0.999909204262595f},
1555 {0.999987711650796f,
1559 0.999999995877693f},
1560 {0.999999999442106f,
1564 0.999999999999813f}},
1565 {{0.761594155955765f,
1569 0.761594155955765f},
1570 {-0.761594155955765f,
1571 -0.761594155955765f,
1572 -0.761594155955765f,
1573 -0.761594155955765f,
1574 -0.761594155955765f},
1576 {0.964027580075817f,
1580 0.964027580075817f}}})
1583 auto test_case = test::TestCase<TestEngine>(function);
1584 test_case.add_multiple_inputs(inputs);
1585 test_case.add_expected_output(expected_output);
1589 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_thresholded_relu)
1591 auto function = onnx_import::import_onnx_model(
1592 file_util::path_join(SERIALIZED_ZOO, "onnx/thresholded_relu.prototxt"));
1595 inputs.emplace_back(
1596 test::NDArray<float, 3>(
1597 {{{-9, -8, -7, -6, -5}, {-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}},
1598 {{-4, -3, -2, -1, 0}, {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1599 {{1, 1, 1, 1, 1}, {-1, -1, -1, -1, -1}, {0, 0, 0, 0, 0}, {2, 2, 2, 2, 2}}})
1602 auto expected_output =
1603 test::NDArray<float, 3>(
1604 {{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 3, 4, 5}, {6, 7, 8, 9, 10}},
1605 {{0, 0, 0, 0, 0}, {0, 0, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}},
1606 {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}})
1609 auto test_case = test::TestCase<TestEngine>(function);
1610 test_case.add_multiple_inputs(inputs);
1611 test_case.add_expected_output(expected_output);
1615 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_matmul_vec_ten3d)
1617 auto function = onnx_import::import_onnx_model(
1618 file_util::path_join(SERIALIZED_ZOO, "onnx/matmul_vec_ten3d.prototxt"));
1621 inputs.emplace_back(std::vector<float>{0.f, 1.f});
1622 inputs.emplace_back(
1623 test::NDArray<float, 3>{{{0.f}, {1.f}}, {{2.f}, {3.f}}, {{4.f}, {5.f}}}.get_vector());
1625 auto expected_output = test::NDArray<float, 2>{{1.f}, {3.f}, {5.f}}.get_vector();
1627 auto test_case = test::TestCase<TestEngine>(function);
1628 test_case.add_multiple_inputs(inputs);
1629 test_case.add_expected_output(expected_output);
1633 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softplus)
1635 auto function = onnx_import::import_onnx_model(
1636 file_util::path_join(SERIALIZED_ZOO, "onnx/softplus.prototxt"));
1638 // -1.0f, 0, 1.0f, 10.f, normal input values for activation
1639 // 100.0f, -100.0f, 1000.0f, -1000.0f, input values that leads to exp() overflow
1640 // FLT_MIN, FLT_MIN / 16, -FLT_MIN / 16, min, denorm, -denorm
1641 // FLT_MAX, -FLT_MAX, max, -max;
1642 Inputs inputs{std::vector<float>{-1.0f,
1656 std::vector<float>& input = inputs.back();
1657 std::vector<float> output;
1658 auto softplus_impl = [](float x) -> float {
1661 return x + std::log(std::exp(-x) + 1);
1665 return std::log(std::exp(x) + 1);
1669 std::transform(std::begin(input), std::end(input), std::back_inserter(output), softplus_impl);
1671 auto test_case = test::TestCase<TestEngine>(function);
1672 test_case.add_multiple_inputs(inputs);
1673 test_case.add_expected_output(output);
1677 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softplus_infinity)
1679 auto function = onnx_import::import_onnx_model(
1680 file_util::path_join(SERIALIZED_ZOO, "onnx/softplus.prototxt"));
1682 std::vector<float> input(13, std::numeric_limits<float>::infinity());
1683 std::vector<float> expected_output(13, std::numeric_limits<float>::infinity());
1685 auto test_case = test::TestCase<TestEngine>(function);
1686 test_case.add_input(input);
1687 test_case.add_expected_output(expected_output);
1691 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sum_opset8)
1693 auto function = onnx_import::import_onnx_model(
1694 file_util::path_join(SERIALIZED_ZOO, "onnx/sum_opset8.prototxt"));
1697 inputs.emplace_back(std::vector<float>{1.0f, 2.0f, 3.0f});
1698 inputs.emplace_back(test::NDArray<float, 2>{{10.0f}, {20.0f}, {30.0f}}.get_vector());
1699 inputs.emplace_back(test::NDArray<float, 3>{{{100.0f}}, {{200.0f}}, {{300.0f}}}.get_vector());
1701 auto expected_output =
1702 test::NDArray<float, 3>{
1703 {{111.0f, 112.0f, 113.0f}, {121.0f, 122.0f, 123.0f}, {131.0f, 132.0f, 133.0f}},
1705 {{211.0f, 212.0f, 213.0f}, {221.0f, 222.0f, 223.0f}, {231.0f, 232.0f, 233.0f}},
1707 {{311.0f, 312.0f, 313.0f}, {321.0f, 322.0f, 323.0f}, {331.0f, 332.0f, 333.0f}}}
1710 auto test_case = test::TestCase<TestEngine>(function);
1711 test_case.add_multiple_inputs(inputs);
1712 test_case.add_expected_output(expected_output);
1716 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmax_int32)
1718 auto function = onnx_import::import_onnx_model(
1719 file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_int32.prototxt"));
1721 auto test_case = test::TestCase<TestEngine>(function);
1722 test_case.add_input<std::int32_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
1723 test_case.add_expected_output<std::int32_t>({1, 1, 1, 1, 1, 1});
1727 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_int32)
1729 auto function = onnx_import::import_onnx_model(
1730 file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_int32.prototxt"));
1732 auto test_case = test::TestCase<TestEngine>(function);
1733 test_case.add_input<std::int32_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
1734 test_case.add_expected_output<std::int32_t>({0, 0, 0, 0});
1738 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmax_float)
1740 auto function = onnx_import::import_onnx_model(
1741 file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_float.prototxt"));
1743 auto test_case = test::TestCase<TestEngine>(function);
1744 test_case.add_input<float>({4, 0.1, 2, 3, -3, 1, -0.9, 0, 1, 2, 3, 0});
1745 test_case.add_expected_output<std::int64_t>({0, 3, 0});
1749 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_float)
1751 auto function = onnx_import::import_onnx_model(
1752 file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_float.prototxt"));
1754 auto test_case = test::TestCase<TestEngine>(function);
1755 test_case.add_input<float>({4, 0.1, 2, 3, -3, 1, -0.9, 0, 1, 2, 3, 0});
1756 test_case.add_expected_output<std::int64_t>({1, 1, 0, 2});
1760 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_top_k)
1763 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/top_k.prototxt"));
1765 auto test_case = test::TestCase<TestEngine>(function);
1766 test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1767 test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1768 test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1769 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1773 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_10)
1775 auto function = onnx_import::import_onnx_model(
1776 file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_10.prototxt"));
1778 auto test_case = test::TestCase<TestEngine>(function);
1779 test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1780 test_case.add_input<int64_t>({3});
1782 test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1783 test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1784 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1788 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_10_const_k)
1790 auto function = onnx_import::import_onnx_model(
1791 file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_10_const_k.prototxt"));
1793 auto test_case = test::TestCase<TestEngine>(function);
1794 test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
1796 test_case.add_expected_output<float>(Shape{3, 3}, {3, 2, 1, 7, 6, 5, 11, 10, 9}); // values
1797 test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1798 {3, 2, 1, 3, 2, 1, 3, 2, 1}); // indices
1802 NGRAPH_TEST(${BACKEND_NAME}, onnx_top_k_opset_11_const_k_smallest)
1804 auto function = onnx_import::import_onnx_model(
1805 file_util::path_join(SERIALIZED_ZOO, "onnx/top_k_opset_11_const_k_smallest.prototxt"));
1807 auto test_case = test::TestCase<TestEngine>(function);
1808 test_case.add_input<float>({0, 1, 2, 3, 4, 5, 6, 7, 11, 10, 9, 8});
1810 test_case.add_expected_output<float>(Shape{3, 3}, {0, 1, 2, 4, 5, 6, 8, 9, 10}); // values
1811 test_case.add_expected_output<std::int64_t>(Shape{3, 3},
1812 {0, 1, 2, 0, 1, 2, 3, 2, 1}); // indices
1816 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_acosh)
1819 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/acosh.prototxt"));
1821 auto test_case = test::TestCase<TestEngine>(function);
1822 test_case.add_input<float>(Shape{1, 3}, {1.0f, 2.5f, 4.3f});
1823 test_case.add_expected_output<float>(Shape{1, 3}, {0.0f, 1.5667993f, 2.13795861f});
1828 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_asinh)
1831 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/asinh.prototxt"));
1833 auto test_case = test::TestCase<TestEngine>(function);
1834 test_case.add_input<float>(Shape{1, 3}, {-1.0f, 0.0f, 1.0f});
1835 test_case.add_expected_output<float>(Shape{1, 3}, {-0.88137358f, 0.0f, 0.88137358f});
1840 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_atanh)
1843 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/atanh.prototxt"));
1845 auto test_case = test::TestCase<TestEngine>(function);
1846 test_case.add_input<float>(Shape{1, 3}, {-0.9f, 0.0f, 0.9f});
1847 test_case.add_expected_output<float>(Shape{1, 3}, {-1.4722194f, 0.0f, 1.4722194f});
1852 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sinh)
1855 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sinh.prototxt"));
1857 auto test_case = test::TestCase<TestEngine>(function);
1858 test_case.add_input<float>({-1.0f, 0.0f, 1.0f});
1859 test_case.add_expected_output<float>({-1.1752012f, 0.f, 1.1752012f});
1863 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_cosh)
1866 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/cosh.prototxt"));
1868 auto test_case = test::TestCase<TestEngine>(function);
1869 test_case.add_input<float>({-1.0f, 0.0f, 1.0f});
1870 test_case.add_expected_output<float>({1.54308069f, 1.f, 1.54308069f});
1874 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sign)
1877 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/sign.prototxt"));
1879 Inputs inputs{std::vector<float>{-std::numeric_limits<float>::infinity(),
1883 std::numeric_limits<float>::infinity()}};
1885 auto test_case = test::TestCase<TestEngine>(function);
1886 test_case.add_multiple_inputs(inputs);
1887 test_case.add_expected_output<float>({-1.0f, -1.0f, 0.0f, 1.0f, 1.0f});
1891 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_one_hot_with_axis)
1893 auto function = onnx_import::import_onnx_model(
1894 file_util::path_join(SERIALIZED_ZOO, "onnx/one_hot_axis.prototxt"));
1896 Inputs inputs{{1.0, 9.0, 2.0, 4.0}, {1.0, 3.0}};
1897 std::vector<float> expected_output{{1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1898 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0,
1899 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 3.0,
1900 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}};
1902 auto test_case = test::TestCase<TestEngine>(function);
1903 test_case.add_multiple_inputs(inputs);
1904 test_case.add_expected_output(expected_output);
1908 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_one_hot_without_axis)
1910 auto function = onnx_import::import_onnx_model(
1911 file_util::path_join(SERIALIZED_ZOO, "onnx/one_hot_no_axis.prototxt"));
1913 std::vector<std::vector<std::int64_t>> inputs{{0, 7, 8}, {2, 5}};
1914 std::vector<std::int64_t> expected_output{5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1915 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2};
1917 auto test_case = test::TestCase<TestEngine>(function);
1918 test_case.add_multiple_inputs(inputs);
1919 test_case.add_expected_output(expected_output);
1923 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_where)
1926 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/where.prototxt"));
1928 // conditions tensor - 3x3x3
1929 auto condition = std::vector<int>{
1930 {0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0}};
1932 // 1x3 tensor of "1"
1933 auto x1 = std::vector<int>{1, 1, 1};
1934 // 3x1 tensor of "2"
1935 auto x2 = std::vector<int>{2, 2, 2};
1937 std::vector<std::vector<int>> inputs;
1938 inputs.push_back(std::move(condition));
1939 inputs.push_back(std::move(x1));
1940 inputs.push_back(std::move(x2));
1943 std::vector<int> expected_output{2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2,
1944 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2};
1946 auto test_case = test::TestCase<TestEngine>(function);
1947 test_case.add_multiple_inputs(inputs);
1948 test_case.add_expected_output(expected_output);
1952 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_erf)
1954 const auto function =
1955 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/erf.prototxt"));
1958 inputs.emplace_back(test::NDArray<float, 2>{
1959 {-std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
1961 {0.5f, 1.0f}}.get_vector());
1963 const std::vector<float> expected_output = test::NDArray<float, 2>{
1965 {-0.99999112f, 0.0f},
1966 {0.52049988f, 0.84270079f}}.get_vector();
1968 auto test_case = test::TestCase<TestEngine>(function);
1969 test_case.add_multiple_inputs(inputs);
1970 test_case.add_expected_output(expected_output);
1974 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_erf_int32)
1976 const auto function = onnx_import::import_onnx_model(
1977 file_util::path_join(SERIALIZED_ZOO, "onnx/erf_int32.prototxt"));
1979 const std::vector<std::vector<int32_t>> inputs{
1980 {-std::numeric_limits<int32_t>::max(), -1, 0, 1, std::numeric_limits<int32_t>::max()}};
1982 const std::vector<int32_t> expected_output{-1, 0, 0, 0, 1};
1984 auto test_case = test::TestCase<TestEngine>(function);
1985 test_case.add_multiple_inputs(inputs);
1986 test_case.add_expected_output(expected_output);
1990 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shrink_float)
1992 const auto function = onnx_import::import_onnx_model(
1993 file_util::path_join(SERIALIZED_ZOO, "onnx/shrink_float.prototxt"));
1995 auto test_case = test::TestCase<TestEngine>(function);
1996 test_case.add_input<float>(
1997 {-2.0f, -1.6f, -1.5f, -1.4f, -1.0f, 0.0f, 1.0f, 1.4f, 1.5f, 1.6f, 2.0f});
1998 test_case.add_expected_output<float>(
1999 Shape{11}, {-1.5f, -1.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.1f, 1.5f});
2004 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shrink_int)
2006 const auto function = onnx_import::import_onnx_model(
2007 file_util::path_join(SERIALIZED_ZOO, "onnx/shrink_int.prototxt"));
2009 auto test_case = test::TestCase<TestEngine>(function);
2010 test_case.add_input<int>({-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5});
2011 test_case.add_expected_output<int>(Shape{11}, {-4, -3, -2, -1, 0, 0, 0, 1, 2, 3, 4});
2016 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_p1)
2018 const auto function = onnx_import::import_onnx_model(
2019 file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_p1.prototxt"));
2021 Shape data_shape{2, 3, 4};
2022 std::vector<float> data(shape_size(data_shape));
2023 std::iota(std::begin(data), std::end(data), 1);
2025 auto test_case = test::TestCase<TestEngine>(function);
2026 test_case.add_input<float>(data);
2027 test_case.add_expected_output<float>(
2028 data_shape, {0.07142857f, 0.125f, 0.16666667f, 0.2f, 0.22727273f, 0.25f,
2029 0.26923078f, 0.2857143f, 0.3f, 0.3125f, 0.32352942f, 0.33333334f,
2030 0.9285714f, 0.875f, 0.8333333f, 0.8f, 0.77272725f, 0.75f,
2031 0.7307692f, 0.71428573f, 0.7f, 0.6875f, 0.6764706f, 0.6666667f});
2036 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_p2)
2038 const auto function = onnx_import::import_onnx_model(
2039 file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_p2.prototxt"));
2041 Shape data_shape{2, 3, 4};
2042 std::vector<float> data(shape_size(data_shape));
2043 std::iota(std::begin(data), std::end(data), 1);
2045 auto test_case = test::TestCase<TestEngine>(function);
2046 test_case.add_input<float>(data);
2047 test_case.add_expected_output<float>(
2048 data_shape, {0.0766965f, 0.14142136f, 0.19611613f, 0.24253564f, 0.28216633f, 0.31622776f,
2049 0.34570536f, 0.37139067f, 0.39391932f, 0.41380295f, 0.4314555f, 0.4472136f,
2050 0.9970545f, 0.98994946f, 0.9805807f, 0.97014254f, 0.9593655f, 0.9486833f,
2051 0.9383431f, 0.9284767f, 0.91914505f, 0.9103665f, 0.9021342f, 0.8944272f});
2056 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_lp_norm_default)
2058 const auto function = onnx_import::import_onnx_model(
2059 file_util::path_join(SERIALIZED_ZOO, "onnx/lp_norm_default.prototxt"));
2061 Shape data_shape{2, 3, 4};
2062 std::vector<float> data(shape_size(data_shape));
2063 std::iota(std::begin(data), std::end(data), 1);
2065 auto test_case = test::TestCase<TestEngine>(function);
2066 test_case.add_input<float>(data);
2067 test_case.add_expected_output<float>(
2068 data_shape, {0.18257418f, 0.36514837f, 0.5477225f, 0.73029673f, 0.37904903f, 0.45485884f,
2069 0.5306686f, 0.60647845f, 0.42616236f, 0.47351375f, 0.5208651f, 0.5682165f,
2070 0.4469492f, 0.48132992f, 0.51571065f, 0.5500913f, 0.45862272f, 0.48560053f,
2071 0.5125783f, 0.53955615f, 0.46609157f, 0.4882864f, 0.51048124f, 0.5326761f});
2076 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_instance_normalization)
2078 const auto function = onnx_import::import_onnx_model(
2079 file_util::path_join(SERIALIZED_ZOO, "onnx/instance_norm.prototxt"));
2081 Shape data_shape{1, 2, 3, 4};
2082 std::vector<float> data(shape_size(data_shape));
2083 std::iota(std::begin(data), std::end(data), 1);
2085 auto test_case = test::TestCase<TestEngine>(function);
2087 test_case.add_input<float>(data);
2088 test_case.add_input<float>(std::vector<float>{2.134f, 3.256f});
2089 test_case.add_input<float>(std::vector<float>{0.765f, 1.055f});
2090 test_case.add_expected_output<float>(
2091 data_shape, {-2.6335807f, -2.015657f, -1.3977331f, -0.77980936f, -0.16188562f, 0.45603812f,
2092 1.0739619f, 1.6918856f, 2.3098092f, 2.927733f, 3.5456567f, 4.1635804f,
2093 -4.130463f, -3.1876516f, -2.2448401f, -1.3020288f, -0.35921717f, 0.5835942f,
2094 1.5264057f, 2.469217f, 3.4120288f, 4.35484f, 5.2976513f, 6.240463f});
2098 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_eye_like)
2100 const auto function = onnx_import::import_onnx_model(
2101 file_util::path_join(SERIALIZED_ZOO, "onnx/eye_like.prototxt"));
2103 auto test_case = test::TestCase<TestEngine>(function);
2104 test_case.add_input<float>({0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f});
2105 test_case.add_expected_output<float>(
2106 Shape{3, 4}, {0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f});
2111 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_0_batch_1)
2113 const auto function = onnx_import::import_onnx_model(
2114 file_util::path_join(SERIALIZED_ZOO, "onnx/reverse_sequence_time_0_batch_1.prototxt"));
2115 auto test_case = test::TestCase<TestEngine>(function);
2117 test_case.add_input<float>(
2118 {0.f, 4.f, 8.f, 12.f, 1.f, 5.f, 9.f, 13.f, 2.f, 6.f, 10.f, 14.f, 3.f, 7.f, 11.f, 15.f});
2119 test_case.add_input<int>({4, 3, 2, 1});
2120 test_case.add_expected_output<float>(
2122 {3.f, 6.f, 9.f, 12.f, 2.f, 5.f, 8.f, 13.f, 1.f, 4.f, 10.f, 14.f, 0.f, 7.f, 11.f, 15.f});
2127 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_1_batch_0)
2129 const auto function = onnx_import::import_onnx_model(
2130 file_util::path_join(SERIALIZED_ZOO, "onnx/reverse_sequence_time_1_batch_0.prototxt"));
2131 auto test_case = test::TestCase<TestEngine>(function);
2133 test_case.add_input<float>(
2134 {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f});
2135 test_case.add_input<int>({1, 2, 3, 4});
2136 test_case.add_expected_output<float>(
2138 {0.f, 1.f, 2.f, 3.f, 5.f, 4.f, 6.f, 7.f, 10.f, 9.f, 8.f, 11.f, 15.f, 14.f, 13.f, 12.f});
2143 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_incorrect_batch_axis)
2145 EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2146 SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_batch_axis.prototxt")),
2148 << "ReverseSequence batch_axis attribute can only equal 0 or 1. Value of '2' is not "
2152 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_incorrect_time_axis)
2154 EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2155 SERIALIZED_ZOO, "onnx/reverse_sequence_incorrect_time_axis.prototxt")),
2157 << "ReverseSequence time_axis attribute can only equal 0 or 1. Value of '2' is not "
2161 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reverse_sequence_time_and_batch_axis_equal)
2163 EXPECT_THROW(onnx_import::import_onnx_model(file_util::path_join(
2164 SERIALIZED_ZOO, "onnx/reverse_sequence_time_and_batch_axis_equal.prototxt")),
2166 << "ReverseSequence 'time_axis' and 'batch_axis' can't be equal.";
2169 NGRAPH_TEST(${BACKEND_NAME}, onnx_matmul_float_type)
2171 auto function = onnx_import::import_onnx_model(
2172 file_util::path_join(SERIALIZED_ZOO, "onnx/matmul_float.prototxt"));
2174 auto test_case = test::TestCase<TestEngine>(function);
2175 test_case.add_input<float>(std::vector<float>{0, 1, 2, 3, 4, 5});
2176 test_case.add_input<float>(std::vector<float>{0, 1});
2177 test_case.add_expected_output<float>(Shape{3, 1}, std::vector<float>{1, 3, 5});
2182 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_mod)
2184 const auto function = onnx_import::import_onnx_model(
2185 file_util::path_join(SERIALIZED_ZOO, "onnx/mod_sign.prototxt"));
2186 auto test_case = test::TestCase<TestEngine>(function);
2188 test_case.add_input<int64_t>({-8, 3, 4, 9, -17, 1});
2189 test_case.add_input<int64_t>({22, -13, 8, -3, 7, 2});
2190 test_case.add_expected_output<int64_t>(Shape{6}, {-8, 3, 4, 0, -3, 1});
2195 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatterND)
2197 const auto function = onnx_import::import_onnx_model(
2198 file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_nd.prototxt"));
2199 auto test_case = test::TestCase<TestEngine>(function);
2201 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f});
2202 test_case.add_input<int64_t>({4, 3, 1, 7});
2203 test_case.add_input<float>({9.f, 10.f, 11.f, 12.f});
2204 test_case.add_expected_output<float>(Shape{8}, {1.f, 11.f, 3.f, 10.f, 9.f, 6.f, 7.f, 12.f});
2209 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gatherND_int32)
2211 const auto function = onnx_import::import_onnx_model(
2212 file_util::path_join(SERIALIZED_ZOO, "onnx/gatherND_int32.prototxt"));
2213 auto test_case = test::TestCase<TestEngine>(function);
2215 test_case.add_input<int32_t>({0, 1, 2, 3});
2216 test_case.add_input<int64_t>({1, 0});
2217 test_case.add_expected_output<int32_t>(Shape{2, 2}, {2, 3, 0, 1});
2222 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_gatherND_float)
2224 const auto function = onnx_import::import_onnx_model(
2225 file_util::path_join(SERIALIZED_ZOO, "onnx/gatherND_float.prototxt"));
2226 auto test_case = test::TestCase<TestEngine>(function);
2228 test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f});
2229 test_case.add_input<int64_t>({0, 1, 1, 0});
2230 test_case.add_expected_output<float>(Shape{2, 2}, {2.f, 3.f, 4.f, 5.f});
2235 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_pad_constant)
2237 const auto function = onnx_import::import_onnx_model(
2238 file_util::path_join(SERIALIZED_ZOO, "onnx/pad_constant.prototxt"));
2239 auto test_case = test::TestCase<TestEngine>(function);
2241 test_case.add_input<float>({1.f, 1.2f, 2.3f, 3.4f, 4.5f, 5.7f});
2242 test_case.add_expected_output<float>(
2243 Shape{3, 4}, {0.f, 0.f, 1.f, 1.2f, 0.f, 0.f, 2.3f, 3.4f, 0.f, 0.f, 4.5f, 5.7f});
2248 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_reciprocal)
2250 const auto function = onnx_import::import_onnx_model(
2251 file_util::path_join(SERIALIZED_ZOO, "onnx/reciprocal.prototxt"));
2252 auto test_case = test::TestCase<TestEngine>(function);
2254 test_case.add_input<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
2255 test_case.add_expected_output<float>(Shape{3, 2},
2256 {1.f, 1 / 2.f, 1 / 3.f, 1 / 4.f, 1 / 5.f, 1 / 6.f});
2261 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_round)
2263 const auto function =
2264 onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/round.prototxt"));
2265 auto test_case = test::TestCase<TestEngine>(function);
2267 test_case.add_input<float>(
2268 {0.1f, 0.9f, 1.2f, 1.5f, 1.8f, 2.3f, 2.7f, -1.1f, -1.9f, -2.2f, -2.8f});
2269 test_case.add_expected_output<float>(
2270 {0.f, 1.f, 1.f, 2.f, 2.f, 2.f, 3.f, -1.f, -2.f, -2.f, -3.f});
2275 // CASES NOT CORRECTLY HANDLED BY CURRENT IMPLEMENTATION OF ROUND
2276 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_round_half_nearest_even)
2278 const auto function = onnx_import::import_onnx_model(
2279 file_util::path_join(SERIALIZED_ZOO, "onnx/round_half_nearest_even.prototxt"));
2280 auto test_case = test::TestCase<TestEngine>(function);
2282 test_case.add_input<float>({0.5f, 2.5f, -1.5f, -2.5f});
2283 test_case.add_expected_output<float>({0.f, 2.f, -2.f, -2.f});
2288 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatter10_import_only)
2290 const auto scatter_fn = onnx_import::import_onnx_model(
2291 file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_opset10.prototxt"));
2293 const Shape data_shape{2, 2};
2295 EXPECT_EQ(scatter_fn->get_output_size(), 1);
2296 EXPECT_EQ(scatter_fn->get_output_shape(0), data_shape);
2297 EXPECT_EQ(count_ops_of_type<op::v3::ScatterElementsUpdate>(scatter_fn), 1);
2298 EXPECT_EQ(count_ops_of_type<op::v0::Constant>(scatter_fn), 4);
2301 NGRAPH_TEST(${BACKEND_NAME}, onnx_model_scatter_elements_import_only)
2303 const auto scatter_fn = onnx_import::import_onnx_model(
2304 file_util::path_join(SERIALIZED_ZOO, "onnx/scatter_elements_opset11.prototxt"));
2306 const Shape data_shape{1, 5};
2308 EXPECT_EQ(scatter_fn->get_output_size(), 1);
2309 EXPECT_EQ(scatter_fn->get_output_shape(0), data_shape);
2310 EXPECT_EQ(count_ops_of_type<op::v3::ScatterElementsUpdate>(scatter_fn), 1);
2311 EXPECT_EQ(count_ops_of_type<op::v0::Constant>(scatter_fn), 4);
2314 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_import_only)
2316 const auto function = onnx_import::import_onnx_model(
2317 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_nearest.prototxt"));
2319 // Input data shape (1, 1, 2, 2)
2320 // Scales attribute values {1.0, 1.0, 2.0, 3.0}
2322 const Shape expected_output_shape{1, 1, 4, 6};
2323 EXPECT_EQ(function->get_output_size(), 1);
2324 EXPECT_EQ(function->get_output_shape(0), expected_output_shape);
2325 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Interpolate>(function), 1);
2326 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(function), 1);
2329 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_nearest_infer)
2331 const auto function = onnx_import::import_onnx_model(
2332 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_nearest.prototxt"));
2334 // Input data shape (1, 1, 2, 2)
2335 // Scales attribute values {1.0, 1.0, 2.0, 3.0}
2338 const Shape expected_output_shape{1, 1, 4, 6};
2339 auto test_case = test::TestCase<TestEngine>(function);
2340 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2341 test_case.add_expected_output<float>(
2342 expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
2343 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
2347 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample8_linear_infer)
2349 const auto function = onnx_import::import_onnx_model(
2350 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample8_linear.prototxt"));
2352 // Input data shape (1, 1, 2, 2)
2353 // Scales attribute values {1.0, 1.0, 2.0, 2.0}
2356 const Shape expected_output_shape{1, 1, 4, 4};
2357 auto test_case = test::TestCase<TestEngine>(function);
2358 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2359 test_case.add_expected_output<float>(
2360 expected_output_shape,
2361 {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
2365 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_import_only)
2367 const auto function = onnx_import::import_onnx_model(
2368 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_nearest.prototxt"));
2370 // Input data shape (1, 1, 2, 2)
2371 // Input const scales values {1.0, 1.0, 2.0, 3.0}
2373 const Shape expected_output_shape{1, 1, 4, 6};
2374 EXPECT_EQ(function->get_output_size(), 1);
2375 EXPECT_EQ(function->get_output_shape(0), expected_output_shape);
2376 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Interpolate>(function), 1);
2377 EXPECT_EQ(count_ops_of_type<onnx_import::default_opset::Constant>(function), 1);
2380 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_nearest_infer)
2382 const auto function = onnx_import::import_onnx_model(
2383 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_nearest.prototxt"));
2385 // Input data shape (1, 1, 2, 2)
2386 // Input const scales values {1.0, 1.0, 2.0, 3.0}
2389 const Shape expected_output_shape{1, 1, 4, 6};
2390 auto test_case = test::TestCase<TestEngine>(function);
2391 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2392 test_case.add_expected_output<float>(
2393 expected_output_shape, {1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0,
2394 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0});
2398 NGRAPH_TEST(${BACKEND_NAME}, onnx_upsample9_scales_const_linear_infer)
2400 const auto function = onnx_import::import_onnx_model(
2401 file_util::path_join(SERIALIZED_ZOO, "onnx/upsample9_scales_const_linear.prototxt"));
2403 // Input data shape (1, 1, 2, 2)
2404 // Input const scales values {1.0, 1.0, 2.0, 2.0}
2407 const Shape expected_output_shape{1, 1, 4, 4};
2408 auto test_case = test::TestCase<TestEngine>(function);
2409 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0});
2410 test_case.add_expected_output<float>(
2411 expected_output_shape,
2412 {1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 3.0, 3.5, 4.0, 4.0, 3.0, 3.5, 4.0, 4.0});
2416 NGRAPH_TEST(${BACKEND_NAME}, onnx_image_scaler)
2418 const auto function = onnx_import::import_onnx_model(
2419 file_util::path_join(SERIALIZED_ZOO, "onnx/image_scaler.prototxt"));
2421 auto test_case = test::TestCase<TestEngine>(function);
2422 test_case.add_input<float>({1.0, 2.0, 3.0, 4.0, 10.0, 20.0, 30.0, 40.0});
2423 test_case.add_expected_output<float>(Shape{1, 2, 2, 2},
2424 {12.0, 14.0, 16.0, 18.0, 21.0, 41.0, 61.0, 81.0});