test_onnx_importer.cpp 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  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. // Copyright (C) 2018-2019, Intel Corporation, all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "test_precomp.hpp"
  7. #include "npy_blob.hpp"
  8. #include <opencv2/dnn/shape_utils.hpp>
  9. namespace opencv_test { namespace {
  10. template<typename TString>
  11. static std::string _tf(TString filename, bool required = true)
  12. {
  13. return findDataFile(std::string("dnn/onnx/") + filename, required);
  14. }
  15. class Test_ONNX_layers : public DNNTestLayer
  16. {
  17. public:
  18. bool required;
  19. Test_ONNX_layers() : required(true) { }
  20. enum Extension
  21. {
  22. npy,
  23. pb
  24. };
  25. void testONNXModels(const String& basename, const Extension ext = npy,
  26. const double l1 = 0, const float lInf = 0, const bool useSoftmax = false,
  27. bool checkNoFallbacks = true, int numInps = 1)
  28. {
  29. String onnxmodel = _tf("models/" + basename + ".onnx", required);
  30. std::vector<Mat> inps(numInps);
  31. Mat ref;
  32. if (ext == npy) {
  33. for (int i = 0; i < numInps; ++i)
  34. inps[i] = blobFromNPY(_tf("data/input_" + basename + (numInps > 1 ? format("_%d", i) : "") + ".npy"));
  35. ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
  36. }
  37. else if (ext == pb) {
  38. for (int i = 0; i < numInps; ++i)
  39. inps[i] = readTensorFromONNX(_tf("data/input_" + basename + (numInps > 1 ? format("_%d", i) : "") + ".pb"));
  40. ref = readTensorFromONNX(_tf("data/output_" + basename + ".pb"));
  41. }
  42. else
  43. CV_Error(Error::StsUnsupportedFormat, "Unsupported extension");
  44. checkBackend(&inps[0], &ref);
  45. Net net = readNetFromONNX(onnxmodel);
  46. ASSERT_FALSE(net.empty());
  47. net.setPreferableBackend(backend);
  48. net.setPreferableTarget(target);
  49. std::vector<String> inputNames;
  50. for (int i = 0; i < numInps; ++i)
  51. inputNames.push_back(format("%d", i));
  52. net.setInputsNames(inputNames);
  53. for (int i = 0; i < numInps; ++i)
  54. net.setInput(inps[i], inputNames[i]);
  55. Mat out = net.forward("");
  56. if (useSoftmax)
  57. {
  58. LayerParams lp;
  59. Net netSoftmax;
  60. netSoftmax.addLayerToPrev("softmaxLayer", "Softmax", lp);
  61. netSoftmax.setPreferableBackend(DNN_BACKEND_OPENCV);
  62. netSoftmax.setInput(out);
  63. out = netSoftmax.forward();
  64. netSoftmax.setInput(ref);
  65. ref = netSoftmax.forward();
  66. }
  67. normAssert(ref, out, "", l1 ? l1 : default_l1, lInf ? lInf : default_lInf);
  68. if (checkNoFallbacks)
  69. expectNoFallbacksFromIE(net);
  70. }
  71. };
  72. TEST_P(Test_ONNX_layers, InstanceNorm)
  73. {
  74. if(backend == DNN_BACKEND_CUDA)
  75. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); /* MVN is not supported */
  76. if (target == DNN_TARGET_MYRIAD)
  77. testONNXModels("instancenorm", npy, 0, 0, false, false);
  78. else
  79. testONNXModels("instancenorm", npy);
  80. }
  81. TEST_P(Test_ONNX_layers, MaxPooling)
  82. {
  83. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  84. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  85. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  86. #endif
  87. testONNXModels("maxpooling", npy, 0, 0, false, false);
  88. }
  89. TEST_P(Test_ONNX_layers, MaxPooling_2)
  90. {
  91. testONNXModels("two_maxpooling", npy, 0, 0, false, false);
  92. }
  93. TEST_P(Test_ONNX_layers, Convolution)
  94. {
  95. testONNXModels("convolution");
  96. testONNXModels("conv_asymmetric_pads");
  97. }
  98. TEST_P(Test_ONNX_layers, Convolution_variable_weight)
  99. {
  100. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
  101. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD)
  102. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  103. if (backend == DNN_BACKEND_CUDA)
  104. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
  105. if (backend == DNN_BACKEND_VKCOM)
  106. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
  107. String basename = "conv_variable_w";
  108. Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
  109. ASSERT_FALSE(net.empty());
  110. net.setPreferableBackend(backend);
  111. net.setPreferableTarget(target);
  112. for (int i = 0; i < 2; i++)
  113. {
  114. Mat input = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_0.npy"));
  115. Mat weights = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_1.npy"));
  116. Mat ref = blobFromNPY(_tf("data/output_" + basename + format("_%d", i) + ".npy"));
  117. net.setInput(input, "0");
  118. net.setInput(weights, "1");
  119. Mat out = net.forward();
  120. normAssert(ref, out, "", default_l1, default_lInf);
  121. }
  122. }
  123. TEST_P(Test_ONNX_layers, Convolution_variable_weight_bias)
  124. {
  125. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
  126. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD)
  127. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  128. if (backend == DNN_BACKEND_CUDA)
  129. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
  130. if (backend == DNN_BACKEND_VKCOM)
  131. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
  132. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU &&
  133. getInferenceEngineCPUType() == CV_DNN_INFERENCE_ENGINE_CPU_TYPE_ARM_COMPUTE)
  134. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_ARM_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  135. String basename = "conv_variable_wb";
  136. Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
  137. ASSERT_FALSE(net.empty());
  138. net.setPreferableBackend(backend);
  139. net.setPreferableTarget(target);
  140. for (int i = 0; i < 2; i++)
  141. {
  142. Mat input = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_0.npy"));
  143. Mat weights = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_1.npy"));
  144. Mat bias = blobFromNPY(_tf("data/input_" + basename + format("_%d", i) + "_2.npy"));
  145. Mat ref = blobFromNPY(_tf("data/output_" + basename + format("_%d", i) + ".npy"));
  146. net.setInput(input, "0");
  147. net.setInput(weights, "1");
  148. net.setInput(bias, "bias");
  149. Mat out = net.forward();
  150. normAssert(ref, out, "", default_l1, default_lInf);
  151. }
  152. }
  153. TEST_P(Test_ONNX_layers, Gather)
  154. {
  155. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  156. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  157. testONNXModels("gather");
  158. // GPU plugin unsupported slice for constant
  159. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  160. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  161. testONNXModels("gather_scalar", npy, 0, 0, false, false);
  162. }
  163. TEST_P(Test_ONNX_layers, Convolution3D)
  164. {
  165. testONNXModels("conv3d");
  166. }
  167. TEST_P(Test_ONNX_layers, Convolution3D_bias)
  168. {
  169. testONNXModels("conv3d_bias");
  170. }
  171. TEST_P(Test_ONNX_layers, Two_convolution)
  172. {
  173. #if defined(INF_ENGINE_RELEASE)
  174. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  175. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
  176. )
  177. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  178. #endif
  179. // Reference output values are in range [-0.855, 0.611]
  180. testONNXModels("two_convolution");
  181. }
  182. TEST_P(Test_ONNX_layers, Deconvolution)
  183. {
  184. testONNXModels("deconvolution", npy, 0, 0, false, false);
  185. testONNXModels("two_deconvolution", npy, 0, 0, false, false);
  186. testONNXModels("deconvolution_group", npy, 0, 0, false, false);
  187. testONNXModels("deconvolution_output_shape", npy, 0, 0, false, false);
  188. if (target != DNN_TARGET_CUDA_FP16) // bug
  189. testONNXModels("deconv_adjpad_2d", npy, 0, 0, false, false);
  190. }
  191. TEST_P(Test_ONNX_layers, Deconvolution3D)
  192. {
  193. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  194. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  195. {
  196. // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
  197. // [ 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)
  198. if (target == DNN_TARGET_MYRIAD)
  199. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  200. }
  201. #endif
  202. if (backend == DNN_BACKEND_OPENCV)
  203. throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags
  204. if (backend == DNN_BACKEND_VKCOM)
  205. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  206. testONNXModels("deconv3d");
  207. }
  208. TEST_P(Test_ONNX_layers, Deconvolution3D_bias)
  209. {
  210. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  211. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  212. {
  213. // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
  214. // [ 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)
  215. if (target == DNN_TARGET_MYRIAD)
  216. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  217. }
  218. #endif
  219. if (backend == DNN_BACKEND_OPENCV)
  220. throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags
  221. if (backend == DNN_BACKEND_VKCOM)
  222. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  223. testONNXModels("deconv3d_bias");
  224. }
  225. TEST_P(Test_ONNX_layers, Deconvolution3D_pad)
  226. {
  227. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  228. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  229. {
  230. // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
  231. // [ 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)
  232. if (target == DNN_TARGET_MYRIAD)
  233. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  234. }
  235. #endif
  236. if (backend == DNN_BACKEND_OPENCV)
  237. throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags
  238. if (backend == DNN_BACKEND_VKCOM)
  239. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  240. testONNXModels("deconv3d_pad");
  241. }
  242. TEST_P(Test_ONNX_layers, Deconvolution3D_adjpad)
  243. {
  244. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  245. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  246. {
  247. // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2":
  248. // [ 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)
  249. if (target == DNN_TARGET_MYRIAD)
  250. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  251. }
  252. #endif
  253. if (backend == DNN_BACKEND_OPENCV)
  254. throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags
  255. if (backend == DNN_BACKEND_VKCOM)
  256. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  257. testONNXModels("deconv3d_adjpad");
  258. }
  259. TEST_P(Test_ONNX_layers, Dropout)
  260. {
  261. testONNXModels("dropout");
  262. }
  263. TEST_P(Test_ONNX_layers, Linear)
  264. {
  265. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  266. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  267. testONNXModels("linear");
  268. }
  269. TEST_P(Test_ONNX_layers, ReLU)
  270. {
  271. testONNXModels("ReLU");
  272. }
  273. TEST_P(Test_ONNX_layers, PReLU)
  274. {
  275. testONNXModels("PReLU_slope");
  276. }
  277. TEST_P(Test_ONNX_layers, Clip)
  278. {
  279. testONNXModels("clip", npy);
  280. }
  281. TEST_P(Test_ONNX_layers, Shape)
  282. {
  283. testONNXModels("shape_of_constant");
  284. }
  285. TEST_P(Test_ONNX_layers, ReduceMean)
  286. {
  287. testONNXModels("reduce_mean");
  288. testONNXModels("reduce_mean_axis1");
  289. testONNXModels("reduce_mean_axis2");
  290. }
  291. TEST_P(Test_ONNX_layers, ReduceSum)
  292. {
  293. testONNXModels("reduce_sum");
  294. }
  295. TEST_P(Test_ONNX_layers, ReduceMax)
  296. {
  297. testONNXModels("reduce_max");
  298. testONNXModels("reduce_max_axis_0");
  299. testONNXModels("reduce_max_axis_1");
  300. }
  301. TEST_P(Test_ONNX_layers, Min)
  302. {
  303. testONNXModels("min", npy, 0, 0, false, true, 2);
  304. }
  305. TEST_P(Test_ONNX_layers, ArgLayer)
  306. {
  307. if (backend != DNN_BACKEND_OPENCV || target != DNN_TARGET_CPU)
  308. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  309. testONNXModels("argmax");
  310. testONNXModels("argmin");
  311. }
  312. TEST_P(Test_ONNX_layers, Scale)
  313. {
  314. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  315. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  316. testONNXModels("scale");
  317. testONNXModels("scale_broadcast", npy, 0, 0, false, true, 3);
  318. testONNXModels("scale_broadcast_mid", npy, 0, 0, false, true, 2);
  319. }
  320. TEST_P(Test_ONNX_layers, ReduceMean3D)
  321. {
  322. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  323. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  324. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  325. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  326. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  327. #endif
  328. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  329. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  330. if (backend == DNN_BACKEND_VKCOM)
  331. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  332. testONNXModels("reduce_mean3d");
  333. }
  334. TEST_P(Test_ONNX_layers, MaxPooling_Sigmoid)
  335. {
  336. testONNXModels("maxpooling_sigmoid");
  337. }
  338. TEST_P(Test_ONNX_layers, Cast)
  339. {
  340. testONNXModels("cast");
  341. }
  342. TEST_P(Test_ONNX_layers, Power)
  343. {
  344. testONNXModels("pow2", npy, 0, 0, false, false);
  345. }
  346. TEST_P(Test_ONNX_layers, Exp)
  347. {
  348. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  349. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  350. testONNXModels("exp");
  351. }
  352. TEST_P(Test_ONNX_layers, Elementwise_Ceil)
  353. {
  354. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  355. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  356. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  357. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  358. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  359. #endif
  360. testONNXModels("ceil");
  361. }
  362. TEST_P(Test_ONNX_layers, Elementwise_Floor)
  363. {
  364. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  365. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  366. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  367. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  368. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  369. #endif
  370. testONNXModels("floor");
  371. }
  372. TEST_P(Test_ONNX_layers, Elementwise_Log)
  373. {
  374. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  375. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  376. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  377. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  378. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  379. #endif
  380. testONNXModels("log");
  381. }
  382. TEST_P(Test_ONNX_layers, Elementwise_Round)
  383. {
  384. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  385. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  386. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  387. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  388. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  389. #endif
  390. testONNXModels("round");
  391. }
  392. TEST_P(Test_ONNX_layers, Elementwise_Sqrt)
  393. {
  394. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  395. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  396. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  397. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  398. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  399. testONNXModels("sqrt");
  400. #endif
  401. }
  402. TEST_P(Test_ONNX_layers, Elementwise_not)
  403. {
  404. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  405. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  406. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  407. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  408. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  409. #endif
  410. testONNXModels("not");
  411. }
  412. TEST_P(Test_ONNX_layers, Compare_EQ)
  413. {
  414. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  415. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  416. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  417. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  418. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  419. #endif
  420. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  421. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  422. {
  423. // IE exception: Function contains several inputs and outputs with one friendly name!
  424. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  425. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  426. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  427. );
  428. // IE exception: Function contains several inputs and outputs with one friendly name!
  429. if (target == DNN_TARGET_MYRIAD)
  430. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  431. }
  432. #endif
  433. testONNXModels("equal");
  434. }
  435. TEST_P(Test_ONNX_layers, Compare_GT)
  436. {
  437. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  438. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  439. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  440. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  441. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  442. #endif
  443. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  444. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  445. {
  446. // IE exception: Function contains several inputs and outputs with one friendly name!
  447. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  448. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  449. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  450. );
  451. // IE exception: Function contains several inputs and outputs with one friendly name!
  452. if (target == DNN_TARGET_MYRIAD)
  453. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  454. }
  455. #endif
  456. testONNXModels("greater");
  457. }
  458. TEST_P(Test_ONNX_layers, Compare_LT)
  459. {
  460. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  461. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  462. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  463. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  464. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  465. #endif
  466. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  467. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  468. {
  469. // IE exception: Function contains several inputs and outputs with one friendly name!
  470. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  471. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  472. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  473. );
  474. // IE exception: Function contains several inputs and outputs with one friendly name!
  475. if (target == DNN_TARGET_MYRIAD)
  476. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  477. }
  478. #endif
  479. testONNXModels("less");
  480. }
  481. TEST_P(Test_ONNX_layers, CompareSameDims_EQ)
  482. {
  483. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  484. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  485. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  486. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  487. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  488. #endif
  489. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  490. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  491. {
  492. // IE exception: Function contains several inputs and outputs with one friendly name!
  493. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  494. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  495. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  496. );
  497. // IE exception: Function contains several inputs and outputs with one friendly name!
  498. if (target == DNN_TARGET_MYRIAD)
  499. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  500. }
  501. #endif
  502. testONNXModels("equal_same_dims", npy, 0, 0, false, true, 2);
  503. }
  504. TEST_P(Test_ONNX_layers, CompareSameDims_GT)
  505. {
  506. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  507. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  508. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  509. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  510. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  511. #endif
  512. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  513. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  514. {
  515. // IE exception: Function contains several inputs and outputs with one friendly name!
  516. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  517. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  518. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  519. );
  520. // IE exception: Function contains several inputs and outputs with one friendly name!
  521. if (target == DNN_TARGET_MYRIAD)
  522. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  523. }
  524. #endif
  525. testONNXModels("greater_same_dims", npy, 0, 0, false, true, 2);
  526. }
  527. TEST_P(Test_ONNX_layers, CompareSameDims_LT)
  528. {
  529. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  530. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  531. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  532. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  533. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  534. #endif
  535. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  536. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  537. {
  538. // IE exception: Function contains several inputs and outputs with one friendly name!
  539. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  540. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  541. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  542. );
  543. // IE exception: Function contains several inputs and outputs with one friendly name!
  544. if (target == DNN_TARGET_MYRIAD)
  545. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  546. }
  547. #endif
  548. testONNXModels("less_same_dims", npy, 0, 0, false, true, 2);
  549. }
  550. TEST_P(Test_ONNX_layers, Concatenation)
  551. {
  552. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  553. {
  554. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  555. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  556. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  557. }
  558. testONNXModels("concatenation");
  559. testONNXModels("concat_const_blobs");
  560. }
  561. TEST_P(Test_ONNX_layers, Eltwise3D)
  562. {
  563. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  564. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  565. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  566. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  567. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  568. #endif
  569. testONNXModels("eltwise3d");
  570. }
  571. TEST_P(Test_ONNX_layers, AveragePooling)
  572. {
  573. testONNXModels("average_pooling");
  574. }
  575. TEST_P(Test_ONNX_layers, MaxPooling3D)
  576. {
  577. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  578. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  579. {
  580. // accuracy
  581. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  582. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  583. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  584. );
  585. // IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired()
  586. if (target == DNN_TARGET_MYRIAD)
  587. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  588. }
  589. #endif
  590. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  591. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  592. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  593. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  594. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  595. #endif
  596. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  597. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  598. if (backend == DNN_BACKEND_VKCOM)
  599. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  600. testONNXModels("max_pool3d", npy, 0, 0, false, false);
  601. }
  602. TEST_P(Test_ONNX_layers, AvePooling3D)
  603. {
  604. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  605. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  606. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  607. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  608. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  609. #endif
  610. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  611. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  612. if (backend == DNN_BACKEND_VKCOM)
  613. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  614. testONNXModels("ave_pool3d");
  615. }
  616. TEST_P(Test_ONNX_layers, PoolConv3D)
  617. {
  618. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  619. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  620. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  621. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  622. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  623. #endif
  624. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  625. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  626. if (backend == DNN_BACKEND_VKCOM)
  627. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  628. testONNXModels("pool_conv_3d");
  629. }
  630. TEST_P(Test_ONNX_layers, BatchNormalization)
  631. {
  632. testONNXModels("batch_norm");
  633. }
  634. TEST_P(Test_ONNX_layers, BatchNormalization3D)
  635. {
  636. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  637. {
  638. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  639. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  640. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  641. }
  642. testONNXModels("batch_norm_3d");
  643. }
  644. TEST_P(Test_ONNX_layers, BatchNormalizationUnfused)
  645. {
  646. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  647. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  648. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  649. #endif
  650. testONNXModels("frozenBatchNorm2d");
  651. }
  652. TEST_P(Test_ONNX_layers, BatchNormalizationSubgraph)
  653. {
  654. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  655. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  656. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  657. #endif
  658. testONNXModels("batch_norm_subgraph");
  659. }
  660. TEST_P(Test_ONNX_layers, NormalizeFusionSubgraph)
  661. {
  662. testONNXModels("normalize_fusion");
  663. }
  664. TEST_P(Test_ONNX_layers, Transpose)
  665. {
  666. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  667. {
  668. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  669. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  670. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  671. }
  672. testONNXModels("transpose");
  673. }
  674. TEST_P(Test_ONNX_layers, Multiplication)
  675. {
  676. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  677. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  678. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  679. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  680. testONNXModels("mul");
  681. }
  682. TEST_P(Test_ONNX_layers, MatMul)
  683. {
  684. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  685. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  686. testONNXModels("matmul_2d");
  687. testONNXModels("matmul_3d");
  688. testONNXModels("matmul_4d");
  689. }
  690. TEST_P(Test_ONNX_layers, MatMulAdd)
  691. {
  692. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  693. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  694. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  695. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  696. testONNXModels("matmul_add");
  697. }
  698. TEST_P(Test_ONNX_layers, Expand)
  699. {
  700. testONNXModels("expand");
  701. testONNXModels("expand_identity");
  702. testONNXModels("expand_batch");
  703. testONNXModels("expand_channels");
  704. testONNXModels("expand_neg_batch");
  705. }
  706. TEST_P(Test_ONNX_layers, ExpandHW)
  707. {
  708. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  709. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  710. testONNXModels("expand_hw");
  711. }
  712. TEST_P(Test_ONNX_layers, Constant)
  713. {
  714. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
  715. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  716. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  717. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  718. #endif
  719. testONNXModels("constant");
  720. }
  721. TEST_P(Test_ONNX_layers, Padding)
  722. {
  723. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000)
  724. testONNXModels("padding", npy, 0, 0, false, false);
  725. #else
  726. testONNXModels("padding");
  727. #endif
  728. }
  729. TEST_P(Test_ONNX_layers, Resize)
  730. {
  731. testONNXModels("resize_nearest");
  732. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  733. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  734. testONNXModels("resize_bilinear");
  735. }
  736. TEST_P(Test_ONNX_layers, ResizeUnfused)
  737. {
  738. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  739. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  740. testONNXModels("upsample_unfused_torch1.2");
  741. testONNXModels("upsample_unfused_opset9_torch1.4");
  742. testONNXModels("resize_nearest_unfused_opset11_torch1.4");
  743. testONNXModels("resize_nearest_unfused_opset11_torch1.3");
  744. testONNXModels("resize_bilinear_unfused_opset11_torch1.4");
  745. }
  746. TEST_P(Test_ONNX_layers, ResizeUnfusedTwoInputs)
  747. {
  748. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  749. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  750. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  751. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  752. testONNXModels("upsample_unfused_two_inputs_opset9_torch1.4", npy, 0, 0, false, true, 2);
  753. testONNXModels("upsample_unfused_two_inputs_opset11_torch1.4", npy, 0, 0, false, true, 2);
  754. }
  755. TEST_P(Test_ONNX_layers, MultyInputs)
  756. {
  757. testONNXModels("multy_inputs", npy, 0, 0, false, true, 2);
  758. }
  759. TEST_P(Test_ONNX_layers, Broadcast)
  760. {
  761. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  762. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  763. testONNXModels("channel_broadcast", npy, 0, 0, false, true, 2);
  764. }
  765. TEST_P(Test_ONNX_layers, DynamicResize)
  766. {
  767. testONNXModels("dynamic_resize_9", npy, 0, 0, false, true, 2);
  768. testONNXModels("dynamic_resize_10", npy, 0, 0, false, true, 2);
  769. testONNXModels("dynamic_resize_11", npy, 0, 0, false, true, 2);
  770. testONNXModels("dynamic_resize_13", npy, 0, 0, false, true, 2);
  771. testONNXModels("dynamic_resize_scale_9", npy, 0, 0, false, true, 2);
  772. testONNXModels("dynamic_resize_scale_10", npy, 0, 0, false, true, 2);
  773. testONNXModels("dynamic_resize_scale_11", npy, 0, 0, false, true, 2);
  774. testONNXModels("dynamic_resize_scale_13", npy, 0, 0, false, true, 2);
  775. testONNXModels("resize_size_opset11");
  776. testONNXModels("resize_size_opset13");
  777. }
  778. TEST_P(Test_ONNX_layers, Resize_HumanSeg)
  779. {
  780. testONNXModels("resize_humanseg");
  781. }
  782. TEST_P(Test_ONNX_layers, Div)
  783. {
  784. const String model = _tf("models/div.onnx");
  785. Net net = readNetFromONNX(model);
  786. ASSERT_FALSE(net.empty());
  787. net.setPreferableBackend(backend);
  788. net.setPreferableTarget(target);
  789. // Reference output values range is -68.80928, 2.991873. So to avoid computational
  790. // difference for FP16 we'll perform reversed division (just swap inputs).
  791. Mat inp1 = blobFromNPY(_tf("data/input_div_1.npy"));
  792. Mat inp2 = blobFromNPY(_tf("data/input_div_0.npy"));
  793. Mat ref = blobFromNPY(_tf("data/output_div.npy"));
  794. cv::divide(1.0, ref, ref);
  795. checkBackend(&inp1, &ref);
  796. net.setInput(inp1, "0");
  797. net.setInput(inp2, "1");
  798. Mat out = net.forward();
  799. normAssert(ref, out, "", default_l1, default_lInf);
  800. expectNoFallbacksFromIE(net);
  801. expectNoFallbacksFromCUDA(net);
  802. }
  803. TEST_P(Test_ONNX_layers, DynamicReshape)
  804. {
  805. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  806. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  807. testONNXModels("dynamic_reshape");
  808. testONNXModels("dynamic_reshape_opset_11");
  809. testONNXModels("flatten_by_prod");
  810. testONNXModels("flatten_const");
  811. }
  812. TEST_P(Test_ONNX_layers, Reshape)
  813. {
  814. testONNXModels("unsqueeze");
  815. testONNXModels("unsqueeze_opset_13");
  816. }
  817. TEST_P(Test_ONNX_layers, Squeeze)
  818. {
  819. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  820. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  821. testONNXModels("squeeze");
  822. }
  823. TEST_P(Test_ONNX_layers, ReduceL2)
  824. {
  825. testONNXModels("reduceL2");
  826. testONNXModels("reduceL2_subgraph");
  827. testONNXModels("reduceL2_subgraph_2");
  828. testONNXModels("reduceL2_subgraph2_2");
  829. }
  830. TEST_P(Test_ONNX_layers, Split)
  831. {
  832. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  833. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  834. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  835. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  836. testONNXModels("split_1");
  837. testONNXModels("split_2");
  838. testONNXModels("split_3");
  839. testONNXModels("split_4");
  840. testONNXModels("split_sizes");
  841. testONNXModels("split_neg_axis");
  842. }
  843. TEST_P(Test_ONNX_layers, Slice)
  844. {
  845. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000)
  846. testONNXModels("slice", npy, 0, 0, false, false);
  847. #else
  848. testONNXModels("slice");
  849. testONNXModels("slice_neg_starts");
  850. testONNXModels("slice_opset_11");
  851. #endif
  852. }
  853. TEST_P(Test_ONNX_layers, Slice_Steps_2DInput)
  854. {
  855. testONNXModels("slice_opset_11_steps_2d");
  856. }
  857. TEST_P(Test_ONNX_layers, Slice_Steps_3DInput)
  858. {
  859. testONNXModels("slice_opset_11_steps_3d");
  860. }
  861. TEST_P(Test_ONNX_layers, Slice_Steps_4DInput)
  862. {
  863. testONNXModels("slice_opset_11_steps_4d");
  864. }
  865. TEST_P(Test_ONNX_layers, Slice_Steps_5DInput)
  866. {
  867. testONNXModels("slice_opset_11_steps_5d");
  868. }
  869. TEST_P(Test_ONNX_layers, Softmax)
  870. {
  871. testONNXModels("softmax");
  872. testONNXModels("log_softmax", npy, 0, 0, false, false);
  873. testONNXModels("softmax_unfused");
  874. }
  875. TEST_P(Test_ONNX_layers, Split_EltwiseMax)
  876. {
  877. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  878. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  879. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  880. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  881. testONNXModels("split_max");
  882. }
  883. TEST_P(Test_ONNX_layers, LSTM_Activations)
  884. {
  885. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  886. // 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
  887. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  888. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  889. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  890. );
  891. #endif
  892. testONNXModels("lstm_cntk_tanh", pb, 0, 0, false, false);
  893. }
  894. TEST_P(Test_ONNX_layers, LSTM)
  895. {
  896. testONNXModels("lstm", npy, 0, 0, false, false);
  897. }
  898. TEST_P(Test_ONNX_layers, LSTM_bidirectional)
  899. {
  900. testONNXModels("lstm_bidirectional", npy, 0, 0, false, false);
  901. }
  902. TEST_P(Test_ONNX_layers, LSTM_hidden)
  903. {
  904. testONNXModels("hidden_lstm", npy, 0, 0, false, false);
  905. }
  906. TEST_P(Test_ONNX_layers, LSTM_hidden_bidirectional)
  907. {
  908. testONNXModels("hidden_lstm_bi", npy, 0, 0, false, false);
  909. }
  910. TEST_P(Test_ONNX_layers, GRU)
  911. {
  912. testONNXModels("gru", npy, 0, 0, false, false);
  913. }
  914. TEST_P(Test_ONNX_layers, GRU_bidirectional)
  915. {
  916. testONNXModels("gru_bi", npy, 0, 0, false, false);
  917. }
  918. TEST_P(Test_ONNX_layers, Pad2d_Unfused)
  919. {
  920. testONNXModels("ReflectionPad2d");
  921. testONNXModels("ZeroPad2d");
  922. }
  923. TEST_P(Test_ONNX_layers, LinearWithConstant)
  924. {
  925. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  926. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  927. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000)
  928. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE);
  929. #endif
  930. if (backend == DNN_BACKEND_CUDA)
  931. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA);
  932. testONNXModels("lin_with_constant");
  933. }
  934. TEST_P(Test_ONNX_layers, MatmulWithTwoInputs)
  935. {
  936. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  937. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  938. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2020040000)
  939. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE);
  940. #endif
  941. testONNXModels("matmul_with_two_inputs");
  942. }
  943. TEST_P(Test_ONNX_layers, ResizeOpset11_Torch1_6)
  944. {
  945. testONNXModels("resize_opset11_torch1.6");
  946. }
  947. TEST_P(Test_ONNX_layers, Mish)
  948. {
  949. testONNXModels("mish");
  950. }
  951. TEST_P(Test_ONNX_layers, CalculatePads)
  952. {
  953. testONNXModels("calc_pads");
  954. }
  955. TEST_P(Test_ONNX_layers, Conv1d)
  956. {
  957. testONNXModels("conv1d");
  958. }
  959. TEST_P(Test_ONNX_layers, Conv1d_bias)
  960. {
  961. testONNXModels("conv1d_bias");
  962. }
  963. TEST_P(Test_ONNX_layers, Conv1d_variable_weight)
  964. {
  965. if (backend == DNN_BACKEND_CUDA)
  966. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
  967. if (backend == DNN_BACKEND_VKCOM)
  968. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
  969. String basename = "conv1d_variable_w";
  970. Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
  971. ASSERT_FALSE(net.empty());
  972. net.setPreferableBackend(backend);
  973. net.setPreferableTarget(target);
  974. Mat input = blobFromNPY(_tf("data/input_" + basename + "_0.npy"));
  975. Mat weights = blobFromNPY(_tf("data/input_" + basename + "_1.npy"));
  976. Mat ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
  977. net.setInput(input, "0");
  978. net.setInput(weights, "1");
  979. Mat out = net.forward();
  980. normAssert(ref, out, "", default_l1, default_lInf);
  981. }
  982. TEST_P(Test_ONNX_layers, Conv1d_variable_weight_bias)
  983. {
  984. if (backend == DNN_BACKEND_CUDA)
  985. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported
  986. if (backend == DNN_BACKEND_VKCOM)
  987. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); // not supported
  988. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  989. {
  990. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  991. if (target == DNN_TARGET_CPU && getInferenceEngineCPUType() == CV_DNN_INFERENCE_ENGINE_CPU_TYPE_ARM_COMPUTE)
  992. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_ARM_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  993. }
  994. String basename = "conv1d_variable_wb";
  995. Net net = readNetFromONNX(_tf("models/" + basename + ".onnx"));
  996. ASSERT_FALSE(net.empty());
  997. net.setPreferableBackend(backend);
  998. net.setPreferableTarget(target);
  999. Mat input = blobFromNPY(_tf("data/input_" + basename + "_0.npy"));
  1000. Mat weights = blobFromNPY(_tf("data/input_" + basename + "_1.npy"));
  1001. Mat bias = blobFromNPY(_tf("data/input_" + basename + "_2.npy"));
  1002. Mat ref = blobFromNPY(_tf("data/output_" + basename + ".npy"));
  1003. net.setInput(input, "0");
  1004. net.setInput(weights, "1");
  1005. net.setInput(bias, "bias");
  1006. Mat out = net.forward();
  1007. normAssert(ref, out, "", default_l1, default_lInf);
  1008. }
  1009. TEST_P(Test_ONNX_layers, GatherMultiOutput)
  1010. {
  1011. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1012. // IE Exception: Ngraph operation Reshape with name 6 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  1013. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  1014. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1015. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1016. );
  1017. #endif
  1018. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  1019. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
  1020. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1021. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1022. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1023. #endif
  1024. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2021030000)
  1025. if (target == DNN_TARGET_MYRIAD)
  1026. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE);
  1027. #endif
  1028. testONNXModels("gather_multi_output");
  1029. }
  1030. TEST_P(Test_ONNX_layers, DynamicAxes_squeeze_and_conv)
  1031. {
  1032. #if defined(INF_ENGINE_RELEASE)
  1033. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1034. {
  1035. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1036. }
  1037. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1038. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1039. {
  1040. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1041. }
  1042. #endif
  1043. #endif
  1044. testONNXModels("squeeze_and_conv_dynamic_axes");
  1045. }
  1046. TEST_P(Test_ONNX_layers, DynamicAxes_unsqueeze_and_conv)
  1047. {
  1048. #if defined(INF_ENGINE_RELEASE)
  1049. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1050. {
  1051. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1052. }
  1053. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1054. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1055. {
  1056. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1057. }
  1058. #endif
  1059. #endif
  1060. testONNXModels("unsqueeze_and_conv_dynamic_axes");
  1061. }
  1062. TEST_P(Test_ONNX_layers, DynamicAxes_gather)
  1063. {
  1064. #if defined(INF_ENGINE_RELEASE)
  1065. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1066. {
  1067. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1068. }
  1069. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1070. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1071. {
  1072. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1073. }
  1074. #endif
  1075. #endif
  1076. testONNXModels("gather_dynamic_axes");
  1077. }
  1078. TEST_P(Test_ONNX_layers, DynamicAxes_gather_scalar)
  1079. {
  1080. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1081. // accuracy
  1082. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  1083. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1084. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1085. );
  1086. #endif
  1087. #if defined(INF_ENGINE_RELEASE)
  1088. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1089. {
  1090. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1091. }
  1092. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1093. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1094. {
  1095. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1096. }
  1097. #endif
  1098. #endif
  1099. testONNXModels("gather_scalar_dynamic_axes");
  1100. }
  1101. TEST_P(Test_ONNX_layers, DynamicAxes_slice)
  1102. {
  1103. #if defined(INF_ENGINE_RELEASE)
  1104. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1105. {
  1106. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1107. }
  1108. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1109. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1110. {
  1111. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1112. }
  1113. #endif
  1114. #endif
  1115. testONNXModels("slice_dynamic_axes");
  1116. }
  1117. TEST_P(Test_ONNX_layers, DynamicAxes_slice_opset_11)
  1118. {
  1119. #if defined(INF_ENGINE_RELEASE)
  1120. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1121. {
  1122. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1123. }
  1124. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1125. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1126. {
  1127. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1128. }
  1129. #endif
  1130. #endif
  1131. testONNXModels("slice_opset_11_dynamic_axes");
  1132. }
  1133. TEST_P(Test_ONNX_layers, DynamicAxes_resize_opset11_torch16)
  1134. {
  1135. #if defined(INF_ENGINE_RELEASE)
  1136. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1137. {
  1138. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1139. }
  1140. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1141. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1142. {
  1143. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1144. }
  1145. #endif
  1146. #endif
  1147. testONNXModels("resize_opset11_torch1.6_dynamic_axes");
  1148. }
  1149. TEST_P(Test_ONNX_layers, DynamicAxes_average_pooling)
  1150. {
  1151. #if defined(INF_ENGINE_RELEASE)
  1152. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1153. {
  1154. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1155. }
  1156. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1157. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1158. {
  1159. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1160. }
  1161. #endif
  1162. #endif
  1163. testONNXModels("average_pooling_dynamic_axes");
  1164. }
  1165. TEST_P(Test_ONNX_layers, DynamicAxes_maxpooling_sigmoid)
  1166. {
  1167. #if defined(INF_ENGINE_RELEASE)
  1168. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1169. {
  1170. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1171. }
  1172. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1173. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1174. {
  1175. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1176. }
  1177. #endif
  1178. #endif
  1179. testONNXModels("maxpooling_sigmoid_dynamic_axes");
  1180. }
  1181. TEST_P(Test_ONNX_layers, DynamicAxes_dynamic_batch)
  1182. {
  1183. #if defined(INF_ENGINE_RELEASE)
  1184. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1185. {
  1186. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1187. }
  1188. #if INF_ENGINE_VER_MAJOR_LT(2021000000)
  1189. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1190. {
  1191. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1192. }
  1193. #endif
  1194. #endif
  1195. testONNXModels("dynamic_batch");
  1196. }
  1197. TEST_P(Test_ONNX_layers, MaxPool1d)
  1198. {
  1199. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1200. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1201. {
  1202. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1203. }
  1204. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1205. {
  1206. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1207. }
  1208. #endif
  1209. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021040000)
  1210. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1211. {
  1212. // 2021.4: [ GENERAL_ERROR ] AssertionFailed: !expired()
  1213. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1214. }
  1215. #endif
  1216. testONNXModels("maxpooling_1d");
  1217. }
  1218. TEST_P(Test_ONNX_layers, MaxPoolSigmoid1d)
  1219. {
  1220. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1221. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1222. {
  1223. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1224. }
  1225. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1226. {
  1227. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1228. }
  1229. #endif
  1230. testONNXModels("maxpooling_sigmoid_1d");
  1231. }
  1232. TEST_P(Test_ONNX_layers, MaxPool1d_Twise)
  1233. {
  1234. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1235. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1236. {
  1237. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1238. }
  1239. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1240. {
  1241. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1242. }
  1243. #endif
  1244. testONNXModels("two_maxpooling_1d");
  1245. }
  1246. TEST_P(Test_ONNX_layers, AvePool1d)
  1247. {
  1248. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1249. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1250. {
  1251. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1252. }
  1253. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1254. {
  1255. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1256. }
  1257. #endif
  1258. testONNXModels("average_pooling_1d");
  1259. }
  1260. TEST_P(Test_ONNX_layers, PoolConv1d)
  1261. {
  1262. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1263. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1264. {
  1265. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1266. }
  1267. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1268. {
  1269. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1270. }
  1271. #endif
  1272. testONNXModels("pool_conv_1d");
  1273. }
  1274. TEST_P(Test_ONNX_layers, ConvResizePool1d)
  1275. {
  1276. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1277. // IE Exception: Ngraph operation Reshape with name 15 has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  1278. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  1279. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1280. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1281. );
  1282. #endif
  1283. #if defined(INF_ENGINE_RELEASE)
  1284. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1285. {
  1286. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1287. }
  1288. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1289. {
  1290. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1291. #if INF_ENGINE_VER_MAJOR_EQ(2021030000)
  1292. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1293. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1294. #endif
  1295. }
  1296. #endif
  1297. testONNXModels("conv_resize_pool_1d");
  1298. }
  1299. TEST_P(Test_ONNX_layers, SubFromConst)
  1300. {
  1301. testONNXModels("sub_from_const1");
  1302. testONNXModels("sub_from_const_eltwise");
  1303. testONNXModels("sub_from_const_broadcast");
  1304. }
  1305. TEST_P(Test_ONNX_layers, DivConst)
  1306. {
  1307. testONNXModels("div_const");
  1308. }
  1309. TEST_P(Test_ONNX_layers, Quantized_Convolution)
  1310. {
  1311. testONNXModels("quantized_conv_uint8_weights", npy, 0.004, 0.02);
  1312. testONNXModels("quantized_conv_int8_weights", npy, 0.03, 0.5);
  1313. testONNXModels("quantized_conv_per_channel_weights", npy, 0.06, 0.4);
  1314. }
  1315. TEST_P(Test_ONNX_layers, Quantized_MatMul)
  1316. {
  1317. testONNXModels("quantized_matmul_uint8_weights", npy, 0.005, 0.007);
  1318. testONNXModels("quantized_matmul_int8_weights", npy, 0.06, 0.2);
  1319. testONNXModels("quantized_matmul_per_channel_weights", npy, 0.06, 0.22);
  1320. }
  1321. TEST_P(Test_ONNX_layers, Quantized_MatMul_Variable_Weights)
  1322. {
  1323. // Unsupported
  1324. EXPECT_THROW(
  1325. {
  1326. testONNXModels("quantized_matmul_variable_inputs");
  1327. }, cv::Exception);
  1328. }
  1329. TEST_P(Test_ONNX_layers, Quantized_Eltwise)
  1330. {
  1331. testONNXModels("quantized_eltwise");
  1332. }
  1333. TEST_P(Test_ONNX_layers, Quantized_Eltwise_Scalar)
  1334. {
  1335. testONNXModels("quantized_eltwise_scalar");
  1336. }
  1337. TEST_P(Test_ONNX_layers, Quantized_Eltwise_Broadcast)
  1338. {
  1339. testONNXModels("quantized_eltwise_broadcast");
  1340. }
  1341. TEST_P(Test_ONNX_layers, Quantized_LeakyReLU)
  1342. {
  1343. testONNXModels("quantized_leaky_relu");
  1344. }
  1345. TEST_P(Test_ONNX_layers, Quantized_Sigmoid)
  1346. {
  1347. testONNXModels("quantized_sigmoid");
  1348. }
  1349. TEST_P(Test_ONNX_layers, Quantized_MaxPool)
  1350. {
  1351. testONNXModels("quantized_maxpool");
  1352. }
  1353. TEST_P(Test_ONNX_layers, Quantized_AvgPool)
  1354. {
  1355. testONNXModels("quantized_avgpool");
  1356. }
  1357. TEST_P(Test_ONNX_layers, Quantized_Split)
  1358. {
  1359. testONNXModels("quantized_split");
  1360. }
  1361. TEST_P(Test_ONNX_layers, Quantized_Pad)
  1362. {
  1363. testONNXModels("quantized_padding");
  1364. }
  1365. TEST_P(Test_ONNX_layers, Quantized_Reshape)
  1366. {
  1367. testONNXModels("quantized_reshape");
  1368. }
  1369. TEST_P(Test_ONNX_layers, Quantized_Transpose)
  1370. {
  1371. testONNXModels("quantized_transpose");
  1372. }
  1373. TEST_P(Test_ONNX_layers, Quantized_Squeeze)
  1374. {
  1375. testONNXModels("quantized_squeeze");
  1376. }
  1377. TEST_P(Test_ONNX_layers, Quantized_Unsqueeze)
  1378. {
  1379. testONNXModels("quantized_unsqueeze");
  1380. }
  1381. TEST_P(Test_ONNX_layers, Quantized_Resize)
  1382. {
  1383. testONNXModels("quantized_resize_nearest");
  1384. testONNXModels("quantized_resize_bilinear", npy, 2e-4, 0.003);
  1385. testONNXModels("quantized_resize_bilinear_align", npy, 3e-4, 0.003);
  1386. }
  1387. TEST_P(Test_ONNX_layers, Quantized_Concat)
  1388. {
  1389. testONNXModels("quantized_concat");
  1390. testONNXModels("quantized_concat_const_blob");
  1391. }
  1392. TEST_P(Test_ONNX_layers, Quantized_Constant)
  1393. {
  1394. testONNXModels("quantized_constant", npy, 0.002, 0.008);
  1395. }
  1396. INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_ONNX_layers, dnnBackendsAndTargets());
  1397. class Test_ONNX_nets : public Test_ONNX_layers
  1398. {
  1399. public:
  1400. Test_ONNX_nets() { required = false; }
  1401. };
  1402. TEST_P(Test_ONNX_nets, Alexnet)
  1403. {
  1404. #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
  1405. applyTestTag(CV_TEST_TAG_MEMORY_2GB);
  1406. #else
  1407. applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
  1408. #endif
  1409. const String model = _tf("models/alexnet.onnx", false);
  1410. Net net = readNetFromONNX(model);
  1411. ASSERT_FALSE(net.empty());
  1412. net.setPreferableBackend(backend);
  1413. net.setPreferableTarget(target);
  1414. Mat inp = imread(_tf("../grace_hopper_227.png"));
  1415. Mat ref = blobFromNPY(_tf("../caffe_alexnet_prob.npy"));
  1416. checkBackend(&inp, &ref);
  1417. net.setInput(blobFromImage(inp, 1.0f, Size(227, 227), Scalar(), false));
  1418. ASSERT_FALSE(net.empty());
  1419. Mat out = net.forward();
  1420. normAssert(out, ref, "", default_l1, default_lInf);
  1421. expectNoFallbacksFromIE(net);
  1422. }
  1423. TEST_P(Test_ONNX_nets, Squeezenet)
  1424. {
  1425. testONNXModels("squeezenet", pb);
  1426. }
  1427. TEST_P(Test_ONNX_nets, Googlenet)
  1428. {
  1429. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1430. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1431. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1432. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1433. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1434. #endif
  1435. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1436. // accuracy
  1437. if (target == DNN_TARGET_MYRIAD)
  1438. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1439. #endif
  1440. const String model = _tf("models/googlenet.onnx", false);
  1441. Net net = readNetFromONNX(model);
  1442. ASSERT_FALSE(net.empty());
  1443. net.setPreferableBackend(backend);
  1444. net.setPreferableTarget(target);
  1445. std::vector<Mat> images;
  1446. images.push_back( imread(_tf("../googlenet_0.png")) );
  1447. images.push_back( imread(_tf("../googlenet_1.png")) );
  1448. Mat inp = blobFromImages(images, 1.0f, Size(), Scalar(), false);
  1449. Mat ref = blobFromNPY(_tf("../googlenet_prob.npy"));
  1450. checkBackend(&inp, &ref);
  1451. net.setInput(inp);
  1452. ASSERT_FALSE(net.empty());
  1453. Mat out = net.forward();
  1454. normAssert(ref, out, "", default_l1, default_lInf);
  1455. expectNoFallbacksFromIE(net);
  1456. }
  1457. TEST_P(Test_ONNX_nets, CaffeNet)
  1458. {
  1459. #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
  1460. applyTestTag(CV_TEST_TAG_MEMORY_2GB);
  1461. #else
  1462. applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
  1463. #endif
  1464. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019030000)
  1465. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  1466. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  1467. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1468. #endif
  1469. testONNXModels("caffenet", pb);
  1470. }
  1471. TEST_P(Test_ONNX_nets, RCNN_ILSVRC13)
  1472. {
  1473. #if defined(OPENCV_32BIT_CONFIGURATION) && (defined(HAVE_OPENCL) || defined(_WIN32))
  1474. applyTestTag(CV_TEST_TAG_MEMORY_2GB);
  1475. #else
  1476. applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
  1477. #endif
  1478. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019030000)
  1479. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  1480. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  1481. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1482. #endif
  1483. // Reference output values are in range [-4.992, -1.161]
  1484. testONNXModels("rcnn_ilsvrc13", pb, 0.0046);
  1485. }
  1486. TEST_P(Test_ONNX_nets, VGG16_bn)
  1487. {
  1488. applyTestTag(CV_TEST_TAG_MEMORY_6GB); // > 2.3Gb
  1489. // output range: [-16; 27], after Softmax [0; 0.67]
  1490. const double lInf = (target == DNN_TARGET_MYRIAD) ? 0.038 : default_lInf;
  1491. testONNXModels("vgg16-bn", pb, default_l1, lInf, true);
  1492. }
  1493. TEST_P(Test_ONNX_nets, ZFNet)
  1494. {
  1495. applyTestTag(CV_TEST_TAG_MEMORY_2GB);
  1496. testONNXModels("zfnet512", pb);
  1497. }
  1498. TEST_P(Test_ONNX_nets, ResNet18v1)
  1499. {
  1500. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  1501. // output range: [-16; 22], after Softmax [0, 0.51]
  1502. testONNXModels("resnet18v1", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
  1503. }
  1504. TEST_P(Test_ONNX_nets, ResNet50v1)
  1505. {
  1506. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  1507. // output range: [-67; 75], after Softmax [0, 0.98]
  1508. testONNXModels("resnet50v1", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
  1509. }
  1510. TEST_P(Test_ONNX_nets, ResNet50_Int8)
  1511. {
  1512. testONNXModels("resnet50_int8", pb, default_l1, default_lInf, true);
  1513. }
  1514. TEST_P(Test_ONNX_nets, ResNet101_DUC_HDC)
  1515. {
  1516. applyTestTag(CV_TEST_TAG_VERYLONG);
  1517. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
  1518. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1519. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1520. #endif
  1521. #if defined(INF_ENGINE_RELEASE)
  1522. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  1523. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1524. #endif
  1525. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_OPENCL)
  1526. {
  1527. if (backend == DNN_BACKEND_OPENCV)
  1528. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_OPENCL : CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  1529. throw SkipTestException("Test is disabled for OpenCL targets");
  1530. }
  1531. testONNXModels("resnet101_duc_hdc", pb);
  1532. }
  1533. TEST_P(Test_ONNX_nets, TinyYolov2)
  1534. {
  1535. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  1536. if (cvtest::skipUnstableTests)
  1537. throw SkipTestException("Skip unstable test");
  1538. #if defined(INF_ENGINE_RELEASE)
  1539. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
  1540. && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  1541. )
  1542. 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);
  1543. if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
  1544. )
  1545. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
  1546. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
  1547. CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
  1548. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1549. #endif
  1550. // output range: [-11; 8]
  1551. double l1 = default_l1, lInf = default_lInf;
  1552. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  1553. {
  1554. l1 = 0.02;
  1555. lInf = 0.2;
  1556. }
  1557. else if (target == DNN_TARGET_CUDA_FP16)
  1558. {
  1559. l1 = 0.018;
  1560. lInf = 0.16;
  1561. }
  1562. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2020040000)
  1563. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1564. {
  1565. l1 = 0.018f; lInf = 0.16f;
  1566. }
  1567. #endif
  1568. testONNXModels("tiny_yolo2", pb, l1, lInf);
  1569. }
  1570. TEST_P(Test_ONNX_nets, CNN_MNIST)
  1571. {
  1572. // output range: [-1952; 6574], after Softmax [0; 1]
  1573. testONNXModels("cnn_mnist", pb, default_l1, default_lInf, true);
  1574. }
  1575. TEST_P(Test_ONNX_nets, MobileNet_v2)
  1576. {
  1577. // output range: [-166; 317], after Softmax [0; 1]
  1578. testONNXModels("mobilenetv2", pb, default_l1, default_lInf, true);
  1579. }
  1580. TEST_P(Test_ONNX_nets, LResNet100E_IR)
  1581. {
  1582. applyTestTag(
  1583. #if defined(OPENCV_32BIT_CONFIGURATION) && defined(HAVE_OPENCL)
  1584. CV_TEST_TAG_MEMORY_2GB,
  1585. #else
  1586. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
  1587. #endif
  1588. CV_TEST_TAG_DEBUG_LONG
  1589. );
  1590. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1591. {
  1592. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1593. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1594. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1595. }
  1596. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1597. {
  1598. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1599. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1600. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1601. }
  1602. double l1 = default_l1, lInf = default_lInf;
  1603. // output range: [-3; 3]
  1604. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  1605. {
  1606. l1 = 0.009;
  1607. lInf = 0.035;
  1608. }
  1609. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_CPU)
  1610. {
  1611. l1 = 4.6e-5;
  1612. lInf = 1.9e-4;
  1613. }
  1614. else if (target == DNN_TARGET_CUDA_FP16)
  1615. {
  1616. l1 = 0.008;
  1617. lInf = 0.04;
  1618. }
  1619. testONNXModels("LResNet100E_IR", pb, l1, lInf);
  1620. }
  1621. TEST_P(Test_ONNX_nets, Emotion_ferplus)
  1622. {
  1623. #if defined(INF_ENGINE_RELEASE)
  1624. if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  1625. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
  1626. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
  1627. CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
  1628. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1629. #endif
  1630. double l1 = default_l1;
  1631. double lInf = default_lInf;
  1632. // Output values are in range [-2.011, 2.111]
  1633. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  1634. l1 = 0.007;
  1635. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL_FP16)
  1636. {
  1637. l1 = 0.021;
  1638. lInf = 0.034;
  1639. }
  1640. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL)) {
  1641. l1 = 2.4e-4;
  1642. lInf = 6e-4;
  1643. }
  1644. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
  1645. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1646. {
  1647. l1 = 0.013f; lInf = 0.035f;
  1648. }
  1649. #endif
  1650. testONNXModels("emotion_ferplus", pb, l1, lInf);
  1651. }
  1652. TEST_P(Test_ONNX_nets, Inception_v2)
  1653. {
  1654. testONNXModels("inception_v2", pb, default_l1, default_lInf, true);
  1655. }
  1656. TEST_P(Test_ONNX_nets, DenseNet121)
  1657. {
  1658. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  1659. // output range: [-87; 138], after Softmax [0; 1]
  1660. testONNXModels("densenet121", pb, default_l1, default_lInf, true, target != DNN_TARGET_MYRIAD);
  1661. }
  1662. TEST_P(Test_ONNX_nets, Inception_v1)
  1663. {
  1664. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1665. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
  1666. backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD)
  1667. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
  1668. #endif
  1669. testONNXModels("inception_v1", pb);
  1670. }
  1671. TEST_P(Test_ONNX_nets, Shufflenet)
  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_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1677. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1678. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1679. }
  1680. #endif
  1681. testONNXModels("shufflenet", pb);
  1682. }
  1683. TEST_P(Test_ONNX_nets, Resnet34_kinetics)
  1684. {
  1685. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1686. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  1687. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  1688. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  1689. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  1690. #endif
  1691. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1692. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1693. {
  1694. // IE exception: Function contains several inputs and outputs with one friendly name!
  1695. if (target == DNN_TARGET_MYRIAD)
  1696. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1697. }
  1698. #endif
  1699. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  1700. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  1701. if (backend == DNN_BACKEND_VKCOM)
  1702. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  1703. String onnxmodel = findDataFile("dnn/resnet-34_kinetics.onnx", false);
  1704. Mat image0 = imread(findDataFile("dnn/dog416.png"));
  1705. Mat image1 = imread(findDataFile("dnn/street.png"));
  1706. Mat ref0 = blobFromNPY(_tf("data/output_kinetics0.npy"));
  1707. Mat ref1 = blobFromNPY(_tf("data/output_kinetics1.npy"));
  1708. std::vector<Mat> images_0(16, image0);
  1709. std::vector<Mat> images_1(16, image1);
  1710. Mat blob0 = blobFromImages(images_0, 1.0, Size(112, 112), Scalar(114.7748, 107.7354, 99.4750), true, true);
  1711. Mat blob1 = blobFromImages(images_1, 1.0, Size(112, 112), Scalar(114.7748, 107.7354, 99.4750), true, true);
  1712. Net permute;
  1713. LayerParams lp;
  1714. int order[] = {1, 0, 2, 3};
  1715. lp.set("order", DictValue::arrayInt<int*>(&order[0], 4));
  1716. permute.addLayerToPrev("perm", "Permute", lp);
  1717. permute.setPreferableBackend(backend);
  1718. permute.setPreferableTarget(target);
  1719. permute.setInput(blob0);
  1720. Mat input0 = permute.forward().clone();
  1721. permute.setInput(blob1);
  1722. Mat input1 = permute.forward().clone();
  1723. int dims[] = {1, 3, 16, 112, 112};
  1724. input0 = input0.reshape(0, 5, &dims[0]);
  1725. input1 = input1.reshape(0, 5, &dims[0]);
  1726. Net net = readNetFromONNX(onnxmodel);
  1727. ASSERT_FALSE(net.empty());
  1728. net.setPreferableBackend(backend);
  1729. net.setPreferableTarget(target);
  1730. // output range [-5, 11]
  1731. float l1 = 0.0013;
  1732. float lInf = 0.009;
  1733. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1734. {
  1735. l1 = 0.02;
  1736. lInf = 0.07;
  1737. }
  1738. if (target == DNN_TARGET_CUDA_FP16)
  1739. {
  1740. l1 = 0.01;
  1741. lInf = 0.06;
  1742. }
  1743. checkBackend(&input0, &ref0);
  1744. net.setInput(input0);
  1745. Mat out = net.forward().clone();
  1746. normAssert(ref0, out, "", l1, lInf);
  1747. checkBackend(&input1, &ref1);
  1748. net.setInput(input1);
  1749. out = net.forward().clone();
  1750. normAssert(ref1, out, "", l1, lInf);
  1751. expectNoFallbacksFromIE(net);
  1752. }
  1753. TEST_P(Test_ONNX_layers, CumSum)
  1754. {
  1755. testONNXModels("cumsum_1d_exclusive_1");
  1756. testONNXModels("cumsum_1d_reverse");
  1757. testONNXModels("cumsum_1d_exclusive_1_reverse");
  1758. testONNXModels("cumsum_2d_dim_1");
  1759. testONNXModels("cumsum_3d_dim_2");
  1760. }
  1761. INSTANTIATE_TEST_CASE_P(/**/, Test_ONNX_nets, dnnBackendsAndTargets());
  1762. }} // namespace