test_tf_importer.cpp 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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) 2017-2019, Intel Corporation, all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. /*
  7. Test for Tensorflow models loading
  8. */
  9. #include "test_precomp.hpp"
  10. #include "npy_blob.hpp"
  11. #include <opencv2/dnn/layer.details.hpp> // CV_DNN_REGISTER_LAYER_CLASS
  12. #include <opencv2/dnn/utils/debug_utils.hpp>
  13. namespace opencv_test
  14. {
  15. using namespace cv;
  16. using namespace cv::dnn;
  17. template<typename TString>
  18. static std::string _tf(TString filename)
  19. {
  20. return (getOpenCVExtraDir() + "/dnn/") + filename;
  21. }
  22. TEST(Test_TensorFlow, read_inception)
  23. {
  24. Net net;
  25. {
  26. const string model = findDataFile("dnn/tensorflow_inception_graph.pb", false);
  27. net = readNetFromTensorflow(model);
  28. ASSERT_FALSE(net.empty());
  29. }
  30. net.setPreferableBackend(DNN_BACKEND_OPENCV);
  31. Mat sample = imread(_tf("grace_hopper_227.png"));
  32. ASSERT_TRUE(!sample.empty());
  33. Mat input;
  34. resize(sample, input, Size(224, 224));
  35. input -= Scalar::all(117); // mean sub
  36. Mat inputBlob = blobFromImage(input);
  37. net.setInput(inputBlob, "input");
  38. Mat out = net.forward("softmax2");
  39. std::cout << out.dims << std::endl;
  40. }
  41. TEST(Test_TensorFlow, inception_accuracy)
  42. {
  43. Net net;
  44. {
  45. const string model = findDataFile("dnn/tensorflow_inception_graph.pb", false);
  46. net = readNetFromTensorflow(model);
  47. ASSERT_FALSE(net.empty());
  48. }
  49. net.setPreferableBackend(DNN_BACKEND_OPENCV);
  50. Mat sample = imread(_tf("grace_hopper_227.png"));
  51. ASSERT_TRUE(!sample.empty());
  52. Mat inputBlob = blobFromImage(sample, 1.0, Size(224, 224), Scalar(), /*swapRB*/true);
  53. net.setInput(inputBlob, "input");
  54. Mat out = net.forward("softmax2");
  55. Mat ref = blobFromNPY(_tf("tf_inception_prob.npy"));
  56. normAssert(ref, out);
  57. }
  58. static std::string path(const std::string& file)
  59. {
  60. return findDataFile("dnn/tensorflow/" + file);
  61. }
  62. class Test_TensorFlow_layers : public DNNTestLayer
  63. {
  64. public:
  65. void runTensorFlowNet(const std::string& prefix, bool hasText = false,
  66. double l1 = 0.0, double lInf = 0.0, bool memoryLoad = false, const std::string& groupPrefix = "")
  67. {
  68. if (cvtest::debugLevel > 0)
  69. {
  70. std::cout << prefix << groupPrefix << std::endl;
  71. }
  72. std::string netPath = path(prefix + groupPrefix + "_net.pb");
  73. std::string netConfig = (hasText ? path(prefix + groupPrefix + "_net.pbtxt") : "");
  74. std::string inpPath = path(prefix + "_in.npy");
  75. std::string outPath = path(prefix + groupPrefix + "_out.npy");
  76. cv::Mat input = blobFromNPY(inpPath);
  77. cv::Mat ref = blobFromNPY(outPath);
  78. checkBackend(&input, &ref);
  79. Net net;
  80. if (memoryLoad)
  81. {
  82. // Load files into a memory buffers
  83. std::vector<char> dataModel;
  84. readFileContent(netPath, dataModel);
  85. std::vector<char> dataConfig;
  86. if (hasText)
  87. {
  88. readFileContent(netConfig, dataConfig);
  89. }
  90. net = readNetFromTensorflow(dataModel.data(), dataModel.size(),
  91. dataConfig.data(), dataConfig.size());
  92. }
  93. else
  94. net = readNetFromTensorflow(netPath, netConfig);
  95. ASSERT_FALSE(net.empty());
  96. net.setPreferableBackend(backend);
  97. net.setPreferableTarget(target);
  98. net.setInput(input);
  99. cv::Mat output = net.forward();
  100. normAssert(ref, output, "", l1 ? l1 : default_l1, lInf ? lInf : default_lInf);
  101. if (cvtest::debugLevel > 0 || HasFailure())
  102. {
  103. std::cout << "input: " << input.size << std::endl;
  104. std::cout << input.reshape(1, 1) << std::endl;
  105. std::cout << "ref " << ref.size << std::endl;
  106. std::cout << ref.reshape(1, 1) << std::endl;
  107. std::cout << "output: " << output.size << std::endl;
  108. std::cout << output.reshape(1, 1) << std::endl;
  109. }
  110. }
  111. };
  112. TEST_P(Test_TensorFlow_layers, reduce_mean)
  113. {
  114. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  115. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  116. runTensorFlowNet("global_pool_by_axis");
  117. }
  118. TEST_P(Test_TensorFlow_layers, reduce_max)
  119. {
  120. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  121. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  122. runTensorFlowNet("max_pool_by_axis", false, 0.0f, 0.0f);
  123. }
  124. TEST_P(Test_TensorFlow_layers, reduce_sum)
  125. {
  126. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  127. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  128. runTensorFlowNet("sum_pool_by_axis");
  129. }
  130. TEST_P(Test_TensorFlow_layers, reduce_max_channel)
  131. {
  132. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
  133. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) // incorrect result
  134. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  135. #endif
  136. runTensorFlowNet("reduce_max_channel", false, 0.0f, 0.0f);
  137. }
  138. TEST_P(Test_TensorFlow_layers, reduce_sum_channel)
  139. {
  140. runTensorFlowNet("reduce_sum_channel");
  141. }
  142. TEST_P(Test_TensorFlow_layers, reduce_max_channel_keep_dims)
  143. {
  144. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
  145. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) // incorrect result
  146. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  147. #endif
  148. runTensorFlowNet("reduce_max_channel", false, 0.0, 0.0, false, "_keep_dims");
  149. }
  150. TEST_P(Test_TensorFlow_layers, reduce_sum_channel_keep_dims)
  151. {
  152. runTensorFlowNet("reduce_sum_channel", false, 0.0, 0.0, false, "_keep_dims");
  153. }
  154. TEST_P(Test_TensorFlow_layers, ArgLayer)
  155. {
  156. if (backend != DNN_BACKEND_OPENCV || target != DNN_TARGET_CPU)
  157. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  158. runTensorFlowNet("argmax");
  159. runTensorFlowNet("argmin");
  160. }
  161. TEST_P(Test_TensorFlow_layers, conv_single_conv)
  162. {
  163. runTensorFlowNet("single_conv");
  164. }
  165. TEST_P(Test_TensorFlow_layers, conv_atrous_conv2d_valid)
  166. {
  167. runTensorFlowNet("atrous_conv2d_valid");
  168. }
  169. TEST_P(Test_TensorFlow_layers, conv_atrous_conv2d_same)
  170. {
  171. runTensorFlowNet("atrous_conv2d_same");
  172. }
  173. TEST_P(Test_TensorFlow_layers, conv_depthwise_conv2d)
  174. {
  175. runTensorFlowNet("depthwise_conv2d");
  176. }
  177. TEST_P(Test_TensorFlow_layers, conv_keras_atrous_conv2d_same)
  178. {
  179. runTensorFlowNet("keras_atrous_conv2d_same");
  180. }
  181. TEST_P(Test_TensorFlow_layers, conv_pool_nchw)
  182. {
  183. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  184. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  185. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  186. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  187. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  188. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  189. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  190. #endif
  191. runTensorFlowNet("conv_pool_nchw");
  192. }
  193. TEST_P(Test_TensorFlow_layers, Convolution3D)
  194. {
  195. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  196. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  197. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  198. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  199. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  200. #endif
  201. runTensorFlowNet("conv3d");
  202. }
  203. TEST_P(Test_TensorFlow_layers, padding)
  204. {
  205. runTensorFlowNet("padding_valid");
  206. runTensorFlowNet("spatial_padding");
  207. runTensorFlowNet("mirror_pad");
  208. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019020000) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  209. if (target == DNN_TARGET_MYRIAD)
  210. {
  211. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  212. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  213. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  214. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  215. }
  216. #endif
  217. runTensorFlowNet("keras_pad_concat");
  218. }
  219. TEST_P(Test_TensorFlow_layers, padding_asymmetric_1)
  220. {
  221. runTensorFlowNet("conv2d_asymmetric_pads_nchw");
  222. }
  223. TEST_P(Test_TensorFlow_layers, padding_asymmetric_2)
  224. {
  225. runTensorFlowNet("conv2d_asymmetric_pads_nhwc");
  226. }
  227. TEST_P(Test_TensorFlow_layers, padding_asymmetric_3)
  228. {
  229. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  230. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU) // Exception: Unsupported pad value
  231. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  232. #endif
  233. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  234. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) // Exception: Unsupported pad value
  235. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  236. #endif
  237. runTensorFlowNet("max_pool2d_asymmetric_pads_nchw");
  238. }
  239. TEST_P(Test_TensorFlow_layers, padding_asymmetric_4)
  240. {
  241. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  242. // Unsupported pad value
  243. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  244. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  245. // accuracy
  246. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  247. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  248. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  249. );
  250. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  251. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) // Exception: Unsupported pad value
  252. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  253. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  254. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU) // Exception: Unsupported pad value
  255. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  256. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  257. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) // Exception: Unsupported pad value
  258. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  259. #endif
  260. #endif
  261. runTensorFlowNet("max_pool2d_asymmetric_pads_nhwc");
  262. }
  263. TEST_P(Test_TensorFlow_layers, padding_asymmetric_5)
  264. {
  265. runTensorFlowNet("conv2d_backprop_input_asymmetric_pads_nchw");
  266. }
  267. TEST_P(Test_TensorFlow_layers, padding_asymmetric_6)
  268. {
  269. runTensorFlowNet("conv2d_backprop_input_asymmetric_pads_nhwc");
  270. }
  271. TEST_P(Test_TensorFlow_layers, padding_same)
  272. {
  273. // Reference output values are in range [0.0006, 2.798]
  274. runTensorFlowNet("padding_same");
  275. }
  276. TEST_P(Test_TensorFlow_layers, eltwise)
  277. {
  278. runTensorFlowNet("eltwise_add_mul");
  279. runTensorFlowNet("eltwise_sub");
  280. }
  281. TEST_P(Test_TensorFlow_layers, eltwise_add_vec)
  282. {
  283. runTensorFlowNet("eltwise_add_vec");
  284. }
  285. TEST_P(Test_TensorFlow_layers, eltwise_mul_vec)
  286. {
  287. runTensorFlowNet("eltwise_mul_vec");
  288. }
  289. TEST_P(Test_TensorFlow_layers, tf_reshape_nhwc)
  290. {
  291. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  292. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  293. runTensorFlowNet("tf_reshape_nhwc");
  294. }
  295. TEST_P(Test_TensorFlow_layers, channel_broadcast)
  296. {
  297. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  298. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  299. runTensorFlowNet("channel_broadcast");
  300. }
  301. TEST_P(Test_TensorFlow_layers, pad_and_concat)
  302. {
  303. runTensorFlowNet("pad_and_concat");
  304. }
  305. TEST_P(Test_TensorFlow_layers, concat_axis_1)
  306. {
  307. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  308. // IE Exception: Ngraph operation Transpose with name Flatten_1/flatten/Reshape/nhwc has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  309. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  310. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  311. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  312. );
  313. #endif
  314. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  315. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL)
  316. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  317. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  318. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  319. #endif
  320. runTensorFlowNet("concat_axis_1");
  321. }
  322. TEST_P(Test_TensorFlow_layers, concat_3d)
  323. {
  324. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  325. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  326. {
  327. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
  328. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL);
  329. }
  330. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH ||
  331. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD)
  332. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  333. #endif
  334. runTensorFlowNet("concat_3d");
  335. }
  336. TEST_P(Test_TensorFlow_layers, batch_norm_1)
  337. {
  338. runTensorFlowNet("batch_norm");
  339. }
  340. TEST_P(Test_TensorFlow_layers, batch_norm_2)
  341. {
  342. runTensorFlowNet("batch_norm", false, 0.0, 0.0, true);
  343. }
  344. TEST_P(Test_TensorFlow_layers, batch_norm_3)
  345. {
  346. runTensorFlowNet("fused_batch_norm");
  347. }
  348. TEST_P(Test_TensorFlow_layers, batch_norm_4)
  349. {
  350. runTensorFlowNet("fused_batch_norm", false, 0.0, 0.0, true);
  351. }
  352. TEST_P(Test_TensorFlow_layers, batch_norm_5)
  353. {
  354. runTensorFlowNet("batch_norm_text", true);
  355. }
  356. TEST_P(Test_TensorFlow_layers, batch_norm_6)
  357. {
  358. runTensorFlowNet("batch_norm_text", true, 0.0, 0.0, true);
  359. }
  360. TEST_P(Test_TensorFlow_layers, batch_norm_7)
  361. {
  362. runTensorFlowNet("unfused_batch_norm");
  363. }
  364. TEST_P(Test_TensorFlow_layers, batch_norm_8)
  365. {
  366. runTensorFlowNet("fused_batch_norm_no_gamma");
  367. }
  368. TEST_P(Test_TensorFlow_layers, batch_norm_9)
  369. {
  370. runTensorFlowNet("unfused_batch_norm_no_gamma");
  371. }
  372. TEST_P(Test_TensorFlow_layers, batch_norm_10)
  373. {
  374. runTensorFlowNet("mvn_batch_norm");
  375. }
  376. TEST_P(Test_TensorFlow_layers, batch_norm_11)
  377. {
  378. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  379. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  380. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // nan
  381. #endif
  382. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  383. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  384. runTensorFlowNet("mvn_batch_norm_1x1");
  385. }
  386. TEST_P(Test_TensorFlow_layers, batch_norm_12)
  387. {
  388. runTensorFlowNet("switch_identity");
  389. }
  390. TEST_P(Test_TensorFlow_layers, batch_norm_13)
  391. {
  392. runTensorFlowNet("keras_batch_norm_training");
  393. }
  394. TEST_P(Test_TensorFlow_layers, batch_norm3D)
  395. {
  396. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  397. {
  398. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  399. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  400. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  401. throw SkipTestException("");
  402. }
  403. runTensorFlowNet("batch_norm3d");
  404. }
  405. TEST_P(Test_TensorFlow_layers, slim_batch_norm)
  406. {
  407. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  408. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  409. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  410. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  411. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  412. #endif
  413. // Output values range: [-40.0597, 207.827]
  414. double l1 = default_l1;
  415. double lInf = default_lInf;
  416. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  417. {
  418. l1 = 0.041;
  419. lInf = 0.33;
  420. }
  421. #if defined(INF_ENGINE_RELEASE)
  422. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  423. {
  424. lInf = 0.0002;
  425. }
  426. #endif
  427. else if (target == DNN_TARGET_CUDA_FP16)
  428. {
  429. l1 = 0.005;
  430. lInf = 0.33;
  431. }
  432. else if (target == DNN_TARGET_CPU_FP16)
  433. {
  434. l1 = 0.041;
  435. lInf = 0.37;
  436. }
  437. runTensorFlowNet("slim_batch_norm", false, l1, lInf);
  438. }
  439. TEST_P(Test_TensorFlow_layers, pooling_max_pool_even)
  440. {
  441. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  442. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  443. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  444. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  445. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  446. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  447. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  448. #endif
  449. runTensorFlowNet("max_pool_even");
  450. }
  451. TEST_P(Test_TensorFlow_layers, pooling_max_pool_odd_valid)
  452. {
  453. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  454. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  455. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  456. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  457. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  458. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  459. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  460. #endif
  461. runTensorFlowNet("max_pool_odd_valid");
  462. }
  463. TEST_P(Test_TensorFlow_layers, pooling_max_pool_odd_same)
  464. {
  465. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  466. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  467. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  468. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  469. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  470. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  471. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  472. #endif
  473. runTensorFlowNet("max_pool_odd_same");
  474. }
  475. TEST_P(Test_TensorFlow_layers, pooling_reduce_mean)
  476. {
  477. runTensorFlowNet("reduce_mean"); // an average pooling over all spatial dimensions.
  478. }
  479. TEST_P(Test_TensorFlow_layers, pooling_reduce_max)
  480. {
  481. runTensorFlowNet("reduce_max"); // a MAX pooling over all spatial dimensions.
  482. }
  483. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum)
  484. {
  485. runTensorFlowNet("reduce_sum"); // a SUM pooling over all spatial dimensions.
  486. }
  487. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_0_false)
  488. {
  489. runTensorFlowNet("reduce_sum_0_False");
  490. }
  491. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_1_false)
  492. {
  493. runTensorFlowNet("reduce_sum_1_False");
  494. }
  495. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_2_false)
  496. {
  497. runTensorFlowNet("reduce_sum_2_False");
  498. }
  499. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_3_false)
  500. {
  501. runTensorFlowNet("reduce_sum_3_False");
  502. }
  503. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_1_2_false)
  504. {
  505. #if defined(INF_ENGINE_RELEASE)
  506. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  507. {
  508. default_l1 = 0.01f;
  509. }
  510. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  511. {
  512. default_l1 = 0.01f;
  513. }
  514. #endif
  515. runTensorFlowNet("reduce_sum_1_2_False");
  516. }
  517. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_0_true)
  518. {
  519. runTensorFlowNet("reduce_sum_0_True");
  520. }
  521. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_1_true)
  522. {
  523. runTensorFlowNet("reduce_sum_1_True");
  524. }
  525. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_2_true)
  526. {
  527. runTensorFlowNet("reduce_sum_2_True");
  528. }
  529. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_3_true)
  530. {
  531. runTensorFlowNet("reduce_sum_3_True");
  532. }
  533. TEST_P(Test_TensorFlow_layers, pooling_reduce_sum_1_2_true)
  534. {
  535. #if defined(INF_ENGINE_RELEASE)
  536. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  537. {
  538. default_l1 = 0.01f;
  539. }
  540. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  541. {
  542. default_l1 = 0.01f;
  543. }
  544. #endif
  545. runTensorFlowNet("reduce_sum_1_2_True");
  546. }
  547. TEST_P(Test_TensorFlow_layers, max_pool_grad)
  548. {
  549. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  550. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  551. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  552. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  553. runTensorFlowNet("max_pool_grad");
  554. }
  555. // TODO: fix tests and replace to pooling
  556. TEST_P(Test_TensorFlow_layers, ave_pool_same)
  557. {
  558. // Reference output values are in range [-0.519531, 0.112976]
  559. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  560. if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  561. {
  562. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  563. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  564. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  565. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  566. }
  567. #endif
  568. runTensorFlowNet("ave_pool_same");
  569. }
  570. TEST_P(Test_TensorFlow_layers, MaxPooling3D)
  571. {
  572. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  573. // IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired()
  574. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  575. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  576. // accuracy
  577. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  578. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  579. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  580. );
  581. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  582. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  583. {
  584. // accuracy
  585. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  586. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  587. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  588. );
  589. // IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired()
  590. if (target == DNN_TARGET_MYRIAD)
  591. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  592. }
  593. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  594. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  595. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  596. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  597. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  598. #endif
  599. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  600. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  601. if (backend == DNN_BACKEND_VKCOM)
  602. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  603. runTensorFlowNet("max_pool3d");
  604. }
  605. TEST_P(Test_TensorFlow_layers, AvePooling3D)
  606. {
  607. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  608. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU)
  609. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported
  610. else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU)
  611. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported
  612. #endif
  613. if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU)
  614. throw SkipTestException("Only CPU is supported"); // FIXIT use tags
  615. if (backend == DNN_BACKEND_VKCOM)
  616. applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN);
  617. runTensorFlowNet("ave_pool3d");
  618. }
  619. TEST_P(Test_TensorFlow_layers, deconvolution)
  620. {
  621. if (backend == DNN_BACKEND_CUDA)
  622. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA);
  623. runTensorFlowNet("deconvolution");
  624. runTensorFlowNet("deconvolution_same");
  625. runTensorFlowNet("deconvolution_stride_2_same");
  626. runTensorFlowNet("deconvolution_adj_pad_valid");
  627. runTensorFlowNet("deconvolution_adj_pad_same");
  628. runTensorFlowNet("keras_deconv_valid");
  629. runTensorFlowNet("keras_deconv_same");
  630. runTensorFlowNet("keras_deconv_same_v2");
  631. }
  632. TEST_P(Test_TensorFlow_layers, matmul)
  633. {
  634. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  635. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  636. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_CPU_FP16)
  637. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  638. runTensorFlowNet("matmul");
  639. runTensorFlowNet("nhwc_transpose_reshape_matmul");
  640. // Reference output values are in range [-5.688, 4.484]
  641. double l1 = target == DNN_TARGET_MYRIAD ? 6.1e-3 : default_l1;
  642. runTensorFlowNet("nhwc_reshape_matmul", false, l1);
  643. runTensorFlowNet("matmul_layout");
  644. runTensorFlowNet("two_inputs_matmul");
  645. }
  646. TEST_P(Test_TensorFlow_layers, batch_matmul)
  647. {
  648. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  649. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  650. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_CPU_FP16)
  651. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  652. runTensorFlowNet("batch_matmul");
  653. }
  654. TEST_P(Test_TensorFlow_layers, square)
  655. {
  656. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  657. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  658. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_CPU_FP16)
  659. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  660. runTensorFlowNet("square");
  661. }
  662. TEST_P(Test_TensorFlow_layers, reshape)
  663. {
  664. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  665. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  666. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  667. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  668. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  669. #endif
  670. runTensorFlowNet("shift_reshape_no_reorder");
  671. runTensorFlowNet("reshape_no_reorder");
  672. runTensorFlowNet("reshape_reduce");
  673. runTensorFlowNet("reshape_as_shape");
  674. }
  675. TEST_P(Test_TensorFlow_layers, flatten)
  676. {
  677. #if defined(INF_ENGINE_RELEASE)
  678. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  679. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
  680. )
  681. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  682. #endif
  683. runTensorFlowNet("flatten", true);
  684. }
  685. TEST_P(Test_TensorFlow_layers, unfused_flatten)
  686. {
  687. runTensorFlowNet("unfused_flatten");
  688. runTensorFlowNet("unfused_flatten_unknown_batch");
  689. }
  690. TEST_P(Test_TensorFlow_layers, reshape_layer)
  691. {
  692. runTensorFlowNet("reshape_layer");
  693. }
  694. TEST_P(Test_TensorFlow_layers, reshape_nchw)
  695. {
  696. runTensorFlowNet("reshape_nchw");
  697. }
  698. TEST_P(Test_TensorFlow_layers, reshape_conv)
  699. {
  700. runTensorFlowNet("reshape_conv");
  701. }
  702. TEST_P(Test_TensorFlow_layers, leaky_relu)
  703. {
  704. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
  705. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL)
  706. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  707. #endif
  708. runTensorFlowNet("leaky_relu");
  709. runTensorFlowNet("leaky_relu_order1");
  710. runTensorFlowNet("leaky_relu_order2");
  711. runTensorFlowNet("leaky_relu_order3");
  712. }
  713. TEST_P(Test_TensorFlow_layers, l2_normalize)
  714. {
  715. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
  716. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  717. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
  718. )
  719. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  720. #endif
  721. runTensorFlowNet("l2_normalize");
  722. }
  723. TEST_P(Test_TensorFlow_layers, BiasAdd)
  724. {
  725. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
  726. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  727. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
  728. )
  729. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  730. #endif
  731. runTensorFlowNet("bias_add_1");
  732. }
  733. TEST_P(Test_TensorFlow_layers, ExpandDims)
  734. {
  735. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  736. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  737. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Layout::ANY is broken on CPU
  738. #endif
  739. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
  740. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  741. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
  742. )
  743. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  744. #endif
  745. runTensorFlowNet("expand_dims_1");
  746. runTensorFlowNet("expand_dims_2");
  747. }
  748. // TODO: fix it and add to l2_normalize
  749. TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
  750. {
  751. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  752. // accuracy
  753. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  754. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  755. #elif defined(INF_ENGINE_RELEASE)
  756. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  757. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  758. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  759. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  760. #endif
  761. runTensorFlowNet("l2_normalize_3d");
  762. }
  763. class Test_TensorFlow_diagnostics : public DNNTestLayer {
  764. public:
  765. Test_TensorFlow_diagnostics()
  766. {
  767. enableModelDiagnostics(true);
  768. skipModelImport(true);
  769. }
  770. ~Test_TensorFlow_diagnostics()
  771. {
  772. enableModelDiagnostics(false);
  773. skipModelImport(false);
  774. }
  775. void runFailingTensorFlowNet(const std::string& prefix, bool hasText = false)
  776. {
  777. std::string netPath = path(prefix + "_net.pb");
  778. std::string netConfig = (hasText ? path(prefix + "_net.pbtxt") : "");
  779. Net net = readNetFromTensorflow(netPath, netConfig);
  780. }
  781. };
  782. TEST_P(Test_TensorFlow_diagnostics, not_implemented_layer)
  783. {
  784. runFailingTensorFlowNet("not_implemented_layer");
  785. }
  786. TEST_P(Test_TensorFlow_diagnostics, broken_parameters)
  787. {
  788. runFailingTensorFlowNet("broken_layer");
  789. }
  790. INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_diagnostics, dnnBackendsAndTargets());
  791. class Test_TensorFlow_nets : public DNNTestLayer {};
  792. TEST_P(Test_TensorFlow_nets, MobileNet_SSD)
  793. {
  794. #if defined(INF_ENGINE_RELEASE)
  795. if (target == DNN_TARGET_MYRIAD)
  796. {
  797. #if INF_ENGINE_VER_MAJOR_GE(2019020000)
  798. if (getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  799. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X,
  800. backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
  801. CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
  802. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH,
  803. CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  804. #endif
  805. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  806. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  807. }
  808. #endif
  809. checkBackend();
  810. std::string imgPath = findDataFile("dnn/street.png");
  811. std::string netConfig = findDataFile("dnn/ssd_mobilenet_v1_coco.pbtxt");
  812. std::string netPath = findDataFile("dnn/ssd_mobilenet_v1_coco.pb", false);
  813. Mat inp;
  814. resize(imread(imgPath), inp, Size(300, 300));
  815. inp = blobFromImage(inp, 1.0f / 127.5, Size(), Scalar(127.5, 127.5, 127.5), true);
  816. Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/ssd_mobilenet_v1_coco.detection_out.npy"));
  817. Net net = readNetFromTensorflow(netPath, netConfig);
  818. net.setPreferableBackend(backend);
  819. net.setPreferableTarget(target);
  820. net.setInput(inp);
  821. Mat out = net.forward();
  822. double scoreDiff = default_l1, iouDiff = default_lInf;
  823. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
  824. {
  825. scoreDiff = 0.01;
  826. iouDiff = 0.1;
  827. }
  828. else if (target == DNN_TARGET_CUDA_FP16)
  829. {
  830. iouDiff = 0.04;
  831. }
  832. normAssertDetections(ref, out, "", 0.2, scoreDiff, iouDiff);
  833. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE >= 2019010000
  834. expectNoFallbacksFromIE(net);
  835. #endif
  836. }
  837. TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
  838. {
  839. applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
  840. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2019010000)
  841. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD &&
  842. getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  843. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  844. #endif
  845. checkBackend();
  846. Mat img = imread(findDataFile("dnn/street.png"));
  847. std::string proto = findDataFile("dnn/ssd_inception_v2_coco_2017_11_17.pbtxt");
  848. std::string model = findDataFile("dnn/ssd_inception_v2_coco_2017_11_17.pb", false);
  849. Net net = readNetFromTensorflow(model, proto);
  850. Mat blob = blobFromImage(img, 1.0f, Size(300, 300), Scalar(), true, false);
  851. net.setPreferableBackend(backend);
  852. net.setPreferableTarget(target);
  853. net.setInput(blob);
  854. // Output has shape 1x1xNx7 where N - number of detections.
  855. // An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
  856. Mat out = net.forward();
  857. Mat ref = (Mat_<float>(5, 7) << 0, 1, 0.90176028, 0.19872092, 0.36311883, 0.26461923, 0.63498729,
  858. 0, 3, 0.93569964, 0.64865261, 0.45906419, 0.80675775, 0.65708131,
  859. 0, 3, 0.75838411, 0.44668293, 0.45907149, 0.49459291, 0.52197015,
  860. 0, 10, 0.95932811, 0.38349164, 0.32528657, 0.40387636, 0.39165527,
  861. 0, 10, 0.93973452, 0.66561931, 0.37841269, 0.68074018, 0.42907384);
  862. double scoreDiff = default_l1, iouDiff = default_lInf;
  863. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
  864. {
  865. scoreDiff = 0.0097;
  866. iouDiff = 0.09;
  867. }
  868. else if (target == DNN_TARGET_CUDA_FP16)
  869. {
  870. scoreDiff = 6e-3;
  871. iouDiff = 0.05;
  872. }
  873. normAssertDetections(ref, out, "", 0.5, scoreDiff, iouDiff);
  874. expectNoFallbacksFromIE(net);
  875. }
  876. TEST_P(Test_TensorFlow_nets, MobileNet_v1_SSD)
  877. {
  878. checkBackend();
  879. std::string proto = findDataFile("dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt");
  880. std::string model = findDataFile("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", false);
  881. Net net = readNetFromTensorflow(model, proto);
  882. Mat img = imread(findDataFile("dnn/dog416.png"));
  883. Mat blob = blobFromImage(img, 1.0f, Size(300, 300), Scalar(), true, false);
  884. net.setPreferableBackend(backend);
  885. net.setPreferableTarget(target);
  886. net.setInput(blob);
  887. Mat out = net.forward();
  888. Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/ssd_mobilenet_v1_coco_2017_11_17.detection_out.npy"));
  889. float scoreDiff = 1.5e-5, iouDiff = 1e-3;
  890. float detectionConfThresh = (target == DNN_TARGET_MYRIAD) ? 0.35 : 0.3;
  891. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
  892. {
  893. scoreDiff = 0.011;
  894. iouDiff = 0.012;
  895. }
  896. else if (target == DNN_TARGET_CUDA_FP16)
  897. {
  898. scoreDiff = 0.006;
  899. iouDiff = 0.01;
  900. }
  901. #if defined(INF_ENGINE_RELEASE)
  902. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD &&
  903. getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  904. {
  905. scoreDiff = 0.061;
  906. iouDiff = 0.12;
  907. detectionConfThresh = 0.36;
  908. }
  909. #endif
  910. normAssertDetections(ref, out, "", detectionConfThresh, scoreDiff, iouDiff);
  911. expectNoFallbacksFromIE(net);
  912. }
  913. TEST_P(Test_TensorFlow_nets, Faster_RCNN_inception_v2_coco_2018_01_28)
  914. {
  915. applyTestTag(
  916. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB),
  917. CV_TEST_TAG_LONG,
  918. CV_TEST_TAG_DEBUG_VERYLONG
  919. );
  920. #ifdef INF_ENGINE_RELEASE
  921. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 &&
  922. (INF_ENGINE_VER_MAJOR_LT(2019020000) || target != DNN_TARGET_CPU))
  923. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  924. if (INF_ENGINE_VER_MAJOR_GT(2019030000) &&
  925. backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  926. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  927. #endif
  928. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  929. // segfault: inference-engine/thirdparty/clDNN/src/gpu/detection_output_cpu.cpp:111:
  930. // Assertion `prior_height > 0' failed.
  931. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  932. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  933. #endif
  934. if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
  935. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
  936. if (target == DNN_TARGET_CPU_FP16)
  937. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  938. checkBackend();
  939. double scoresDiff = 1e-5;
  940. double iouDiff = 1e-4;
  941. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  942. {
  943. scoresDiff = 0.02;
  944. iouDiff = 0.1;
  945. }
  946. std::string name = "faster_rcnn_inception_v2_coco_2018_01_28";
  947. {
  948. std::string proto = findDataFile("dnn/" + name + ".pbtxt");
  949. std::string model = findDataFile("dnn/" + name + ".pb", false);
  950. Net net = readNetFromTensorflow(model, proto);
  951. net.setPreferableBackend(backend);
  952. net.setPreferableTarget(target);
  953. Mat img = imread(findDataFile("dnn/dog416.png"));
  954. Mat blob = blobFromImage(img, 1.0f, Size(800, 600), Scalar(), true, false);
  955. net.setInput(blob);
  956. Mat out = net.forward();
  957. Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/" + name + ".detection_out.npy"));
  958. // accuracy (both OpenCV & IE)
  959. if (target == DNN_TARGET_OPENCL_FP16)
  960. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  961. if (target == DNN_TARGET_CPU_FP16)
  962. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  963. normAssertDetections(ref, out, name.c_str(), 0.3, scoresDiff, iouDiff);
  964. }
  965. }
  966. TEST_P(Test_TensorFlow_nets, Faster_RCNN_resnet50_coco_2018_01_28)
  967. {
  968. applyTestTag(
  969. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB),
  970. CV_TEST_TAG_LONG,
  971. CV_TEST_TAG_DEBUG_VERYLONG
  972. );
  973. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  974. // [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep < subgraphs.size()
  975. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  976. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  977. // [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep < subgraphs.size()
  978. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  979. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  980. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  981. );
  982. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  983. // [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep++ < subgraphs.size()
  984. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  985. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  986. // IE exception: Ngraph operation Transpose with name FirstStageBoxPredictor/ClassPredictor/reshape_1/nhwc has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  987. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  988. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  989. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  990. );
  991. #elif defined(INF_ENGINE_RELEASE)
  992. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 &&
  993. (INF_ENGINE_VER_MAJOR_LT(2019020000) || target != DNN_TARGET_CPU))
  994. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  995. if (INF_ENGINE_VER_MAJOR_GT(2019030000) &&
  996. backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  997. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  998. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  999. // segfault: inference-engine/thirdparty/clDNN/src/gpu/detection_output_cpu.cpp:111:
  1000. // Assertion `prior_height > 0' failed.
  1001. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1002. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1003. #endif
  1004. #endif
  1005. if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
  1006. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
  1007. checkBackend();
  1008. double scoresDiff = backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ? 2.9e-5 : 1e-5;
  1009. double iouDiff = 1e-4;
  1010. if (target == DNN_TARGET_CUDA)
  1011. {
  1012. scoresDiff = 0.06;
  1013. iouDiff = 0.08;
  1014. }
  1015. std::string name = "faster_rcnn_resnet50_coco_2018_01_28";
  1016. {
  1017. std::string proto = findDataFile("dnn/" + name + ".pbtxt");
  1018. std::string model = findDataFile("dnn/" + name + ".pb", false);
  1019. Net net = readNetFromTensorflow(model, proto);
  1020. net.setPreferableBackend(backend);
  1021. net.setPreferableTarget(target);
  1022. Mat img = imread(findDataFile("dnn/dog416.png"));
  1023. Mat blob = blobFromImage(img, 1.0f, Size(800, 600), Scalar(), true, false);
  1024. net.setInput(blob);
  1025. Mat out = net.forward();
  1026. Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/" + name + ".detection_out.npy"));
  1027. // accuracy
  1028. if (target == DNN_TARGET_OPENCL_FP16)
  1029. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  1030. if (target == DNN_TARGET_CPU_FP16)
  1031. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  1032. normAssertDetections(ref, out, name.c_str(), 0.3, scoresDiff, iouDiff);
  1033. }
  1034. }
  1035. TEST_P(Test_TensorFlow_nets, MobileNet_v1_SSD_PPN)
  1036. {
  1037. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
  1038. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  1039. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1040. CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1041. #endif
  1042. checkBackend();
  1043. std::string proto = findDataFile("dnn/ssd_mobilenet_v1_ppn_coco.pbtxt");
  1044. std::string model = findDataFile("dnn/ssd_mobilenet_v1_ppn_coco.pb", false);
  1045. Net net = readNetFromTensorflow(model, proto);
  1046. Mat img = imread(findDataFile("dnn/dog416.png"));
  1047. Mat ref = blobFromNPY(findDataFile("dnn/tensorflow/ssd_mobilenet_v1_ppn_coco.detection_out.npy"));
  1048. Mat blob = blobFromImage(img, 1.0f, Size(300, 300), Scalar(), true, false);
  1049. net.setPreferableBackend(backend);
  1050. net.setPreferableTarget(target);
  1051. net.setInput(blob);
  1052. Mat out = net.forward();
  1053. double scoreDiff = 1.1e-5, iouDiff = default_lInf;
  1054. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
  1055. {
  1056. scoreDiff = 0.048;
  1057. iouDiff = 0.058;
  1058. }
  1059. else if (target == DNN_TARGET_CUDA_FP16)
  1060. {
  1061. scoreDiff = 0.006;
  1062. iouDiff = 0.05;
  1063. }
  1064. normAssertDetections(ref, out, "", 0.45, scoreDiff, iouDiff);
  1065. expectNoFallbacksFromIE(net);
  1066. }
  1067. TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
  1068. {
  1069. checkBackend();
  1070. std::string proto = findDataFile("dnn/opencv_face_detector.pbtxt");
  1071. std::string model = findDataFile("dnn/opencv_face_detector_uint8.pb", false);
  1072. Net net = readNetFromTensorflow(model, proto);
  1073. Mat img = imread(findDataFile("gpu/lbpcascade/er.png"));
  1074. Mat blob = blobFromImage(img, 1.0, Size(), Scalar(104.0, 177.0, 123.0), false, false);
  1075. net.setPreferableBackend(backend);
  1076. net.setPreferableTarget(target);
  1077. net.setInput(blob);
  1078. // Output has shape 1x1xNx7 where N - number of detections.
  1079. // An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
  1080. Mat out = net.forward();
  1081. // References are from test for Caffe model.
  1082. Mat ref = (Mat_<float>(6, 7) << 0, 1, 0.99520785, 0.80997437, 0.16379407, 0.87996572, 0.26685631,
  1083. 0, 1, 0.9934696, 0.2831718, 0.50738752, 0.345781, 0.5985168,
  1084. 0, 1, 0.99096733, 0.13629119, 0.24892329, 0.19756334, 0.3310290,
  1085. 0, 1, 0.98977017, 0.23901358, 0.09084064, 0.29902688, 0.1769477,
  1086. 0, 1, 0.97203469, 0.67965847, 0.06876482, 0.73999709, 0.1513494,
  1087. 0, 1, 0.95097077, 0.51901293, 0.45863652, 0.5777427, 0.5347801);
  1088. double scoreDiff = 3.4e-3, iouDiff = 1e-2;
  1089. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
  1090. {
  1091. scoreDiff = 4e-3;
  1092. iouDiff = 0.024;
  1093. }
  1094. else if (target == DNN_TARGET_CUDA_FP16)
  1095. {
  1096. scoreDiff = 4e-3;
  1097. iouDiff = 0.02;
  1098. }
  1099. normAssertDetections(ref, out, "", 0.9, scoreDiff, iouDiff);
  1100. expectNoFallbacksFromIE(net);
  1101. }
  1102. // inp = cv.imread('opencv_extra/testdata/cv/ximgproc/sources/08.png')
  1103. // inp = inp[:,:,[2, 1, 0]].astype(np.float32).reshape(1, 512, 512, 3)
  1104. // outs = sess.run([sess.graph.get_tensor_by_name('feature_fusion/Conv_7/Sigmoid:0'),
  1105. // sess.graph.get_tensor_by_name('feature_fusion/concat_3:0')],
  1106. // feed_dict={'input_images:0': inp})
  1107. // scores = np.ascontiguousarray(outs[0].transpose(0, 3, 1, 2))
  1108. // geometry = np.ascontiguousarray(outs[1].transpose(0, 3, 1, 2))
  1109. // np.save('east_text_detection.scores.npy', scores)
  1110. // np.save('east_text_detection.geometry.npy', geometry)
  1111. TEST_P(Test_TensorFlow_nets, EAST_text_detection)
  1112. {
  1113. applyTestTag(
  1114. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
  1115. CV_TEST_TAG_DEBUG_LONG
  1116. );
  1117. #if defined(INF_ENGINE_RELEASE)
  1118. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  1119. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1120. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1121. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1122. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL_FP16 &&
  1123. (INF_ENGINE_VER_MAJOR_EQ(2019020000) || INF_ENGINE_VER_MAJOR_GE(2020010000))
  1124. )
  1125. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1126. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16)
  1127. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1128. #endif
  1129. checkBackend();
  1130. std::string netPath = findDataFile("dnn/frozen_east_text_detection.pb", false);
  1131. std::string imgPath = findDataFile("cv/ximgproc/sources/08.png");
  1132. std::string refScoresPath = findDataFile("dnn/east_text_detection.scores.npy");
  1133. std::string refGeometryPath = findDataFile("dnn/east_text_detection.geometry.npy");
  1134. Net net = readNet(netPath);
  1135. net.setPreferableBackend(backend);
  1136. net.setPreferableTarget(target);
  1137. Mat img = imread(imgPath);
  1138. Mat inp = blobFromImage(img, 1.0, Size(), Scalar(123.68, 116.78, 103.94), true, false);
  1139. net.setInput(inp);
  1140. std::vector<Mat> outs;
  1141. std::vector<String> outNames(2);
  1142. outNames[0] = "feature_fusion/Conv_7/Sigmoid";
  1143. outNames[1] = "feature_fusion/concat_3";
  1144. net.forward(outs, outNames);
  1145. Mat scores = outs[0];
  1146. Mat geometry = outs[1];
  1147. // Scores are in range [0, 1]. Geometry values are in range [-0.23, 290]
  1148. double l1_scores = default_l1, lInf_scores = default_lInf;
  1149. double l1_geometry = default_l1, lInf_geometry = default_lInf;
  1150. if (target == DNN_TARGET_OPENCL_FP16)
  1151. {
  1152. lInf_scores = backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ? 0.16 : 0.11;
  1153. l1_geometry = 0.28; lInf_geometry = 5.94;
  1154. }
  1155. else if (target == DNN_TARGET_MYRIAD)
  1156. {
  1157. lInf_scores = 0.41;
  1158. l1_geometry = 0.28; lInf_geometry = 5.94;
  1159. }
  1160. else if (target == DNN_TARGET_CUDA_FP16)
  1161. {
  1162. lInf_scores = 0.1;
  1163. l1_geometry = 0.3; lInf_geometry = 7;
  1164. }
  1165. else if (target == DNN_TARGET_CPU_FP16)
  1166. {
  1167. lInf_scores = 0.1;
  1168. l1_geometry = 0.28; lInf_geometry = 5.94;
  1169. }
  1170. else
  1171. {
  1172. l1_geometry = 1e-4, lInf_geometry = 4.3e-3;
  1173. }
  1174. normAssert(scores, blobFromNPY(refScoresPath), "scores", l1_scores, lInf_scores);
  1175. normAssert(geometry, blobFromNPY(refGeometryPath), "geometry", l1_geometry, lInf_geometry);
  1176. expectNoFallbacksFromIE(net);
  1177. }
  1178. INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_nets, dnnBackendsAndTargets());
  1179. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_single_conv)
  1180. {
  1181. float l1 = 0.00078, lInf = 0.012;
  1182. runTensorFlowNet("fp16_single_conv", false, l1, lInf);
  1183. }
  1184. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_max_pool_odd_same)
  1185. {
  1186. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  1187. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  1188. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1189. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1190. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  1191. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1192. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1193. #endif
  1194. float l1 = 0.00078, lInf = 0.012;
  1195. runTensorFlowNet("fp16_max_pool_odd_same", false, l1, lInf);
  1196. }
  1197. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_eltwise_add_mul)
  1198. {
  1199. float l1 = 0.00078, lInf = 0.012;
  1200. runTensorFlowNet("fp16_eltwise_add_mul", false, l1, lInf);
  1201. }
  1202. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_pad_and_concat)
  1203. {
  1204. float l1 = 0.00078, lInf = 0.012;
  1205. runTensorFlowNet("fp16_pad_and_concat", false, l1, lInf);
  1206. }
  1207. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_padding_valid)
  1208. {
  1209. float l1 = 0.00078, lInf = 0.012;
  1210. if (target == DNN_TARGET_CPU_FP16)
  1211. l1 = 0.00083;
  1212. runTensorFlowNet("fp16_padding_valid", false, l1, lInf);
  1213. }
  1214. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_max_pool_even)
  1215. {
  1216. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  1217. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  1218. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1219. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1220. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  1221. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1222. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1223. #endif
  1224. float l1 = 0.00078, lInf = 0.012;
  1225. // Reference output values are in range [0.0889, 1.651]
  1226. runTensorFlowNet("fp16_max_pool_even", false, (target == DNN_TARGET_MYRIAD) ? 0.003 : l1, lInf);
  1227. }
  1228. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_deconvolution)
  1229. {
  1230. float l1 = 0.00078, lInf = 0.012;
  1231. if (target == DNN_TARGET_MYRIAD) {
  1232. l1 = 0.0041;
  1233. lInf = 0.024;
  1234. }
  1235. // Reference output values are in range [0, 10.75]
  1236. runTensorFlowNet("fp16_deconvolution", false, l1, lInf);
  1237. }
  1238. TEST_P(Test_TensorFlow_layers, fp16_weights_fp16_max_pool_odd_valid)
  1239. {
  1240. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  1241. // [ GENERAL_ERROR ] AssertionFailed: !expired()
  1242. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1243. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1244. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
  1245. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1246. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1247. #endif
  1248. float l1 = 0.00078, lInf = 0.012;
  1249. if (target == DNN_TARGET_MYRIAD) {
  1250. l1 = 0.0041;
  1251. lInf = 0.024;
  1252. }
  1253. // Reference output values are in range [0.418, 2.297]
  1254. runTensorFlowNet("fp16_max_pool_odd_valid", false, l1, lInf);
  1255. }
  1256. TEST_P(Test_TensorFlow_layers, fp16_padding_same)
  1257. {
  1258. float l1 = 7e-4, lInf = 4e-3;
  1259. if (target == DNN_TARGET_CPU_FP16)
  1260. lInf = 5e-3;
  1261. // Reference output values are in range [-3.504, -0.002]
  1262. runTensorFlowNet("fp16_padding_same", false, l1, lInf);
  1263. }
  1264. TEST_P(Test_TensorFlow_layers, defun)
  1265. {
  1266. runTensorFlowNet("defun_dropout");
  1267. }
  1268. TEST_P(Test_TensorFlow_layers, quantized)
  1269. {
  1270. runTensorFlowNet("uint8_single_conv");
  1271. }
  1272. TEST_P(Test_TensorFlow_layers, lstm)
  1273. {
  1274. if(backend == DNN_BACKEND_CUDA)
  1275. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); /* not supported */
  1276. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  1277. // Xlink, Failed to allocate graph: NC_ERROR
  1278. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1279. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1280. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1281. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1282. {
  1283. // Exception: Ngraph operation Reshape with name Reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  1284. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  1285. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1286. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1287. );
  1288. // Xlink
  1289. if (target == DNN_TARGET_MYRIAD)
  1290. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1291. }
  1292. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1293. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1294. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1295. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1296. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1297. #endif
  1298. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  1299. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  1300. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_CPU_FP16)
  1301. applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  1302. runTensorFlowNet("lstm", true);
  1303. runTensorFlowNet("lstm", true, 0.0, 0.0, true);
  1304. }
  1305. TEST_P(Test_TensorFlow_layers, split)
  1306. {
  1307. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  1308. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1309. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1310. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1311. runTensorFlowNet("split");
  1312. }
  1313. TEST_P(Test_TensorFlow_layers, split_equals)
  1314. {
  1315. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1316. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1317. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1318. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1319. runTensorFlowNet("split_equals");
  1320. }
  1321. TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor)
  1322. {
  1323. runTensorFlowNet("resize_nearest_neighbor");
  1324. }
  1325. TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_keras_upsampling2d)
  1326. {
  1327. runTensorFlowNet("keras_upsampling2d");
  1328. }
  1329. TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_align_corners)
  1330. {
  1331. runTensorFlowNet("resize_nearest_neighbor", false, 0.0, 0.0, false, "_align_corners");
  1332. }
  1333. TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_half_pixel)
  1334. {
  1335. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1336. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1337. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1338. #endif
  1339. runTensorFlowNet("resize_nearest_neighbor", false, 0.0, 0.0, false, "_half_pixel");
  1340. }
  1341. TEST_P(Test_TensorFlow_layers, fused_resize_conv)
  1342. {
  1343. runTensorFlowNet("fused_resize_conv");
  1344. }
  1345. TEST_P(Test_TensorFlow_layers, slice_crop2d)
  1346. {
  1347. double l1 = target == DNN_TARGET_MYRIAD ? 4.9e-3 : default_l1;
  1348. runTensorFlowNet("crop2d", false, l1);
  1349. }
  1350. TEST_P(Test_TensorFlow_layers, slice_4d)
  1351. {
  1352. runTensorFlowNet("slice_4d");
  1353. }
  1354. TEST_P(Test_TensorFlow_layers, slice_strided)
  1355. {
  1356. runTensorFlowNet("strided_slice");
  1357. }
  1358. TEST_P(Test_TensorFlow_layers, softmax_keras)
  1359. {
  1360. runTensorFlowNet("keras_softmax");
  1361. }
  1362. TEST_P(Test_TensorFlow_layers, softmax_slim)
  1363. {
  1364. runTensorFlowNet("slim_softmax");
  1365. }
  1366. TEST_P(Test_TensorFlow_layers, softmax_slim_v2)
  1367. {
  1368. #if defined(INF_ENGINE_RELEASE)
  1369. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD &&
  1370. getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
  1371. )
  1372. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1373. #endif
  1374. runTensorFlowNet("slim_softmax_v2");
  1375. }
  1376. TEST_P(Test_TensorFlow_layers, relu6)
  1377. {
  1378. runTensorFlowNet("keras_relu6");
  1379. runTensorFlowNet("keras_relu6", /*hasText*/ true);
  1380. }
  1381. TEST_P(Test_TensorFlow_layers, subpixel)
  1382. {
  1383. #if defined(INF_ENGINE_RELEASE)
  1384. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1385. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1386. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1387. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1388. #endif
  1389. runTensorFlowNet("subpixel");
  1390. }
  1391. TEST_P(Test_TensorFlow_layers, keras_mobilenet_head)
  1392. {
  1393. runTensorFlowNet("keras_mobilenet_head");
  1394. runTensorFlowNet("keras_learning_phase");
  1395. }
  1396. // TF case: align_corners=False, half_pixel_centers=False
  1397. TEST_P(Test_TensorFlow_layers, resize_bilinear)
  1398. {
  1399. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  1400. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1401. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1402. #endif
  1403. runTensorFlowNet("resize_bilinear");
  1404. }
  1405. // TF case: align_corners=True, half_pixel_centers=False
  1406. TEST_P(Test_TensorFlow_layers, resize_bilinear_align_corners)
  1407. {
  1408. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
  1409. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  1410. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // exception
  1411. #endif
  1412. runTensorFlowNet("resize_bilinear",
  1413. false, 0.0, 0.0, false, // default parameters
  1414. "_align_corners");
  1415. }
  1416. // TF case: align_corners=False, half_pixel_centers=True
  1417. TEST_P(Test_TensorFlow_layers, resize_bilinear_half_pixel)
  1418. {
  1419. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1420. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1421. runTensorFlowNet("resize_bilinear", false, 0.0, 0.0, false, "_half_pixel");
  1422. }
  1423. // TF case: align_corners=False, half_pixel_centers=False
  1424. TEST_P(Test_TensorFlow_layers, resize_bilinear_factor)
  1425. {
  1426. runTensorFlowNet("resize_bilinear_factor");
  1427. }
  1428. // TF case: align_corners=False, half_pixel_centers=True
  1429. TEST_P(Test_TensorFlow_layers, resize_bilinear_factor_half_pixel)
  1430. {
  1431. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1432. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1433. runTensorFlowNet("resize_bilinear_factor", false, 0.0, 0.0, false, "_half_pixel");
  1434. }
  1435. // TF case: align_corners=True, half_pixel_centers=False
  1436. TEST_P(Test_TensorFlow_layers, resize_bilinear_factor_align_corners)
  1437. {
  1438. runTensorFlowNet("resize_bilinear_factor", false, 0.0, 0.0, false, "_align_corners");
  1439. }
  1440. // TF case: align_corners=False, half_pixel_centers=False
  1441. TEST_P(Test_TensorFlow_layers, resize_bilinear_down)
  1442. {
  1443. runTensorFlowNet("resize_bilinear_down");
  1444. }
  1445. TEST_P(Test_TensorFlow_layers, resize_concat_optimization)
  1446. {
  1447. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1448. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) // Exception: Function contains several inputs and outputs with one friendly name! (HETERO bug?)
  1449. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1450. #endif
  1451. runTensorFlowNet("resize_concat_optimization");
  1452. }
  1453. TEST_P(Test_TensorFlow_layers, tf2_dense)
  1454. {
  1455. runTensorFlowNet("tf2_dense");
  1456. }
  1457. TEST_P(Test_TensorFlow_layers, clip_by_value)
  1458. {
  1459. runTensorFlowNet("clip_by_value");
  1460. }
  1461. TEST_P(Test_TensorFlow_layers, tf2_prelu)
  1462. {
  1463. if (backend == DNN_BACKEND_CUDA)
  1464. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA); // not supported; only across channels is supported
  1465. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
  1466. // Eltwise executor got invalid input/output dims configuration
  1467. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU)
  1468. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1469. // Input prelu:StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add hasn't been found in primitiveIDs map
  1470. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  1471. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1472. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1473. );
  1474. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  1475. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1476. {
  1477. // IE exception: Input prelu:StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add hasn't been found in primitiveIDs map
  1478. if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)
  1479. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  1480. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  1481. );
  1482. // IE exception: Eltwise node with name `StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add` has invalid input/output dims configuration
  1483. if (target == DNN_TARGET_CPU)
  1484. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  1485. }
  1486. #elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  1487. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  1488. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1489. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1490. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1491. #endif
  1492. runTensorFlowNet("tf2_prelu");
  1493. }
  1494. TEST_P(Test_TensorFlow_layers, tf2_permute_nhwc_ncwh)
  1495. {
  1496. runTensorFlowNet("tf2_permute_nhwc_ncwh");
  1497. }
  1498. TEST_P(Test_TensorFlow_layers, squeeze)
  1499. {
  1500. #if defined(INF_ENGINE_RELEASE)
  1501. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  1502. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
  1503. )
  1504. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1505. #endif
  1506. int inpShapes[][4] = {{1, 3, 4, 2}, {1, 3, 1, 2}, {1, 3, 4, 1}, {1, 3, 4, 1}}; // TensorFlow's shape (NHWC)
  1507. int outShapes[][3] = {{3, 4, 2}, {1, 3, 2}, {1, 3, 4}, {1, 3, 4}};
  1508. int squeeze_dims[] = {0, 2, 3, -1};
  1509. for (int i = 0; i < 4; ++i)
  1510. {
  1511. SCOPED_TRACE(format("i=%d", i));
  1512. std::string pbtxt =
  1513. "node { name: \"input\" op: \"Placeholder\""
  1514. "attr { key: \"data_format\" value { s: \"NHWC\" } } }"
  1515. "node { name: \"squeeze\" op: \"Squeeze\" input: \"input\""
  1516. "attr { key: \"squeeze_dims\" value { list { i:" + format("%d", squeeze_dims[i]) + "}}}}";
  1517. Net net = readNetFromTensorflow(0, 0, pbtxt.c_str(), pbtxt.size());
  1518. net.setPreferableBackend(backend);
  1519. net.setPreferableTarget(target);
  1520. Mat tfInp(4, &inpShapes[i][0], CV_32F);
  1521. randu(tfInp, -1, 1);
  1522. // NHWC to NCHW
  1523. CV_Assert(inpShapes[i][0] == 1);
  1524. std::swap(inpShapes[i][2], inpShapes[i][3]);
  1525. std::swap(inpShapes[i][1], inpShapes[i][2]);
  1526. Mat cvInp = tfInp.reshape(1, tfInp.total() / inpShapes[i][1]).t();
  1527. cvInp = cvInp.reshape(1, 4, &inpShapes[i][0]);
  1528. net.setInput(cvInp);
  1529. Mat out = net.forward();
  1530. normAssert(tfInp.reshape(1, 3, &outShapes[i][0]), out, "", default_l1, default_lInf);
  1531. }
  1532. }
  1533. INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_layers, dnnBackendsAndTargets());
  1534. TEST(Test_TensorFlow, two_inputs)
  1535. {
  1536. Net net = readNet(path("two_inputs_net.pbtxt"));
  1537. net.setPreferableBackend(DNN_BACKEND_OPENCV);
  1538. Mat firstInput(2, 3, CV_32FC1), secondInput(2, 3, CV_32FC1);
  1539. randu(firstInput, -1, 1);
  1540. randu(secondInput, -1, 1);
  1541. net.setInput(firstInput, "first_input");
  1542. net.setInput(secondInput, "second_input");
  1543. Mat out = net.forward();
  1544. normAssert(out, firstInput + secondInput);
  1545. }
  1546. TEST_P(Test_TensorFlow_nets, Mask_RCNN)
  1547. {
  1548. static const double kMaskThreshold = 0.5;
  1549. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  1550. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  1551. if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  1552. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  1553. if (target == DNN_TARGET_CUDA_FP16)
  1554. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
  1555. applyTestTag(CV_TEST_TAG_MEMORY_1GB, CV_TEST_TAG_DEBUG_VERYLONG);
  1556. Mat img = imread(findDataFile("dnn/street.png"));
  1557. std::string proto = findDataFile("dnn/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt");
  1558. std::string model = findDataFile("dnn/mask_rcnn_inception_v2_coco_2018_01_28.pb", false);
  1559. Net net = readNetFromTensorflow(model, proto);
  1560. Mat refDetections = blobFromNPY(path("mask_rcnn_inception_v2_coco_2018_01_28.detection_out.npy"));
  1561. Mat refMasks = blobFromNPY(path("mask_rcnn_inception_v2_coco_2018_01_28.detection_masks.npy"));
  1562. Mat blob = blobFromImage(img, 1.0f, Size(800, 800), Scalar(), true, false);
  1563. net.setPreferableBackend(backend);
  1564. net.setPreferableTarget(target);
  1565. net.setInput(blob);
  1566. // Mask-RCNN predicts bounding boxes and segmentation masks.
  1567. std::vector<String> outNames(2);
  1568. outNames[0] = "detection_out_final";
  1569. outNames[1] = "detection_masks";
  1570. std::vector<Mat> outs;
  1571. net.forward(outs, outNames);
  1572. Mat outDetections = outs[0];
  1573. Mat outMasks = outs[1];
  1574. double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16) ? 0.2 : 2e-5;
  1575. double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16) ? 0.018 : default_lInf;
  1576. normAssertDetections(refDetections, outDetections, "", /*threshold for zero confidence*/1e-5, scoreDiff, iouDiff);
  1577. // Output size of masks is NxCxHxW where
  1578. // N - number of detected boxes
  1579. // C - number of classes (excluding background)
  1580. // HxW - segmentation shape
  1581. const int numDetections = outDetections.size[2];
  1582. int masksSize[] = {1, numDetections, outMasks.size[2], outMasks.size[3]};
  1583. Mat masks(4, &masksSize[0], CV_32F);
  1584. std::vector<cv::Range> srcRanges(4, cv::Range::all());
  1585. std::vector<cv::Range> dstRanges(4, cv::Range::all());
  1586. outDetections = outDetections.reshape(1, outDetections.total() / 7);
  1587. for (int i = 0; i < numDetections; ++i)
  1588. {
  1589. // Get a class id for this bounding box and copy mask only for that class.
  1590. int classId = static_cast<int>(outDetections.at<float>(i, 1));
  1591. srcRanges[0] = dstRanges[1] = cv::Range(i, i + 1);
  1592. srcRanges[1] = cv::Range(classId, classId + 1);
  1593. outMasks(srcRanges).copyTo(masks(dstRanges));
  1594. }
  1595. cv::Range topRefMasks[] = {Range::all(), Range(0, numDetections), Range::all(), Range::all()};
  1596. refMasks = refMasks(&topRefMasks[0]);
  1597. // make binary masks
  1598. cv::threshold(masks.reshape(1, 1), masks, kMaskThreshold, 1, THRESH_BINARY);
  1599. cv::threshold(refMasks.reshape(1, 1), refMasks, kMaskThreshold, 1, THRESH_BINARY);
  1600. double inter = cv::countNonZero(masks & refMasks);
  1601. double area = cv::countNonZero(masks | refMasks);
  1602. EXPECT_GE(inter / area, (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16) ? 0.98 : 0.99);
  1603. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  1604. expectNoFallbacks(net);
  1605. }
  1606. TEST_P(Test_TensorFlow_nets, EfficientDet)
  1607. {
  1608. if (target != DNN_TARGET_CPU)
  1609. {
  1610. if (target == DNN_TARGET_CPU_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_CPU_FP16);
  1611. if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  1612. if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL);
  1613. if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
  1614. }
  1615. checkBackend();
  1616. std::string proto = findDataFile("dnn/efficientdet-d0.pbtxt");
  1617. std::string model = findDataFile("dnn/efficientdet-d0.pb", false);
  1618. Net net = readNetFromTensorflow(model, proto);
  1619. Mat img = imread(findDataFile("dnn/dog416.png"));
  1620. Mat blob = blobFromImage(img, 1.0/255, Size(512, 512), Scalar(123.675, 116.28, 103.53));
  1621. net.setPreferableBackend(backend);
  1622. net.setPreferableTarget(target);
  1623. net.setInput(blob);
  1624. // Output has shape 1x1xNx7 where N - number of detections.
  1625. // An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
  1626. Mat out = net.forward();
  1627. // References are from test for TensorFlow model.
  1628. Mat ref = (Mat_<float>(3, 7) << 0, 1, 0.8437444, 0.153996080160141, 0.20534580945968628, 0.7463544607162476, 0.7414066195487976,
  1629. 0, 17, 0.8245924, 0.16657517850399017, 0.3996818959712982, 0.4111558794975281, 0.9306337833404541,
  1630. 0, 7, 0.8039304, 0.6118435263633728, 0.13175517320632935, 0.9065558314323425, 0.2943994700908661);
  1631. double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 4e-3 : 1e-5;
  1632. double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 2e-3 : 1e-4;
  1633. if (target == DNN_TARGET_CUDA_FP16)
  1634. {
  1635. scoreDiff = 0.002;
  1636. iouDiff = 0.005;
  1637. }
  1638. normAssertDetections(ref, out, "", 0.5, scoreDiff, iouDiff);
  1639. expectNoFallbacksFromIE(net);
  1640. }
  1641. TEST(Test_TensorFlow_Importer, tf_graph_simplifier_buffer_overflow_21852)
  1642. {
  1643. uint8_t payload[] = {0x08, 0x08, 0x0a, 0x00, 0x0a, 0x00};
  1644. EXPECT_ANY_THROW(readNetFromTensorflow(reinterpret_cast<const char*>(payload), sizeof(payload) / sizeof(payload[0])));
  1645. }
  1646. // can be triggered with -fsanitize=address
  1647. TEST(Test_TensorFlow_Importer, tf_graph_simplifier_buffer_overflow_21947)
  1648. {
  1649. uint8_t payload[] = {0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00,
  1650. 0xba, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00,
  1651. 0x0a, 0xbd, 0x00, 0x1a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0xba,
  1652. 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00,
  1653. 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0xba, 0x0a, 0x00,
  1654. 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0xba,
  1655. 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00,
  1656. 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x2a, 0x00, 0xba, 0x0a, 0x00,
  1657. 0x0a, 0x00, 0x5d, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x0a, 0x40};
  1658. EXPECT_ANY_THROW(readNetFromTensorflow(reinterpret_cast<const char*>(payload), sizeof(payload) / sizeof(payload[0])));
  1659. }
  1660. }