b310dce8080a6e02fc01aac5fe46f2d82e33b82d
[platform/upstream/opencv.git] / modules / dnn / test / test_onnx_importer.cpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4
5 // Copyright (C) 2018-2019, Intel Corporation, all rights reserved.
6 // Third party copyrights are property of their respective owners.
7
8
9 #include "test_precomp.hpp"
10 #include "npy_blob.hpp"
11 #include <opencv2/dnn/shape_utils.hpp>
12 namespace opencv_test { namespace {
13
14 template<typename TString>
15 static std::string _tf(TString filename, bool required = true)
16 {
17     return findDataFile(std::string("dnn/onnx/") + filename, required);
18 }
19
20 class Test_ONNX_layers : public DNNTestLayer
21 {
22 public:
23     bool required;
24
25     Test_ONNX_layers() : required(true) { }
26
27     enum Extension
28     {
29         npy,
30         pb
31     };
32
33     void testONNXModels(const String& basename, const Extension ext = npy,
34                         const double l1 = 0, const float lInf = 0, const bool useSoftmax = false,
35                         bool checkNoFallbacks = true, int numInps = 1)
36     {
37         String onnxmodel = _tf("models/" + basename + ".onnx", required);
38         std::vector<Mat> inps(numInps);
39         Mat ref;
40         if (ext == npy) {
41             for (int i = 0; i < numInps; ++i)
42                 inps[i] = blobFromNPY(_tf("data/input_" + basename + (numInps > 1 ? format("_%d", i) : "") + ".npy"));
43             ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
44         }
45         else if (ext == pb) {
46             for (int i = 0; i < numInps; ++i)
47                 inps[i] = readTensorFromONNX(_tf("data/input_" + basename + (numInps > 1 ? format("_%d", i) : "") + ".pb"));
48             ref = readTensorFromONNX(_tf("data/output_" + basename + ".pb"));
49         }
50         else
51             CV_Error(Error::StsUnsupportedFormat, "Unsupported extension");
52
53         checkBackend(&inps[0], &ref);
54         Net net = readNetFromONNX(onnxmodel);
55         ASSERT_FALSE(net.empty());
56
57         net.setPreferableBackend(backend);
58         net.setPreferableTarget(target);
59
60         std::vector<String> inputNames;
61         for (int i = 0; i < numInps; ++i)
62             inputNames.push_back(format("%d", i));
63         net.setInputsNames(inputNames);
64
65         for (int i = 0; i < numInps; ++i)
66             net.setInput(inps[i], inputNames[i]);
67         Mat out = net.forward("");
68
69         if (useSoftmax)
70         {
71             LayerParams lp;
72             Net netSoftmax;
73             netSoftmax.addLayerToPrev("softmaxLayer", "Softmax", lp);
74             netSoftmax.setPreferableBackend(DNN_BACKEND_OPENCV);
75
76             netSoftmax.setInput(out);
77             out = netSoftmax.forward();
78
79             netSoftmax.setInput(ref);
80             ref = netSoftmax.forward();
81         }
82         normAssert(ref, out, "", l1 ? l1 : default_l1, lInf ? lInf : default_lInf);
83         if (checkNoFallbacks)
84             expectNoFallbacksFromIE(net);
85     }
86 };
87
88 TEST_P(Test_ONNX_layers, InstanceNorm)
89 {
90     if(backend == DNN_BACKEND_CUDA)
91         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); /* MVN is not supported */
92
93     if (target == DNN_TARGET_MYRIAD)
94         testONNXModels("instancenorm", npy, 0, 0, false, false);
95     else
96         testONNXModels("instancenorm", npy);
97 }
98
99 TEST_P(Test_ONNX_layers, MaxPooling)
100 {
101 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
102     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
103         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
104 #endif
105     testONNXModels("maxpooling", npy, 0, 0, false, false);
106 }
107 TEST_P(Test_ONNX_layers, MaxPooling_2)
108 {
109 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
110     // IE exception: Cannot get memory!
111     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
112         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
113 #endif
114
115     testONNXModels("two_maxpooling", npy, 0, 0, false, false);
116 }
117
118 TEST_P(Test_ONNX_layers, Convolution)
119 {
120     testONNXModels("convolution");
121     testONNXModels("conv_asymmetric_pads");
122 }
123
124 TEST_P(Test_ONNX_layers, Convolution_variable_weight)
125 {
126     if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
127          backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD)
128         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
129
130     if (backend == DNN_BACKEND_CUDA)
131         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
132     if (backend == DNN_BACKEND_VKCOM)
133         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
134     String basename = "conv_variable_w";
135     Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
136     ASSERT_FALSE(net.empty());
137
138     net.setPreferableBackend(backend);
139     net.setPreferableTarget(target);
140
141     for (int i = 0; i < 2; i++)
142     {
143         Mat input = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_0.npy"));
144         Mat weights = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_1.npy"));
145         Mat ref = blobFromNPY(_tf("data/output_" + basename + format("_%d", i) + ".npy"));
146
147         net.setInput(input, "0");
148         net.setInput(weights, "1");
149
150         Mat out = net.forward();
151         normAssert(ref, out, "", default_l1, default_lInf);
152     }
153 }
154
155 TEST_P(Test_ONNX_layers, Convolution_variable_weight_bias)
156 {
157 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
158     // openvino/src/plugins/intel_myriad/common/src/ngraph/transformations/extract_dynamic_batch/slice_convolution.cpp:14 Expecting operation v1::GroupConvolution GroupConvolution_6904725 (Reshape_17[0]:f32{1,4,5,5}, Reshape_6904719[0]:f32{4,1,1,2,2}) -> (f32{1,4,4,4}) to have constant kernel, got Reshape_6904719[0]:f32{4,1,1,2,2}
159     // openvino\src\plugins\intel_myriad\common\src\ngraph\transformations\extract_dynamic_batch\slice_convolution.cpp:15 Expecting operation v1::GroupConvolution GroupConvolution_6904692 (Reshape_17[0]:f32{1,4,5,5}, Reshape_6904686[0]:f32{4,1,1,2,2}) -> (f32{1,4,4,4}) to have constant kernel, got Reshape_6904686[0]:f32{4,1,1,2,2}
160     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
161         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
162     // accuracy (depends on OpenCL version / HW)
163     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
164         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
165             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
166         );
167 #elif defined(INF_ENGINE_RELEASE)
168     if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
169          backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD)
170         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
171
172     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU &&
173         getInferenceEngineCPUType() == CV_DNN_INFERENCE_ENGINE_CPU_TYPE_ARM_COMPUTE)
174         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_ARM_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
175 #endif
176
177     if (backend == DNN_BACKEND_CUDA)
178         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // supports only <= 2 inputs
179
180     if (backend == DNN_BACKEND_VKCOM)
181         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
182
183     String basename = "conv_variable_wb";
184     Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
185     ASSERT_FALSE(net.empty());
186
187     net.setPreferableBackend(backend);
188     net.setPreferableTarget(target);
189
190     for (int i = 0; i < 2; i++)
191     {
192         Mat input = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_0.npy"));
193         Mat weights = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_1.npy"));
194         Mat bias = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_2.npy"));
195         Mat ref = blobFromNPY(_tf("data/output_" + basename + format("_%d", i) + ".npy"));
196
197         net.setInput(input, "0");
198         net.setInput(weights, "1");
199         net.setInput(bias, "bias");
200
201         Mat out = net.forward();
202         normAssert(ref, out, "", default_l1, default_lInf);
203     }
204 }
205
206 TEST_P(Test_ONNX_layers, Gather)
207 {
208     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
209         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
210     testONNXModels("gather", npy, 0, 0, false, false);
211     testONNXModels("gather_scalar", npy, 0, 0, false, false);
212 }
213
214 TEST_P(Test_ONNX_layers, GatherMulti)
215 {
216     // GPU plugin unsupported slice for constant
217     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
218         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
219     testONNXModels("gather_multi", npy, 0, 0, false, false);
220 }
221
222 TEST_P(Test_ONNX_layers, Convolution3D)
223 {
224     if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
225     {
226         // CUDA_FP16: cuDNN did not return a suitable algorithm for convolution.
227         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
228     }
229     testONNXModels("conv3d");
230 }
231
232 TEST_P(Test_ONNX_layers, Convolution3D_bias)
233 {
234     if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
235     {
236         // CUDA_FP16: cuDNN did not return a suitable algorithm for convolution.
237         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
238     }
239     testONNXModels("conv3d_bias");
240 }
241
242 TEST_P(Test_ONNX_layers, Two_convolution)
243 {
244 #if defined(INF_ENGINE_RELEASE)
245     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
246         && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
247     )
248         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
249 #endif
250     // Reference output values are in range [-0.855, 0.611]
251     testONNXModels("two_convolution");
252 }
253
254 TEST_P(Test_ONNX_layers, Deconvolution)
255 {
256     testONNXModels("deconvolution", npy, 0, 0, false, false);
257     testONNXModels("two_deconvolution", npy, 0, 0, false, false);
258     testONNXModels("deconvolution_group", npy, 0, 0, false, false);
259     testONNXModels("deconvolution_output_shape", npy, 0, 0, false, false);
260     if (target != DNN_TARGET_CUDA_FP16) // bug
261         testONNXModels("deconv_adjpad_2d", npy, 0, 0, false, false);
262 }
263
264 TEST_P(Test_ONNX_layers, Deconvolution3D)
265 {
266 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
267     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
268     {
269         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/frontend/frontend.cpp:592 Failed to compile layer "2":
270         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively)
271         if (target == DNN_TARGET_MYRIAD)
272             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
273     }
274 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
275     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
276     {
277         // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
278         // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively)
279         if (target == DNN_TARGET_MYRIAD)
280             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
281     }
282 #endif
283
284     if (backend == DNN_BACKEND_OPENCV)
285         throw SkipTestException("OpenCV backend is not supported");  // FIXIT use tags
286
287     if (backend == DNN_BACKEND_VKCOM)
288         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
289
290     testONNXModels("deconv3d");
291 }
292
293 TEST_P(Test_ONNX_layers, Deconvolution3D_bias)
294 {
295 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
296     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
297     {
298         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/frontend/frontend.cpp:592 Failed to compile layer "3":
299         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 3@weights Const data got different desc and content byte sizes (270 and 810 respectively)
300         if (target == DNN_TARGET_MYRIAD)
301             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
302     }
303 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
304     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
305     {
306         // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
307         // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively)
308         if (target == DNN_TARGET_MYRIAD)
309             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
310     }
311 #endif
312
313     if (backend == DNN_BACKEND_OPENCV)
314         throw SkipTestException("OpenCV backend is not supported");  // FIXIT use tags
315
316     if (backend == DNN_BACKEND_VKCOM)
317         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
318
319     testONNXModels("deconv3d_bias");
320 }
321
322 TEST_P(Test_ONNX_layers, Deconvolution3D_pad)
323 {
324 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
325     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
326     {
327         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/frontend/frontend.cpp:592 Failed to compile layer "3":
328         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 3@weights Const data got different desc and content byte sizes (108 and 432 respectively)
329         if (target == DNN_TARGET_MYRIAD)
330             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
331     }
332 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
333     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
334     {
335         // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
336         // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively)
337         if (target == DNN_TARGET_MYRIAD)
338             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
339     }
340 #endif
341
342     if (backend == DNN_BACKEND_OPENCV)
343         throw SkipTestException("OpenCV backend is not supported");  // FIXIT use tags
344
345     if (backend == DNN_BACKEND_VKCOM)
346         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
347
348     testONNXModels("deconv3d_pad");
349 }
350
351 TEST_P(Test_ONNX_layers, Deconvolution3D_adjpad)
352 {
353 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
354     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
355     {
356         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/frontend/frontend.cpp:592 Failed to compile layer "3":
357         // [ GENERAL_ERROR ] openvino/src/plugins/intel_myriad/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 3@weights Const data got different desc and content byte sizes (90 and 180 respectively)
358         if (target == DNN_TARGET_MYRIAD)
359             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
360     }
361 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
362     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
363     {
364         // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
365         // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively)
366         if (target == DNN_TARGET_MYRIAD)
367             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
368     }
369 #endif
370
371     if (backend == DNN_BACKEND_OPENCV)
372         throw SkipTestException("OpenCV backend is not supported");  // FIXIT use tags
373
374     if (backend == DNN_BACKEND_VKCOM)
375         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
376
377     testONNXModels("deconv3d_adjpad");
378 }
379
380 TEST_P(Test_ONNX_layers, Dropout)
381 {
382     testONNXModels("dropout");
383 }
384
385 TEST_P(Test_ONNX_layers, Linear)
386 {
387     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
388         applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
389     testONNXModels("linear");
390 }
391
392 TEST_P(Test_ONNX_layers, ReLU)
393 {
394     testONNXModels("ReLU");
395 }
396
397 TEST_P(Test_ONNX_layers, PReLU)
398 {
399     testONNXModels("PReLU_slope");
400 }
401
402 TEST_P(Test_ONNX_layers, Clip)
403 {
404     testONNXModels("clip", npy);
405 }
406
407 TEST_P(Test_ONNX_layers, Clip_init)
408 {
409     testONNXModels("clip_init_min_max");
410     testONNXModels("clip_init_min");
411     testONNXModels("clip_init_max");
412 }
413
414 TEST_P(Test_ONNX_layers, Shape)
415 {
416     testONNXModels("shape_of_constant");
417 }
418
419 TEST_P(Test_ONNX_layers, ReduceMean)
420 {
421     testONNXModels("reduce_mean");
422     testONNXModels("reduce_mean_axis1");
423     testONNXModels("reduce_mean_axis2");
424 }
425
426 TEST_P(Test_ONNX_layers, ReduceSum)
427 {
428     testONNXModels("reduce_sum");
429     testONNXModels("reduce_sum_axis_dynamic_batch");
430 }
431
432 TEST_P(Test_ONNX_layers, ReduceMax)
433 {
434     testONNXModels("reduce_max");
435 }
436 TEST_P(Test_ONNX_layers, ReduceMax_axis_0)
437 {
438     testONNXModels("reduce_max_axis_0");
439 }
440 TEST_P(Test_ONNX_layers, ReduceMax_axis_1)
441 {
442 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
443     // [ GENERAL_ERROR ]  AssertionFailed: !out.networkInputs.empty()
444     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
445         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
446 #endif
447     testONNXModels("reduce_max_axis_1");
448 }
449
450 TEST_P(Test_ONNX_layers, Min)
451 {
452     testONNXModels("min", npy, 0, 0, false, true, 2);
453 }
454
455 TEST_P(Test_ONNX_layers, ArgLayer)
456 {
457     if (backend != DNN_BACKEND_OPENCV || target != DNN_TARGET_CPU)
458         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
459
460     testONNXModels("argmax");
461     testONNXModels("argmin");
462 }
463
464 TEST_P(Test_ONNX_layers, Scale)
465 {
466 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
467     // accuracy (inf/nan)
468     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
469         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
470 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
471     // accuracy
472     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
473         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
474     // IE exception: mkldnn_node.cpp:238 Ngraph operation Reshape with name ReduceMean_0 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
475     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
476         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
477             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
478         );
479 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
480     // Ngraph operation Reshape with name ReduceMean_0 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
481     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
482         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
483     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
484         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
485 #endif
486     testONNXModels("scale");
487 }
488
489 TEST_P(Test_ONNX_layers, Scale_broadcast)
490 {
491     if (backend == DNN_BACKEND_CUDA)
492         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // doesn't support broadcasting
493     testONNXModels("scale_broadcast", npy, 0, 0, false, true, 3);
494 }
495
496 TEST_P(Test_ONNX_layers, Scale_broadcast_mid)
497 {
498     if (backend == DNN_BACKEND_CUDA)
499         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // doesn't support broadcasting
500     testONNXModels("scale_broadcast_mid", npy, 0, 0, false, true, 2);
501 }
502
503 TEST_P(Test_ONNX_layers, ReduceMean3D)
504 {
505 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
506     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
507         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
508     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
509         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
510 #endif
511     if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
512         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
513
514     if (backend == DNN_BACKEND_VKCOM)
515         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
516
517     testONNXModels("reduce_mean3d");
518 }
519
520 TEST_P(Test_ONNX_layers, MaxPooling_Sigmoid)
521 {
522     testONNXModels("maxpooling_sigmoid");
523 }
524
525 TEST_P(Test_ONNX_layers, Cast)
526 {
527     testONNXModels("cast");
528 }
529
530 TEST_P(Test_ONNX_layers, Power)
531 {
532     testONNXModels("pow2", npy, 0, 0, false, false);
533 }
534
535 TEST_P(Test_ONNX_layers, Exp)
536 {
537     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
538         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
539     testONNXModels("exp");
540 }
541
542 TEST_P(Test_ONNX_layers, Elementwise_Ceil)
543 {
544 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
545     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
546         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
547     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
548         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
549 #endif
550     testONNXModels("ceil");
551 }
552
553 TEST_P(Test_ONNX_layers, Elementwise_Floor)
554 {
555 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
556     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
557         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
558     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
559         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
560 #endif
561     testONNXModels("floor");
562 }
563
564 TEST_P(Test_ONNX_layers, Elementwise_Log)
565 {
566 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
567     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
568         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
569     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
570         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
571 #endif
572     testONNXModels("log");
573 }
574
575 TEST_P(Test_ONNX_layers, Elementwise_Round)
576 {
577 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
578     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
579         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
580     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
581         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
582 #endif
583     testONNXModels("round");
584 }
585
586 TEST_P(Test_ONNX_layers, Elementwise_Sqrt)
587 {
588 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
589     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
590         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
591     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
592         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
593     testONNXModels("sqrt");
594 #endif
595 }
596
597 TEST_P(Test_ONNX_layers, Elementwise_not)
598 {
599 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
600     // Cannot get memory!
601     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
602         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
603     // Cannot get memory!
604     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
605         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
606             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
607         );
608     // Cannot get memory!
609     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
610         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
611 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
612     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
613         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
614     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
615         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
616 #endif
617     testONNXModels("not");
618 }
619
620 TEST_P(Test_ONNX_layers, Compare_EQ)
621 {
622 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
623     // Cannot get memory!
624     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
625         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
626 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
627     // IE exception: Function contains several inputs and outputs with one friendly name!
628     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
629         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
630             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
631         );
632     // IE exception: Function contains several inputs and outputs with one friendly name!
633     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
634         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
635 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
636     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
637         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
638     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
639         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
640 #endif
641
642     testONNXModels("equal");
643 }
644
645 TEST_P(Test_ONNX_layers, Compare_GT)
646 {
647 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
648     // Cannot get memory!
649     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
650         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
651 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
652     // IE exception: Function contains several inputs and outputs with one friendly name!
653     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
654         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
655             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
656         );
657     // IE exception: Function contains several inputs and outputs with one friendly name!
658     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
659         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
660 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
661     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
662         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
663     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
664         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
665 #endif
666
667     testONNXModels("greater");
668 }
669
670 TEST_P(Test_ONNX_layers, Compare_LT)
671 {
672 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
673     // Cannot get memory!
674     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
675         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
676 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
677     // IE exception: Function contains several inputs and outputs with one friendly name!
678     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
679         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
680             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
681         );
682     // IE exception: Function contains several inputs and outputs with one friendly name!
683     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
684         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
685 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
686     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
687         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
688     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
689         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
690 #endif
691
692     testONNXModels("less");
693 }
694
695 TEST_P(Test_ONNX_layers, Compare_GTorEQ)
696 {
697     testONNXModels("greater_or_equal");
698 }
699
700 TEST_P(Test_ONNX_layers, Compare_LEorEQ)
701 {
702     testONNXModels("less_or_equal");
703 }
704
705 TEST_P(Test_ONNX_layers, CompareSameDims_EQ)
706 {
707 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
708     // Cannot get memory!
709     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
710         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
711 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
712     // IE exception: Function contains several inputs and outputs with one friendly name!
713     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
714         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
715             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
716         );
717     // IE exception: Function contains several inputs and outputs with one friendly name!
718     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
719         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
720 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
721     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
722         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
723     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
724         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
725 #endif
726
727     testONNXModels("equal_same_dims", npy, 0, 0, false, true, 2);
728 }
729
730 TEST_P(Test_ONNX_layers, CompareSameDims_GT)
731 {
732 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
733     // Cannot get memory!
734     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
735         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
736 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
737     // IE exception: Function contains several inputs and outputs with one friendly name!
738     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
739         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
740             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
741         );
742     // IE exception: Function contains several inputs and outputs with one friendly name!
743     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
744         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
745 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
746     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
747         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
748     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
749         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
750 #endif
751
752     testONNXModels("greater_same_dims", npy, 0, 0, false, true, 2);
753 }
754
755 TEST_P(Test_ONNX_layers, CompareSameDims_LT)
756 {
757 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
758     // Cannot get memory!
759     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
760         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
761 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
762     // IE exception: Function contains several inputs and outputs with one friendly name!
763     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
764         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
765             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
766         );
767     // IE exception: Function contains several inputs and outputs with one friendly name!
768     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
769         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
770 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
771     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
772         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
773     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
774         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
775 #endif
776
777     testONNXModels("less_same_dims", npy, 0, 0, false, true, 2);
778 }
779
780 TEST_P(Test_ONNX_layers, Concatenation)
781 {
782     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
783     {
784         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
785         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
786         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
787     }
788     testONNXModels("concatenation");
789     testONNXModels("concat_const_blobs");
790 }
791
792 TEST_P(Test_ONNX_layers, Eltwise3D)
793 {
794 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
795     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
796         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
797     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
798         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
799 #endif
800     testONNXModels("eltwise3d");
801 }
802
803 TEST_P(Test_ONNX_layers, AveragePooling)
804 {
805     testONNXModels("average_pooling");
806 }
807
808 TEST_P(Test_ONNX_layers, MaxPooling3D)
809 {
810 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
811     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
812     {
813         // accuracy
814         if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
815             applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
816                 CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
817             );
818         // IE exception: [ GENERAL_ERROR ]  AssertionFailed: !expired()
819         if (target == DNN_TARGET_MYRIAD)
820             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
821     }
822 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
823     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
824     {
825         // accuracy
826         if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
827             applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
828                 CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
829             );
830         // IE exception: [ GENERAL_ERROR ]  AssertionFailed: !expired()
831         if (target == DNN_TARGET_MYRIAD)
832             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
833     }
834 #endif
835 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
836     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
837         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
838     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
839         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
840 #endif
841     if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
842         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
843
844     if (backend == DNN_BACKEND_VKCOM)
845         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
846
847     testONNXModels("max_pool3d", npy, 0, 0, false, false);
848 }
849
850 TEST_P(Test_ONNX_layers, AvePooling3D)
851 {
852 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
853     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
854         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
855     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
856         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
857 #endif
858     if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
859         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
860
861     if (backend == DNN_BACKEND_VKCOM)
862         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
863
864     testONNXModels("ave_pool3d");
865 }
866
867 TEST_P(Test_ONNX_layers, PoolConv3D)
868 {
869 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
870     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
871         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
872     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
873         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
874 #endif
875     if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
876         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
877
878     if (backend == DNN_BACKEND_VKCOM)
879         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
880
881     if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
882     {
883         // CUDA_FP16: cuDNN did not return a suitable algorithm for convolution.
884         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
885     }
886
887     testONNXModels("pool_conv_3d");
888 }
889
890 TEST_P(Test_ONNX_layers, BatchNormalization)
891 {
892     testONNXModels("batch_norm");
893 }
894
895 TEST_P(Test_ONNX_layers, BatchNormalization3D)
896 {
897     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
898     {
899         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
900         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
901         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
902     }
903     testONNXModels("batch_norm_3d");
904 }
905
906 TEST_P(Test_ONNX_layers, BatchNormalizationUnfused)
907 {
908 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
909     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
910         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
911 #endif
912     testONNXModels("frozenBatchNorm2d");
913 }
914
915 TEST_P(Test_ONNX_layers, BatchNormalizationSubgraph)
916 {
917 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
918     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
919         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
920 #endif
921     testONNXModels("batch_norm_subgraph");
922 }
923
924 TEST_P(Test_ONNX_layers, NormalizeFusionSubgraph)
925 {
926     testONNXModels("normalize_fusion");
927 }
928
929 TEST_P(Test_ONNX_layers, Transpose)
930 {
931     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
932     {
933         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
934         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
935         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
936     }
937     testONNXModels("transpose");
938 }
939
940 TEST_P(Test_ONNX_layers, Multiplication)
941 {
942     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
943         applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
944     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
945         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
946     testONNXModels("mul");
947 }
948
949 TEST_P(Test_ONNX_layers, MatMul)
950 {
951     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
952         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
953
954     testONNXModels("matmul_2d");
955     testONNXModels("matmul_3d");
956     testONNXModels("matmul_4d");
957 }
958
959 TEST_P(Test_ONNX_layers, MatMulAdd)
960 {
961 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
962     // accuracy
963     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
964         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
965 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021010000)
966     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
967         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
968 #endif
969     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
970         applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
971     testONNXModels("matmul_add");
972 }
973
974 TEST_P(Test_ONNX_layers, Expand)
975 {
976     testONNXModels("expand");
977     testONNXModels("expand_identity");
978     testONNXModels("expand_batch");
979     testONNXModels("expand_channels");
980     testONNXModels("expand_neg_batch");
981 }
982
983 TEST_P(Test_ONNX_layers, ExpandHW)
984 {
985     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
986         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
987     testONNXModels("expand_hw");
988 }
989
990 TEST_P(Test_ONNX_layers, Constant)
991 {
992 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
993     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
994             && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
995        applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
996 #endif
997     testONNXModels("constant");
998 }
999
1000 TEST_P(Test_ONNX_layers, Padding)
1001 {
1002 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000)
1003     testONNXModels("padding", npy, 0, 0, false, false);
1004 #else
1005     testONNXModels("padding");
1006 #endif
1007 }
1008
1009 TEST_P(Test_ONNX_layers, Resize)
1010 {
1011     testONNXModels("resize_nearest");
1012     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1013         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1014     testONNXModels("resize_bilinear");
1015 }
1016
1017 TEST_P(Test_ONNX_layers, ResizeUnfused)
1018 {
1019     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1020         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1021     testONNXModels("upsample_unfused_torch1.2");
1022     testONNXModels("upsample_unfused_opset9_torch1.4");
1023     testONNXModels("resize_nearest_unfused_opset11_torch1.4");
1024     testONNXModels("resize_nearest_unfused_opset11_torch1.3");
1025     testONNXModels("resize_bilinear_unfused_opset11_torch1.4");
1026 }
1027
1028 TEST_P(Test_ONNX_layers, ResizeUnfusedTwoInputs)
1029 {
1030     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1031         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1032     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1033         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1034     testONNXModels("upsample_unfused_two_inputs_opset9_torch1.4", npy, 0, 0, false, true, 2);
1035     testONNXModels("upsample_unfused_two_inputs_opset11_torch1.4", npy, 0, 0, false, true, 2);
1036 }
1037
1038 TEST_P(Test_ONNX_layers, MultyInputs)
1039 {
1040     testONNXModels("multy_inputs", npy, 0, 0, false, true, 2);
1041 }
1042
1043 TEST_P(Test_ONNX_layers, Broadcast)
1044 {
1045     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1046         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1047     testONNXModels("channel_broadcast", npy, 0, 0, false, true, 2);
1048 }
1049
1050 TEST_P(Test_ONNX_layers, DynamicResize)
1051 {
1052     testONNXModels("dynamic_resize_9", npy, 0, 0, false, true, 2);
1053     testONNXModels("dynamic_resize_10", npy, 0, 0, false, true, 2);
1054     testONNXModels("dynamic_resize_11", npy, 0, 0, false, true, 2);
1055     testONNXModels("dynamic_resize_13", npy, 0, 0, false, true, 2);
1056     testONNXModels("dynamic_resize_scale_9", npy, 0, 0, false, true, 2);
1057     testONNXModels("dynamic_resize_scale_10", npy, 0, 0, false, true, 2);
1058     testONNXModels("dynamic_resize_scale_11", npy, 0, 0, false, true, 2);
1059     testONNXModels("dynamic_resize_scale_13", npy, 0, 0, false, true, 2);
1060
1061     testONNXModels("resize_size_opset11");
1062     testONNXModels("resize_size_opset13");
1063 }
1064
1065 TEST_P(Test_ONNX_layers, Resize_HumanSeg)
1066 {
1067     testONNXModels("resize_humanseg");
1068 }
1069
1070 TEST_P(Test_ONNX_layers, Div)
1071 {
1072     const String model =  _tf("models/div.onnx");
1073     Net net = readNetFromONNX(model);
1074     ASSERT_FALSE(net.empty());
1075
1076     net.setPreferableBackend(backend);
1077     net.setPreferableTarget(target);
1078
1079     // Reference output values range is -68.80928, 2.991873. So to avoid computational
1080     // difference for FP16 we'll perform reversed division (just swap inputs).
1081     Mat inp1 = blobFromNPY(_tf("data/input_div_1.npy"));
1082     Mat inp2 = blobFromNPY(_tf("data/input_div_0.npy"));
1083     Mat ref  = blobFromNPY(_tf("data/output_div.npy"));
1084     cv::divide(1.0, ref, ref);
1085     checkBackend(&inp1, &ref);
1086
1087     net.setInput(inp1, "0");
1088     net.setInput(inp2, "1");
1089     Mat out = net.forward();
1090
1091     normAssert(ref, out, "", default_l1,  default_lInf);
1092
1093     // NaryEltwise layer suuports only CPU for now
1094     testONNXModels("div_test_1x1", npy, 0, 0, false, false, 2);
1095 }
1096
1097 TEST_P(Test_ONNX_layers, DynamicReshape)
1098 {
1099     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1100         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1101
1102     testONNXModels("dynamic_reshape");
1103     testONNXModels("dynamic_reshape_opset_11");
1104     testONNXModels("flatten_by_prod");
1105     testONNXModels("flatten_const");
1106 }
1107
1108 TEST_P(Test_ONNX_layers, Reshape)
1109 {
1110     testONNXModels("unsqueeze");
1111     testONNXModels("unsqueeze_opset_13");
1112 }
1113
1114 TEST_P(Test_ONNX_layers, Unsqueeze_Neg_Axes)
1115 {
1116     testONNXModels("unsqueeze_neg_axes");
1117 }
1118
1119 TEST_P(Test_ONNX_layers, Squeeze)
1120 {
1121     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
1122         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1123     testONNXModels("squeeze");
1124     testONNXModels("squeeze_axes_op13");
1125 }
1126
1127 TEST_P(Test_ONNX_layers, ReduceL2)
1128 {
1129     testONNXModels("reduceL2");
1130     testONNXModels("reduceL2_subgraph");
1131     testONNXModels("reduceL2_subgraph_2");
1132     testONNXModels("reduceL2_subgraph2_2");
1133 }
1134
1135 TEST_P(Test_ONNX_layers, Split)
1136 {
1137     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1138         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1139     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1140         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1141     testONNXModels("split_1");
1142     testONNXModels("split_2");
1143     testONNXModels("split_3");
1144     testONNXModels("split_4");
1145     testONNXModels("split_neg_axis");
1146 }
1147
1148 // Mul inside with 0-d tensor, output should be A x 1, but is 1 x A. PR #22652
1149 TEST_P(Test_ONNX_layers, DISABLED_Split_sizes_0d)
1150 {
1151     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1152         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1153     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1154         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1155     testONNXModels("split_sizes");
1156 }
1157
1158 TEST_P(Test_ONNX_layers, Slice)
1159 {
1160 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000)
1161     testONNXModels("slice", npy, 0, 0, false, false);
1162 #else
1163     testONNXModels("slice");
1164     testONNXModels("slice_neg_starts");
1165     testONNXModels("slice_opset_11");
1166 #endif
1167 }
1168
1169 TEST_P(Test_ONNX_layers, Slice_Steps_2DInput)
1170 {
1171     testONNXModels("slice_opset_11_steps_2d");
1172 }
1173
1174 TEST_P(Test_ONNX_layers, Slice_Steps_3DInput)
1175 {
1176 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1177     // Cannot get memory!
1178     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1179         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1180     // IE exception: Cannot get memory!
1181     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1182         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1183             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1184         );
1185 #endif
1186
1187     testONNXModels("slice_opset_11_steps_3d");
1188 }
1189
1190 TEST_P(Test_ONNX_layers, Slice_Steps_4DInput)
1191 {
1192     testONNXModels("slice_opset_11_steps_4d");
1193 }
1194
1195 TEST_P(Test_ONNX_layers, Slice_Steps_5DInput)
1196 {
1197 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1198     // Cannot get memory!
1199     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1200         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1201     // IE exception: Cannot get memory!
1202     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1203         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1204             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1205         );
1206     // Cannot get memory!
1207     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
1208         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1209 #endif
1210
1211     testONNXModels("slice_opset_11_steps_5d");
1212 }
1213
1214 TEST_P(Test_ONNX_layers, Slice_Nonseq_Axes)
1215 {
1216     testONNXModels("slice_nonseq_axes");
1217     testONNXModels("slice_nonseq_axes_steps");
1218     testONNXModels("slice_nonseq_miss_axes_steps");
1219 }
1220
1221 TEST_P(Test_ONNX_layers, Slice_Neg_Axes)
1222 {
1223     testONNXModels("slice_neg_axes");
1224     testONNXModels("slice_neg_axes_steps");
1225     testONNXModels("slice_neg_miss_axes_steps");
1226 }
1227
1228 TEST_P(Test_ONNX_layers, Softmax)
1229 {
1230     testONNXModels("softmax");
1231     testONNXModels("log_softmax", npy, 0, 0, false, false);
1232     testONNXModels("softmax_unfused");
1233 }
1234
1235 TEST_P(Test_ONNX_layers, Split_EltwiseMax)
1236 {
1237     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1238         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1239     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1240         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1241     testONNXModels("split_max");
1242 }
1243
1244 TEST_P(Test_ONNX_layers, LSTM_Activations)
1245 {
1246 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1247     // Cannot get memory!
1248     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1249         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1250     // IE exception: Node Block1326/lstm/reshape_0/permute was not assigned on any pointed device
1251     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1252         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1253             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1254         );
1255 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1256     // IE Exception: Ngraph operation Reshape with name Block1237_Output_0_before_reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape
1257     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1258         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1259             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1260         );
1261 #endif
1262
1263     testONNXModels("lstm_cntk_tanh", pb, 0, 0, false, false);
1264 }
1265
1266 // disabled due to poor handling of 1-d mats
1267 TEST_P(Test_ONNX_layers, DISABLED_LSTM)
1268 {
1269     testONNXModels("lstm", npy, 0, 0, false, false);
1270 }
1271
1272 // disabled due to poor handling of 1-d mats
1273 TEST_P(Test_ONNX_layers, DISABLED_LSTM_bidirectional)
1274 {
1275     testONNXModels("lstm_bidirectional", npy, 0, 0, false, false);
1276 }
1277
1278 TEST_P(Test_ONNX_layers, LSTM_hidden)
1279 {
1280     testONNXModels("hidden_lstm", npy, 0, 0, false, false);
1281 }
1282
1283 TEST_P(Test_ONNX_layers, LSTM_hidden_bidirectional)
1284 {
1285 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1286     // Cannot get memory!
1287     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1288         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1289     // IE exception: Node Transpose_45 was not assigned on any pointed device.
1290     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1291         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1292             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1293         );
1294 #endif
1295
1296     testONNXModels("hidden_lstm_bi", npy, 0, 0, false, false);
1297 }
1298
1299 TEST_P(Test_ONNX_layers, GRU)
1300 {
1301 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1302     // Cannot get memory!
1303     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1304         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1305     // IE exception: Node GRU_22 was not assigned on any pointed device
1306     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1307         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1308             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1309         );
1310 #endif
1311     testONNXModels("gru", npy, 0, 0, false, false);
1312 }
1313
1314 TEST_P(Test_ONNX_layers, GRU_bidirectional)
1315 {
1316     testONNXModels("gru_bi", npy, 0, 0, false, false);
1317 }
1318
1319 TEST_P(Test_ONNX_layers, LSTM_cell_forward)
1320 {
1321 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1322     // accuracy!
1323     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1324         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1325 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1326     // Ngraph operation Reshape with name LSTM_16/lstm_y/reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape
1327     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
1328         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1329     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
1330         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1331 #endif
1332     testONNXModels("lstm_cell_forward", npy, 0, 0, false, false);
1333 }
1334 TEST_P(Test_ONNX_layers, LSTM_cell_bidirectional)
1335 {
1336 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1337     // Cannot get memory!
1338     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1339         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1340 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1341     // Ngraph operation Reshape with name LSTM_16/lstm_y/reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape
1342     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
1343         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1344     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
1345         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1346 #endif
1347     testONNXModels("lstm_cell_bidirectional", npy, 0, 0, false, false);
1348 }
1349 TEST_P(Test_ONNX_layers, LSTM_cell_with_peepholes)
1350 {
1351     testONNXModels("lstm_cell_with_peepholes", npy, 0, 0, false, false);
1352 }
1353
1354 TEST_P(Test_ONNX_layers, Pad2d_Unfused)
1355 {
1356     testONNXModels("ReflectionPad2d");
1357     testONNXModels("ZeroPad2d");
1358 }
1359
1360 TEST_P(Test_ONNX_layers, LinearWithConstant)
1361 {
1362     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
1363         applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
1364 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000)
1365     applyTestTag(CV_TEST_TAG_DNN_SKIP_IE);
1366 #endif
1367     if (backend == DNN_BACKEND_CUDA)
1368         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA);
1369     testONNXModels("lin_with_constant");
1370 }
1371
1372 TEST_P(Test_ONNX_layers, MatmulWithTwoInputs)
1373 {
1374     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
1375         applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
1376 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000)
1377     applyTestTag(CV_TEST_TAG_DNN_SKIP_IE);
1378 #endif
1379     testONNXModels("matmul_with_two_inputs");
1380 }
1381
1382 TEST_P(Test_ONNX_layers, ResizeOpset11_Torch1_6)
1383 {
1384     testONNXModels("resize_opset11_torch1.6");
1385 }
1386
1387 TEST_P(Test_ONNX_layers, Mish)
1388 {
1389     testONNXModels("mish");
1390     testONNXModels("mish_no_softplus");
1391 }
1392
1393 TEST_P(Test_ONNX_layers, CalculatePads)
1394 {
1395     testONNXModels("calc_pads");
1396 }
1397
1398 TEST_P(Test_ONNX_layers, Conv1d)
1399 {
1400     testONNXModels("conv1d");
1401 }
1402
1403 TEST_P(Test_ONNX_layers, Conv1d_bias)
1404 {
1405     testONNXModels("conv1d_bias");
1406 }
1407
1408 TEST_P(Test_ONNX_layers, Conv1d_variable_weight)
1409 {
1410     if (backend == DNN_BACKEND_CUDA)
1411         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
1412     if (backend == DNN_BACKEND_VKCOM)
1413         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
1414     String basename = "conv1d_variable_w";
1415     Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
1416     ASSERT_FALSE(net.empty());
1417
1418     net.setPreferableBackend(backend);
1419     net.setPreferableTarget(target);
1420
1421     Mat input = blobFromNPY(_tf("data/input_" + basename + "_0.npy"));
1422     Mat weights = blobFromNPY(_tf("data/input_" + basename + "_1.npy"));
1423     Mat ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
1424
1425     net.setInput(input, "0");
1426     net.setInput(weights, "1");
1427
1428     Mat out = net.forward();
1429     normAssert(ref, out, "", default_l1, default_lInf);
1430 }
1431
1432 TEST_P(Test_ONNX_layers, Conv1d_variable_weight_bias)
1433 {
1434     if (backend == DNN_BACKEND_CUDA)
1435         applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
1436     if (backend == DNN_BACKEND_VKCOM)
1437         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
1438     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1439     {
1440         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1441         if (target == DNN_TARGET_CPU && getInferenceEngineCPUType() == CV_DNN_INFERENCE_ENGINE_CPU_TYPE_ARM_COMPUTE)
1442             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_ARM_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1443     }
1444     String basename = "conv1d_variable_wb";
1445     Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
1446     ASSERT_FALSE(net.empty());
1447
1448     net.setPreferableBackend(backend);
1449     net.setPreferableTarget(target);
1450
1451     Mat input = blobFromNPY(_tf("data/input_" + basename + "_0.npy"));
1452     Mat weights = blobFromNPY(_tf("data/input_" + basename + "_1.npy"));
1453     Mat bias = blobFromNPY(_tf("data/input_" + basename + "_2.npy"));
1454     Mat ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
1455
1456     net.setInput(input, "0");
1457     net.setInput(weights, "1");
1458     net.setInput(bias, "bias");
1459
1460     Mat out = net.forward();
1461     normAssert(ref, out, "", default_l1, default_lInf);
1462 }
1463
1464 TEST_P(Test_ONNX_layers, GatherMultiOutput)
1465 {
1466 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1467     // IE Exception: Ngraph operation Reshape with name 6 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
1468     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1469         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1470             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1471         );
1472 #endif
1473 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
1474     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
1475         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
1476     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
1477         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
1478 #endif
1479
1480 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2021030000)
1481     if (target == DNN_TARGET_MYRIAD)
1482         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE);
1483 #endif
1484
1485     testONNXModels("gather_multi_output", npy, 0, 0, false, false);
1486 }
1487
1488 TEST_P(Test_ONNX_layers, DynamicAxes_squeeze_and_conv)
1489 {
1490 #if defined(INF_ENGINE_RELEASE)
1491     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1492     {
1493         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1494     }
1495 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1496     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1497     {
1498         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1499     }
1500 #endif
1501 #endif
1502     testONNXModels("squeeze_and_conv_dynamic_axes");
1503 }
1504
1505 TEST_P(Test_ONNX_layers, DynamicAxes_unsqueeze_and_conv)
1506 {
1507 #if defined(INF_ENGINE_RELEASE)
1508     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1509     {
1510         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1511     }
1512 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1513     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1514     {
1515         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1516     }
1517 #endif
1518 #endif
1519     testONNXModels("unsqueeze_and_conv_dynamic_axes");
1520 }
1521
1522 TEST_P(Test_ONNX_layers, DynamicAxes_gather)
1523 {
1524 #if defined(INF_ENGINE_RELEASE)
1525     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1526     {
1527         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1528     }
1529 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1530     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1531     {
1532         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1533     }
1534 #endif
1535 #endif
1536     testONNXModels("gather_dynamic_axes", npy, 0, 0, false, false);
1537 }
1538
1539 TEST_P(Test_ONNX_layers, DynamicAxes_gather_scalar)
1540 {
1541 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1542     // accuracy
1543     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1544         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1545             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1546         );
1547 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1548     // accuracy
1549     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1550         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1551             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1552         );
1553 #elif defined(INF_ENGINE_RELEASE)
1554     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1555     {
1556         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1557     }
1558 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1559     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1560     {
1561         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1562     }
1563 #endif
1564 #endif
1565     testONNXModels("gather_scalar_dynamic_axes", npy, 0, 0, false, false);
1566 }
1567
1568 TEST_P(Test_ONNX_layers, DynamicAxes_slice)
1569 {
1570 #if defined(INF_ENGINE_RELEASE)
1571     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1572     {
1573         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1574     }
1575 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1576     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1577     {
1578         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1579     }
1580 #endif
1581 #endif
1582     testONNXModels("slice_dynamic_axes");
1583 }
1584
1585 TEST_P(Test_ONNX_layers, DynamicAxes_slice_opset_11)
1586 {
1587 #if defined(INF_ENGINE_RELEASE)
1588     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1589     {
1590         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1591     }
1592 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1593     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1594     {
1595         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1596     }
1597 #endif
1598 #endif
1599     testONNXModels("slice_opset_11_dynamic_axes");
1600 }
1601
1602 TEST_P(Test_ONNX_layers, DynamicAxes_resize_opset11_torch16)
1603 {
1604 #if defined(INF_ENGINE_RELEASE)
1605     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1606     {
1607         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1608     }
1609 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1610     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1611     {
1612         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1613     }
1614 #endif
1615 #endif
1616     testONNXModels("resize_opset11_torch1.6_dynamic_axes");
1617 }
1618
1619 TEST_P(Test_ONNX_layers, DynamicAxes_average_pooling)
1620 {
1621 #if defined(INF_ENGINE_RELEASE)
1622     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1623     {
1624         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1625     }
1626 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1627     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1628     {
1629         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1630     }
1631 #endif
1632 #endif
1633     testONNXModels("average_pooling_dynamic_axes");
1634 }
1635
1636 TEST_P(Test_ONNX_layers, DynamicAxes_maxpooling_sigmoid)
1637 {
1638 #if defined(INF_ENGINE_RELEASE)
1639     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1640     {
1641         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1642     }
1643 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1644     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1645     {
1646         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1647     }
1648 #endif
1649 #endif
1650     testONNXModels("maxpooling_sigmoid_dynamic_axes");
1651 }
1652
1653 TEST_P(Test_ONNX_layers, DynamicAxes_dynamic_batch)
1654 {
1655 #if defined(INF_ENGINE_RELEASE)
1656     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1657     {
1658         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1659     }
1660 #if INF_ENGINE_VER_MAJOR_LT(2021000000)
1661     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1662     {
1663         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1664     }
1665 #endif
1666 #endif
1667     testONNXModels("dynamic_batch");
1668 }
1669
1670
1671 TEST_P(Test_ONNX_layers, MaxPool1d)
1672 {
1673 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
1674     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1675     {
1676         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1677     }
1678     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1679     {
1680         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1681     }
1682 #endif
1683 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021040000)
1684     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
1685     {
1686         // 2021.4: [ GENERAL_ERROR ]  AssertionFailed: !expired()
1687         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1688     }
1689 #endif
1690     testONNXModels("maxpooling_1d");
1691 }
1692
1693 TEST_P(Test_ONNX_layers, MaxPoolSigmoid1d)
1694 {
1695 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1696     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1697         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1698 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
1699     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1700     {
1701         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1702     }
1703     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1704     {
1705         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1706     }
1707 #endif
1708     testONNXModels("maxpooling_sigmoid_1d");
1709 }
1710
1711 TEST_P(Test_ONNX_layers, MaxPool1d_Twise)
1712 {
1713 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1714     // Cannot get memory!
1715     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1716         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1717     // Cannot get memory!
1718     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1719         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1720             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1721         );
1722 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
1723     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1724     {
1725         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1726     }
1727     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1728     {
1729         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1730     }
1731 #endif
1732     testONNXModels("two_maxpooling_1d");
1733 }
1734
1735 TEST_P(Test_ONNX_layers, AvePool1d)
1736 {
1737 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1738     // Cannot get memory!
1739     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
1740         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1741 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
1742     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1743     {
1744         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1745     }
1746     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1747     {
1748         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1749     }
1750 #endif
1751     testONNXModels("average_pooling_1d");
1752 }
1753
1754 TEST_P(Test_ONNX_layers, PoolConv1d)
1755 {
1756 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1757     // Cannot get memory!
1758     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
1759         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1760     // Cannot get memory!
1761     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
1762         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
1763     // Cannot get memory!
1764     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1765         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1766             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1767         );
1768 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
1769     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1770     {
1771         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1772     }
1773     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1774     {
1775         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1776     }
1777 #endif
1778     testONNXModels("pool_conv_1d");
1779 }
1780
1781 TEST_P(Test_ONNX_layers, ConvResizePool1d)
1782 {
1783 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
1784     // IE Exception: Ngraph operation Reshape with name 15 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
1785     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
1786         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
1787             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
1788         );
1789 #endif
1790 #if defined(INF_ENGINE_RELEASE)
1791     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
1792     {
1793         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
1794     }
1795     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1796     {
1797         if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
1798 #if INF_ENGINE_VER_MAJOR_EQ(2021030000)
1799         if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
1800         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // exception
1801 #endif
1802     }
1803 #endif
1804     testONNXModels("conv_resize_pool_1d");
1805 }
1806
1807 TEST_P(Test_ONNX_layers, SubFromConst)
1808 {
1809     testONNXModels("sub_from_const1");
1810     testONNXModels("sub_from_const_eltwise");
1811     testONNXModels("sub_from_const_broadcast");
1812 }
1813
1814 TEST_P(Test_ONNX_layers, DivConst)
1815 {
1816     testONNXModels("div_const");
1817 }
1818
1819 TEST_P(Test_ONNX_layers, Gemm)
1820 {
1821     testONNXModels("gemm_no_transB");
1822     testONNXModels("gemm_transB_0");
1823 }
1824
1825 TEST_P(Test_ONNX_layers, Quantized_Convolution)
1826 {
1827     // The difference of QOperator and QDQ format:
1828     // https://onnxruntime.ai/docs/performance/quantization.html#onnx-quantization-representation-format.
1829     {
1830         SCOPED_TRACE("QOperator quantized model.");
1831         testONNXModels("quantized_conv_uint8_weights", npy, 0.004, 0.02);
1832         testONNXModels("quantized_conv_int8_weights", npy, 0.03, 0.5);
1833         testONNXModels("quantized_conv_per_channel_weights", npy, 0.06, 0.4);
1834         testONNXModels("quantized_conv_asymmetric_pads_int8_weights");
1835     }
1836
1837     {
1838         SCOPED_TRACE("QDQ quantized model.");
1839         testONNXModels("quantized_conv_uint8_weights_qdq", npy, 0.004, 0.02);
1840         testONNXModels("quantized_conv_int8_weights_qdq", npy, 0.03, 0.5);
1841         testONNXModels("quantized_conv_per_channel_weights_qdq", npy, 0.06, 0.4);
1842     }
1843 }
1844
1845 TEST_P(Test_ONNX_layers, Quantized_MatMul)
1846 {
1847     testONNXModels("quantized_matmul_uint8_weights", npy, 0.005, 0.007);
1848     testONNXModels("quantized_matmul_int8_weights", npy, 0.06, 0.2);
1849     testONNXModels("quantized_matmul_per_channel_weights", npy, 0.06, 0.22);
1850 }
1851
1852 TEST_P(Test_ONNX_layers, Quantized_Gemm)
1853 {
1854     testONNXModels("quantized_gemm", npy);
1855 }
1856
1857 TEST_P(Test_ONNX_layers, Quantized_MatMul_Variable_Weights)
1858 {
1859     // Unsupported
1860     EXPECT_THROW(
1861     {
1862         testONNXModels("quantized_matmul_variable_inputs");
1863     }, cv::Exception);
1864 }
1865
1866 TEST_P(Test_ONNX_layers, Quantized_Eltwise)
1867 {
1868     testONNXModels("quantized_eltwise");
1869 }
1870
1871 TEST_P(Test_ONNX_layers, Quantized_Eltwise_Scalar)
1872 {
1873     testONNXModels("quantized_eltwise_scalar");
1874 }
1875
1876 TEST_P(Test_ONNX_layers, Quantized_Eltwise_Broadcast)
1877 {
1878     testONNXModels("quantized_eltwise_broadcast");
1879 }
1880
1881 TEST_P(Test_ONNX_layers, Quantized_LeakyReLU)
1882 {
1883     testONNXModels("quantized_leaky_relu");
1884 }
1885
1886 TEST_P(Test_ONNX_layers, Quantized_Sigmoid)
1887 {
1888     testONNXModels("quantized_sigmoid");
1889 }
1890
1891 TEST_P(Test_ONNX_layers, Quantized_MaxPool)
1892 {
1893     testONNXModels("quantized_maxpool");
1894 }
1895
1896 TEST_P(Test_ONNX_layers, Quantized_AvgPool)
1897 {
1898     testONNXModels("quantized_avgpool");
1899 }
1900
1901 TEST_P(Test_ONNX_layers, Quantized_Split)
1902 {
1903     testONNXModels("quantized_split");
1904 }
1905
1906 TEST_P(Test_ONNX_layers, Quantized_Pad)
1907 {
1908     testONNXModels("quantized_padding");
1909 }
1910
1911 TEST_P(Test_ONNX_layers, Quantized_Reshape)
1912 {
1913     testONNXModels("quantized_reshape");
1914 }
1915
1916 TEST_P(Test_ONNX_layers, Quantized_Transpose)
1917 {
1918     testONNXModels("quantized_transpose");
1919 }
1920
1921 TEST_P(Test_ONNX_layers, Quantized_Squeeze)
1922 {
1923     testONNXModels("quantized_squeeze");
1924 }
1925
1926 TEST_P(Test_ONNX_layers, Quantized_Unsqueeze)
1927 {
1928     testONNXModels("quantized_unsqueeze");
1929 }
1930
1931 TEST_P(Test_ONNX_layers, Quantized_Resize)
1932 {
1933     testONNXModels("quantized_resize_nearest");
1934     testONNXModels("quantized_resize_bilinear", npy, 2e-4, 0.003);
1935     testONNXModels("quantized_resize_bilinear_align", npy, 3e-4, 0.003);
1936 }
1937
1938 TEST_P(Test_ONNX_layers, Quantized_Concat)
1939 {
1940     testONNXModels("quantized_concat");
1941     testONNXModels("quantized_concat_const_blob");
1942 }
1943
1944 TEST_P(Test_ONNX_layers, Quantized_Constant)
1945 {
1946     testONNXModels("quantized_constant", npy, 0.002, 0.008);
1947 }
1948
1949 TEST_P(Test_ONNX_layers, OutputRegistration)
1950 {
1951     testONNXModels("output_registration", npy, 0, 0, false, true, 2);
1952 }
1953
1954 INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
1955
1956 class Test_ONNX_nets : public Test_ONNX_layers
1957 {
1958 public:
1959     Test_ONNX_nets() { required = false; }
1960 };
1961
1962 TEST_P(Test_ONNX_nets, Alexnet)
1963 {
1964 #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
1965     applyTestTag(CV_TEST_TAG_MEMORY_2GB);
1966 #else
1967     applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
1968 #endif
1969
1970     const String model =  _tf("models/alexnet.onnx", false);
1971
1972     Net net = readNetFromONNX(model);
1973     ASSERT_FALSE(net.empty());
1974
1975     net.setPreferableBackend(backend);
1976     net.setPreferableTarget(target);
1977
1978     Mat inp = imread(_tf("../grace_hopper_227.png"));
1979     Mat ref = blobFromNPY(_tf("../caffe_alexnet_prob.npy"));
1980     checkBackend(&inp, &ref);
1981
1982     net.setInput(blobFromImage(inp, 1.0f, Size(227, 227), Scalar(), false));
1983     ASSERT_FALSE(net.empty());
1984     Mat out = net.forward();
1985
1986     normAssert(out, ref, "", default_l1,  default_lInf);
1987     expectNoFallbacksFromIE(net);
1988 }
1989
1990 TEST_P(Test_ONNX_nets, Squeezenet)
1991 {
1992     testONNXModels("squeezenet", pb);
1993 }
1994
1995 TEST_P(Test_ONNX_nets, Googlenet)
1996 {
1997 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
1998     // accuracy
1999     if (target == DNN_TARGET_MYRIAD)
2000         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2001 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
2002     // accuracy
2003     if (target == DNN_TARGET_MYRIAD)
2004         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2005 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2006     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
2007         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2008
2009     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
2010         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2011 #endif
2012
2013     const String model = _tf("models/googlenet.onnx", false);
2014
2015     Net net = readNetFromONNX(model);
2016     ASSERT_FALSE(net.empty());
2017
2018     net.setPreferableBackend(backend);
2019     net.setPreferableTarget(target);
2020
2021     std::vector<Mat> images;
2022     images.push_back( imread(_tf("../googlenet_0.png")) );
2023     images.push_back( imread(_tf("../googlenet_1.png")) );
2024     Mat inp = blobFromImages(images, 1.0f, Size(), Scalar(), false);
2025     Mat ref = blobFromNPY(_tf("../googlenet_prob.npy"));
2026     checkBackend(&inp, &ref);
2027
2028     net.setInput(inp);
2029     ASSERT_FALSE(net.empty());
2030     Mat out = net.forward();
2031
2032     normAssert(ref, out, "", default_l1,  default_lInf);
2033     expectNoFallbacksFromIE(net);
2034 }
2035
2036 TEST_P(Test_ONNX_nets, CaffeNet)
2037 {
2038 #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
2039     applyTestTag(CV_TEST_TAG_MEMORY_2GB);
2040 #else
2041     applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
2042 #endif
2043
2044 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019030000)
2045     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
2046         && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
2047         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2048 #endif
2049     testONNXModels("caffenet", pb);
2050 }
2051
2052 TEST_P(Test_ONNX_nets, RCNN_ILSVRC13)
2053 {
2054 #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
2055     applyTestTag(CV_TEST_TAG_MEMORY_2GB);
2056 #else
2057     applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
2058 #endif
2059
2060 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019030000)
2061     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
2062         && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
2063         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2064 #endif
2065     // Reference output values are in range [-4.992, -1.161]
2066     testONNXModels("rcnn_ilsvrc13", pb, 0.0046);
2067 }
2068
2069 TEST_P(Test_ONNX_nets, VGG16_bn)
2070 {
2071     applyTestTag(CV_TEST_TAG_MEMORY_6GB);  // > 2.3Gb
2072
2073     // output range: [-16; 27], after Softmax [0; 0.67]
2074     const double lInf = (target == DNN_TARGET_MYRIAD) ? 0.038 : default_lInf;
2075     testONNXModels("vgg16-bn", pb, default_l1, lInf, true);
2076 }
2077
2078 TEST_P(Test_ONNX_nets, ZFNet)
2079 {
2080     applyTestTag(CV_TEST_TAG_MEMORY_2GB);
2081     testONNXModels("zfnet512", pb);
2082 }
2083
2084 TEST_P(Test_ONNX_nets, ResNet18v1)
2085 {
2086     applyTestTag(CV_TEST_TAG_MEMORY_512MB);
2087
2088     // output range: [-16; 22], after Softmax [0, 0.51]
2089     testONNXModels("resnet18v1", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
2090 }
2091
2092 TEST_P(Test_ONNX_nets, ResNet50v1)
2093 {
2094     applyTestTag(CV_TEST_TAG_MEMORY_512MB);
2095
2096     // output range: [-67; 75], after Softmax [0, 0.98]
2097     testONNXModels("resnet50v1", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
2098 }
2099
2100 TEST_P(Test_ONNX_nets, ResNet50_Int8)
2101 {
2102     testONNXModels("resnet50_int8", pb, default_l1, default_lInf, true);
2103 }
2104
2105 TEST_P(Test_ONNX_nets, ResNet101_DUC_HDC)
2106 {
2107     applyTestTag(CV_TEST_TAG_VERYLONG);
2108
2109 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
2110     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
2111         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2112 #endif
2113 #if defined(INF_ENGINE_RELEASE)
2114     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
2115         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2116 #endif
2117     if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL)
2118     {
2119         if (backend == DNN_BACKEND_OPENCV)
2120             applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_OPENCL : CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
2121         throw SkipTestException("Test is disabled for OpenCL targets");
2122     }
2123     testONNXModels("resnet101_duc_hdc", pb);
2124 }
2125
2126 TEST_P(Test_ONNX_nets, TinyYolov2)
2127 {
2128     applyTestTag(CV_TEST_TAG_MEMORY_512MB);
2129
2130     if (cvtest::skipUnstableTests)
2131         throw SkipTestException("Skip unstable test");
2132 #if defined(INF_ENGINE_RELEASE)
2133     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
2134             && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
2135     )
2136         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2137
2138     if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
2139     )
2140         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
2141                      backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
2142                      CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
2143                      CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2144 #endif
2145
2146     // output range: [-11; 8]
2147     double l1 =  default_l1, lInf = default_lInf;
2148     if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
2149     {
2150         l1 = 0.02;
2151         lInf = 0.2;
2152     }
2153     else if (target == DNN_TARGET_CUDA_FP16)
2154     {
2155         l1 = 0.018;
2156         lInf = 0.16;
2157     }
2158 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2020040000)
2159     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
2160     {
2161         l1 = 0.018f; lInf = 0.16f;
2162     }
2163 #endif
2164
2165     testONNXModels("tiny_yolo2", pb, l1, lInf);
2166 }
2167
2168 TEST_P(Test_ONNX_nets, CNN_MNIST)
2169 {
2170     // output range: [-1952; 6574], after Softmax [0; 1]
2171     testONNXModels("cnn_mnist", pb, default_l1, default_lInf, true);
2172 }
2173
2174 TEST_P(Test_ONNX_nets, MobileNet_v2)
2175 {
2176     // output range: [-166; 317], after Softmax [0; 1]
2177     testONNXModels("mobilenetv2", pb, default_l1, default_lInf, true);
2178 }
2179
2180 TEST_P(Test_ONNX_nets, MobileNet_v2_FP16)
2181 {
2182     testONNXModels("mobilenetv2_fp16", npy, default_l1, default_lInf, true);
2183 }
2184
2185 TEST_P(Test_ONNX_nets, LResNet100E_IR)
2186 {
2187     applyTestTag(
2188 #if defined(OPENCV_32BIT_CONFIGURATION) && defined(HAVE_OPENCL)
2189         CV_TEST_TAG_MEMORY_2GB,
2190 #else
2191         (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
2192 #endif
2193         CV_TEST_TAG_DEBUG_LONG
2194     );
2195     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
2196     {
2197         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2198         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2199         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2200     }
2201     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
2202     {
2203         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2204         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2205         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2206     }
2207
2208     double l1 = default_l1, lInf = default_lInf;
2209     // output range: [-3; 3]
2210     if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
2211     {
2212         l1 = 0.009;
2213         lInf = 0.035;
2214     }
2215     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_CPU)
2216     {
2217         l1 = 4.6e-5;
2218         lInf = 1.9e-4;
2219     }
2220     else if (target == DNN_TARGET_CUDA_FP16)
2221     {
2222         l1 = 0.009;
2223         lInf = 0.04;
2224     }
2225     testONNXModels("LResNet100E_IR", pb, l1, lInf);
2226 }
2227
2228 TEST_P(Test_ONNX_nets, Emotion_ferplus)
2229 {
2230 #if defined(INF_ENGINE_RELEASE)
2231     if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
2232         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
2233                      backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
2234                      CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
2235                      CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
2236 #endif
2237
2238     double l1 = default_l1;
2239     double lInf = default_lInf;
2240
2241     // Output values are in range [-2.011, 2.111]
2242     if ((backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) || (target == DNN_TARGET_CUDA_FP16))
2243         l1 = 0.007;
2244     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL_FP16)
2245     {
2246         l1 = 0.021;
2247         lInf = 0.034;
2248     }
2249     else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL)) {
2250         l1 = 2.4e-4;
2251         lInf = 6e-4;
2252     }
2253 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
2254     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
2255     {
2256         l1 = 0.013f; lInf = 0.035f;
2257     }
2258 #endif
2259
2260     testONNXModels("emotion_ferplus", pb, l1, lInf);
2261 }
2262
2263 TEST_P(Test_ONNX_nets, Inception_v2)
2264 {
2265     testONNXModels("inception_v2", pb, default_l1, default_lInf, true);
2266 }
2267
2268 TEST_P(Test_ONNX_nets, DenseNet121)
2269 {
2270     applyTestTag(CV_TEST_TAG_MEMORY_512MB);
2271
2272     // output range: [-87; 138], after Softmax [0; 1]
2273     testONNXModels("densenet121", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
2274 }
2275
2276 TEST_P(Test_ONNX_nets, Inception_v1)
2277 {
2278 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2279     if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
2280          backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD)
2281         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
2282 #endif
2283     testONNXModels("inception_v1", pb);
2284 }
2285
2286 TEST_P(Test_ONNX_nets, Shufflenet)
2287 {
2288 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2289     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
2290     {
2291         if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2292         if (target == DNN_TARGET_OPENCL)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2293         if (target == DNN_TARGET_MYRIAD)      applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
2294     }
2295 #endif
2296     testONNXModels("shufflenet", pb);
2297 }
2298
2299 TEST_P(Test_ONNX_nets, Resnet34_kinetics)
2300 {
2301     applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG);
2302 #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
2303     // IE exception: Failed to allocate graph: MYRIAD device is not opened
2304     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
2305         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2306     // accuracy
2307     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
2308         applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
2309             CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
2310         );
2311 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
2312     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
2313     {
2314         // IE exception: Function contains several inputs and outputs with one friendly name!
2315         if (target == DNN_TARGET_MYRIAD)
2316             applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
2317     }
2318 #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2319     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
2320         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);  // Only CPU on DLIE backend is supported
2321     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
2322         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);  // Only CPU on DLIE backend is supported
2323 #endif
2324     if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
2325         throw SkipTestException("Only CPU is supported");  // FIXIT use tags
2326
2327     if (backend == DNN_BACKEND_VKCOM)
2328         applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
2329
2330     String onnxmodel = findDataFile("dnn/resnet-34_kinetics.onnx", false);
2331     Mat image0 = imread(findDataFile("dnn/dog416.png"));
2332     Mat image1 = imread(findDataFile("dnn/street.png"));
2333
2334     Mat ref0 = blobFromNPY(_tf("data/output_kinetics0.npy"));
2335     Mat ref1 = blobFromNPY(_tf("data/output_kinetics1.npy"));
2336
2337     std::vector<Mat> images_0(16, image0);
2338     std::vector<Mat> images_1(16, image1);
2339     Mat blob0 = blobFromImages(images_0, 1.0, Size(112, 112), Scalar(114.7748, 107.7354, 99.4750), true, true);
2340     Mat blob1 = blobFromImages(images_1, 1.0, Size(112, 112), Scalar(114.7748, 107.7354, 99.4750), true, true);
2341
2342     Net permute;
2343     LayerParams lp;
2344     int order[] = {1, 0, 2, 3};
2345     lp.set("order", DictValue::arrayInt<int*>(&order[0], 4));
2346     permute.addLayerToPrev("perm", "Permute", lp);
2347
2348     permute.setPreferableBackend(backend);
2349     permute.setPreferableTarget(target);
2350
2351     permute.setInput(blob0);
2352     Mat input0 = permute.forward().clone();
2353
2354     permute.setInput(blob1);
2355     Mat input1 = permute.forward().clone();
2356
2357     int dims[] = {1, 3, 16, 112, 112};
2358     input0 = input0.reshape(0, 5, &dims[0]);
2359     input1 = input1.reshape(0, 5, &dims[0]);
2360
2361     Net net = readNetFromONNX(onnxmodel);
2362     ASSERT_FALSE(net.empty());
2363     net.setPreferableBackend(backend);
2364     net.setPreferableTarget(target);
2365
2366     // output range [-5, 11]
2367     float l1 = 0.0013;
2368     float lInf = 0.009;
2369     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
2370     {
2371         l1 = 0.02;
2372         lInf = 0.07;
2373     }
2374     if (target == DNN_TARGET_CUDA_FP16)
2375     {
2376         l1 = 0.01;
2377         lInf = 0.06;
2378     }
2379
2380     checkBackend(&input0, &ref0);
2381     net.setInput(input0);
2382     Mat out = net.forward().clone();
2383     normAssert(ref0, out, "", l1, lInf);
2384
2385     checkBackend(&input1, &ref1);
2386     net.setInput(input1);
2387     out = net.forward().clone();
2388     normAssert(ref1, out, "", l1, lInf);
2389
2390     expectNoFallbacksFromIE(net);
2391 }
2392
2393 TEST_P(Test_ONNX_layers, CumSum)
2394 {
2395     testONNXModels("cumsum_1d_exclusive_1");
2396     testONNXModels("cumsum_1d_reverse");
2397     testONNXModels("cumsum_1d_exclusive_1_reverse");
2398     testONNXModels("cumsum_2d_dim_1");
2399     testONNXModels("cumsum_3d_dim_2");
2400 }
2401
2402 // This test is mainly to test:
2403 //  1. identity node with constant input
2404 //  2. limited support to range operator (all inputs are constant)
2405 //  3. parseExpand with multiple broadcast axes
2406 //  4. 1D mat dimension issue with the output of range operator
2407 TEST_P(Test_ONNX_layers, YOLOv7)
2408 {
2409     std::string weightPath = _tf("models/yolov7_not_simplified.onnx", false);
2410     std::string imgPath = _tf("../dog_orig_size.png");
2411
2412     Size targetSize{640, 640};
2413     float conf_threshold = 0.3;
2414     float iou_threshold = 0.5;
2415
2416     // Reference, which is collected with input size of 640x640
2417     std::vector<int> refClassIds{1, 16, 7};
2418     std::vector<float> refScores{0.9614331f, 0.9589417f, 0.8679074f};
2419     // [x1, y1, x2, y2] x 3
2420     std::vector<Rect2d> refBoxes{Rect2d(105.973236f, 150.16716f,  472.59012f, 466.48834f),
2421                                   Rect2d(109.97953f,  246.17862f, 259.83676f, 600.76624f),
2422                                   Rect2d(385.96185f, 83.02809f,  576.07355f,  189.82793f)};
2423
2424     Mat img = imread(imgPath);
2425     Mat inp = blobFromImage(img, 1/255.0, targetSize, Scalar(0, 0, 0), true, false);
2426
2427     Net net = readNet(weightPath);
2428
2429     net.setInput(inp);
2430     std::vector<Mat> outs;
2431     net.forward(outs, net.getUnconnectedOutLayersNames());
2432
2433     Mat preds = outs[3].reshape(1, outs[3].size[1]); // [1, 25200, 85]
2434
2435     // Retrieve
2436     std::vector<int> classIds;
2437     std::vector<float> confidences;
2438     std::vector<Rect2d> boxes;
2439     // each row is [cx, cy, w, h, conf_obj, conf_class1, ..., conf_class80]
2440     for (int i = 0; i < preds.rows; ++i)
2441     {
2442         // filter out non objects
2443         float obj_conf = preds.row(i).at<float>(4);
2444         if (obj_conf < conf_threshold)
2445             continue;
2446
2447         // get class id and conf
2448         Mat scores = preds.row(i).colRange(5, preds.cols);
2449         double conf;
2450         Point maxLoc;
2451         minMaxLoc(scores, 0, &conf, 0, &maxLoc);
2452         conf *= obj_conf;
2453         if (conf < conf_threshold)
2454             continue;
2455
2456         // get bbox coords
2457         float* det = preds.ptr<float>(i);
2458         double cx = det[0];
2459         double cy = det[1];
2460         double w = det[2];
2461         double h = det[3];
2462         // [x1, y1, x2, y2]
2463         boxes.push_back(Rect2d(cx - 0.5 * w, cy - 0.5 * h,
2464                                 cx + 0.5 * w, cy + 0.5 * h));
2465         classIds.push_back(maxLoc.x);
2466         confidences.push_back(conf);
2467     }
2468
2469     // NMS
2470     std::vector<int> keep_idx;
2471     NMSBoxes(boxes, confidences, conf_threshold, iou_threshold, keep_idx);
2472
2473     std::vector<int> keep_classIds;
2474     std::vector<float> keep_confidences;
2475     std::vector<Rect2d> keep_boxes;
2476     for (auto i : keep_idx)
2477     {
2478         keep_classIds.push_back(classIds[i]);
2479         keep_confidences.push_back(confidences[i]);
2480         keep_boxes.push_back(boxes[i]);
2481     }
2482
2483     normAssertDetections(refClassIds, refScores, refBoxes, keep_classIds, keep_confidences, keep_boxes);
2484 }
2485
2486 INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets());
2487
2488 }} // namespace