test_backends.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018-2019, Intel Corporation, all rights reserved.
  6. // Third party copyrights are property of their respective owners.
  7. #include "test_precomp.hpp"
  8. #include "opencv2/core/ocl.hpp"
  9. namespace opencv_test { namespace {
  10. class DNNTestNetwork : public DNNTestLayer
  11. {
  12. public:
  13. void processNet(const std::string& weights, const std::string& proto,
  14. Size inpSize, const std::string& outputLayer = "",
  15. const std::string& halideScheduler = "",
  16. double l1 = 0.0, double lInf = 0.0)
  17. {
  18. // Create a common input blob.
  19. int blobSize[] = {1, 3, inpSize.height, inpSize.width};
  20. Mat inp(4, blobSize, CV_32FC1);
  21. randu(inp, 0.0f, 1.0f);
  22. processNet(weights, proto, inp, outputLayer, halideScheduler, l1, lInf);
  23. }
  24. void processNet(std::string weights, std::string proto,
  25. Mat inp, const std::string& outputLayer = "",
  26. std::string halideScheduler = "",
  27. double l1 = 0.0, double lInf = 0.0, double detectionConfThresh = 0.2)
  28. {
  29. checkBackend();
  30. l1 = l1 ? l1 : default_l1;
  31. lInf = lInf ? lInf : default_lInf;
  32. weights = findDataFile(weights, false);
  33. if (!proto.empty())
  34. proto = findDataFile(proto);
  35. // Create two networks - with default backend and target and a tested one.
  36. Net netDefault = readNet(weights, proto);
  37. netDefault.setPreferableBackend(DNN_BACKEND_OPENCV);
  38. netDefault.setInput(inp);
  39. Mat outDefault = netDefault.forward(outputLayer).clone();
  40. net = readNet(weights, proto);
  41. net.setInput(inp);
  42. net.setPreferableBackend(backend);
  43. net.setPreferableTarget(target);
  44. if (backend == DNN_BACKEND_HALIDE && !halideScheduler.empty())
  45. {
  46. halideScheduler = findDataFile(halideScheduler);
  47. net.setHalideScheduler(halideScheduler);
  48. }
  49. Mat out = net.forward(outputLayer).clone();
  50. check(outDefault, out, outputLayer, l1, lInf, detectionConfThresh, "First run");
  51. // Test 2: change input.
  52. float* inpData = (float*)inp.data;
  53. for (int i = 0; i < inp.size[0] * inp.size[1]; ++i)
  54. {
  55. Mat slice(inp.size[2], inp.size[3], CV_32F, inpData);
  56. cv::flip(slice, slice, 1);
  57. inpData += slice.total();
  58. }
  59. netDefault.setInput(inp);
  60. net.setInput(inp);
  61. outDefault = netDefault.forward(outputLayer).clone();
  62. out = net.forward(outputLayer).clone();
  63. check(outDefault, out, outputLayer, l1, lInf, detectionConfThresh, "Second run");
  64. }
  65. void check(Mat& ref, Mat& out, const std::string& outputLayer, double l1, double lInf,
  66. double detectionConfThresh, const char* msg)
  67. {
  68. if (outputLayer == "detection_out")
  69. {
  70. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  71. {
  72. // Inference Engine produces detections terminated by a row which starts from -1.
  73. out = out.reshape(1, out.total() / 7);
  74. int numDetections = 0;
  75. while (numDetections < out.rows && out.at<float>(numDetections, 0) != -1)
  76. {
  77. numDetections += 1;
  78. }
  79. out = out.rowRange(0, numDetections);
  80. }
  81. normAssertDetections(ref, out, msg, detectionConfThresh, l1, lInf);
  82. }
  83. else
  84. normAssert(ref, out, msg, l1, lInf);
  85. }
  86. Net net;
  87. };
  88. TEST_P(DNNTestNetwork, AlexNet)
  89. {
  90. applyTestTag(CV_TEST_TAG_MEMORY_1GB);
  91. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  92. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  93. processNet("dnn/bvlc_alexnet.caffemodel", "dnn/bvlc_alexnet.prototxt",
  94. Size(227, 227), "prob",
  95. target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_alexnet.yml" :
  96. "dnn/halide_scheduler_alexnet.yml");
  97. expectNoFallbacksFromIE(net);
  98. expectNoFallbacksFromCUDA(net);
  99. }
  100. TEST_P(DNNTestNetwork, ResNet_50)
  101. {
  102. applyTestTag(
  103. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
  104. CV_TEST_TAG_DEBUG_LONG
  105. );
  106. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  107. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  108. processNet("dnn/ResNet-50-model.caffemodel", "dnn/ResNet-50-deploy.prototxt",
  109. Size(224, 224), "prob",
  110. target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_resnet_50.yml" :
  111. "dnn/halide_scheduler_resnet_50.yml");
  112. expectNoFallbacksFromIE(net);
  113. expectNoFallbacksFromCUDA(net);
  114. }
  115. TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
  116. {
  117. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  118. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  119. processNet("dnn/squeezenet_v1.1.caffemodel", "dnn/squeezenet_v1.1.prototxt",
  120. Size(227, 227), "prob",
  121. target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_squeezenet_v1_1.yml" :
  122. "dnn/halide_scheduler_squeezenet_v1_1.yml");
  123. expectNoFallbacksFromIE(net);
  124. expectNoFallbacksFromCUDA(net);
  125. }
  126. TEST_P(DNNTestNetwork, GoogLeNet)
  127. {
  128. applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
  129. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  130. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  131. processNet("dnn/bvlc_googlenet.caffemodel", "dnn/bvlc_googlenet.prototxt",
  132. Size(224, 224), "prob");
  133. expectNoFallbacksFromIE(net);
  134. expectNoFallbacksFromCUDA(net);
  135. }
  136. TEST_P(DNNTestNetwork, Inception_5h)
  137. {
  138. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  139. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  140. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  141. double l1 = default_l1, lInf = default_lInf;
  142. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL))
  143. {
  144. l1 = 1.72e-5;
  145. lInf = 8e-4;
  146. }
  147. processNet("dnn/tensorflow_inception_graph.pb", "", Size(224, 224), "softmax2",
  148. target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_inception_5h.yml" :
  149. "dnn/halide_scheduler_inception_5h.yml",
  150. l1, lInf);
  151. expectNoFallbacksFromIE(net);
  152. expectNoFallbacksFromCUDA(net);
  153. }
  154. TEST_P(DNNTestNetwork, ENet)
  155. {
  156. applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
  157. if (backend == DNN_BACKEND_HALIDE) // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
  158. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  159. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
  160. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  161. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  162. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  163. if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16)
  164. applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16);
  165. if (backend == DNN_BACKEND_CUDA && target == DNN_TARGET_CUDA_FP16)
  166. applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
  167. processNet("dnn/Enet-model-best.net", "", Size(512, 512), "l367_Deconvolution",
  168. target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_enet.yml" :
  169. "dnn/halide_scheduler_enet.yml",
  170. 2e-5, 0.15);
  171. expectNoFallbacksFromCUDA(net);
  172. }
  173. TEST_P(DNNTestNetwork, MobileNet_SSD_Caffe)
  174. {
  175. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  176. if (backend == DNN_BACKEND_HALIDE)
  177. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  178. Mat sample = imread(findDataFile("dnn/street.png"));
  179. Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
  180. float scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 1.5e-2 : 0.0;
  181. float iouDiff = (target == DNN_TARGET_MYRIAD) ? 0.063 : 0.0;
  182. float detectionConfThresh = (target == DNN_TARGET_MYRIAD) ? 0.262 : FLT_MIN;
  183. processNet("dnn/MobileNetSSD_deploy.caffemodel", "dnn/MobileNetSSD_deploy.prototxt",
  184. inp, "detection_out", "", scoreDiff, iouDiff, detectionConfThresh);
  185. expectNoFallbacksFromIE(net);
  186. }
  187. TEST_P(DNNTestNetwork, MobileNet_SSD_Caffe_Different_Width_Height)
  188. {
  189. if (backend == DNN_BACKEND_HALIDE)
  190. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  191. #if defined(INF_ENGINE_RELEASE)
  192. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
  193. target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  194. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  195. #endif
  196. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
  197. // IE exception: Ngraph operation Transpose with name conv15_2_mbox_conf_perm has dynamic output shape on 0 port, but CPU plug-in supports only static shape
  198. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
  199. applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
  200. CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
  201. );
  202. #endif
  203. Mat sample = imread(findDataFile("dnn/street.png"));
  204. Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 560), Scalar(127.5, 127.5, 127.5), false);
  205. float scoreDiff = 0.0, iouDiff = 0.0;
  206. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  207. {
  208. scoreDiff = 0.029;
  209. iouDiff = 0.09;
  210. }
  211. else if (target == DNN_TARGET_CUDA_FP16)
  212. {
  213. scoreDiff = 0.03;
  214. iouDiff = 0.08;
  215. }
  216. processNet("dnn/MobileNetSSD_deploy.caffemodel", "dnn/MobileNetSSD_deploy.prototxt",
  217. inp, "detection_out", "", scoreDiff, iouDiff);
  218. expectNoFallbacksFromIE(net);
  219. }
  220. TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow)
  221. {
  222. applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
  223. if (backend == DNN_BACKEND_HALIDE)
  224. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  225. Mat sample = imread(findDataFile("dnn/street.png"));
  226. Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
  227. float detectionConfThresh = (target == DNN_TARGET_MYRIAD) ? 0.216 : 0.2;
  228. float scoreDiff = 0.0, iouDiff = 0.0;
  229. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  230. {
  231. scoreDiff = 0.095;
  232. iouDiff = 0.09;
  233. }
  234. else if (target == DNN_TARGET_CUDA_FP16)
  235. {
  236. scoreDiff = 0.007;
  237. iouDiff = 0.08;
  238. }
  239. processNet("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", "dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt",
  240. inp, "detection_out", "", scoreDiff, iouDiff, detectionConfThresh);
  241. expectNoFallbacksFromIE(net);
  242. }
  243. TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow_Different_Width_Height)
  244. {
  245. if (backend == DNN_BACKEND_HALIDE)
  246. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  247. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
  248. if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) &&
  249. target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  250. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
  251. #endif
  252. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000)
  253. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  254. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  255. #endif
  256. Mat sample = imread(findDataFile("dnn/street.png"));
  257. Mat inp = blobFromImage(sample, 1.0f, Size(300, 560), Scalar(), false);
  258. float scoreDiff = 0.0, iouDiff = 0.0;
  259. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  260. {
  261. scoreDiff = 0.013;
  262. iouDiff = 0.06;
  263. }
  264. else if (target == DNN_TARGET_CUDA_FP16)
  265. {
  266. scoreDiff = 0.007;
  267. iouDiff = 0.06;
  268. }
  269. processNet("dnn/ssd_mobilenet_v1_coco_2017_11_17.pb", "dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt",
  270. inp, "detection_out", "", scoreDiff, iouDiff);
  271. expectNoFallbacksFromIE(net);
  272. }
  273. TEST_P(DNNTestNetwork, MobileNet_SSD_v2_TensorFlow)
  274. {
  275. applyTestTag(target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB);
  276. if (backend == DNN_BACKEND_HALIDE)
  277. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  278. Mat sample = imread(findDataFile("dnn/street.png"));
  279. Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
  280. float scoreDiff = 2e-5, iouDiff = 0.0;
  281. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  282. {
  283. scoreDiff = 0.013;
  284. iouDiff = 0.062;
  285. }
  286. else if (target == DNN_TARGET_CUDA_FP16)
  287. {
  288. scoreDiff = 0.02;
  289. iouDiff = 0.07;
  290. }
  291. processNet("dnn/ssd_mobilenet_v2_coco_2018_03_29.pb", "dnn/ssd_mobilenet_v2_coco_2018_03_29.pbtxt",
  292. inp, "detection_out", "", scoreDiff, iouDiff, 0.25);
  293. expectNoFallbacksFromIE(net);
  294. }
  295. TEST_P(DNNTestNetwork, SSD_VGG16)
  296. {
  297. applyTestTag(CV_TEST_TAG_LONG, (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB),
  298. CV_TEST_TAG_DEBUG_VERYLONG);
  299. if (backend == DNN_BACKEND_HALIDE && target == DNN_TARGET_CPU)
  300. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE); // TODO HALIDE_CPU
  301. Mat sample = imread(findDataFile("dnn/street.png"));
  302. Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
  303. float scoreDiff = 0.0, iouDiff = 0.0;
  304. if (target == DNN_TARGET_OPENCL_FP16)
  305. {
  306. scoreDiff = 0.04;
  307. }
  308. else if (target == DNN_TARGET_MYRIAD)
  309. {
  310. scoreDiff = 0.0325;
  311. iouDiff = 0.032;
  312. }
  313. else if (target == DNN_TARGET_CUDA_FP16)
  314. {
  315. scoreDiff = 0.03;
  316. iouDiff = 0.13;
  317. }
  318. processNet("dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel",
  319. "dnn/ssd_vgg16.prototxt", inp, "detection_out", "", scoreDiff, iouDiff);
  320. expectNoFallbacksFromIE(net);
  321. }
  322. TEST_P(DNNTestNetwork, OpenPose_pose_coco)
  323. {
  324. applyTestTag(CV_TEST_TAG_LONG, (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB),
  325. CV_TEST_TAG_DEBUG_LONG);
  326. if (backend == DNN_BACKEND_HALIDE)
  327. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  328. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000)
  329. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  330. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  331. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  332. #endif
  333. const float l1 = (target == DNN_TARGET_MYRIAD) ? 0.009 : 0.0;
  334. const float lInf = (target == DNN_TARGET_MYRIAD) ? 0.09 : 0.0;
  335. processNet("dnn/openpose_pose_coco.caffemodel", "dnn/openpose_pose_coco.prototxt",
  336. Size(46, 46), "", "", l1, lInf);
  337. expectNoFallbacksFromIE(net);
  338. expectNoFallbacksFromCUDA(net);
  339. }
  340. TEST_P(DNNTestNetwork, OpenPose_pose_mpi)
  341. {
  342. applyTestTag(CV_TEST_TAG_LONG, (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB),
  343. CV_TEST_TAG_DEBUG_VERYLONG);
  344. if (backend == DNN_BACKEND_HALIDE)
  345. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  346. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000)
  347. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  348. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  349. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  350. #endif
  351. // output range: [-0.001, 0.97]
  352. const float l1 = (target == DNN_TARGET_MYRIAD) ? 0.02 : 0.0;
  353. const float lInf = (target == DNN_TARGET_MYRIAD || target == DNN_TARGET_OPENCL_FP16) ? 0.2 : 0.0;
  354. processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi.prototxt",
  355. Size(46, 46), "", "", l1, lInf);
  356. expectNoFallbacksFromIE(net);
  357. expectNoFallbacksFromCUDA(net);
  358. }
  359. TEST_P(DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
  360. {
  361. applyTestTag(CV_TEST_TAG_LONG, CV_TEST_TAG_MEMORY_1GB);
  362. if (backend == DNN_BACKEND_HALIDE)
  363. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  364. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000)
  365. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  366. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  367. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  368. #endif
  369. // The same .caffemodel but modified .prototxt
  370. // See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
  371. processNet("dnn/openpose_pose_mpi.caffemodel", "dnn/openpose_pose_mpi_faster_4_stages.prototxt",
  372. Size(46, 46));
  373. expectNoFallbacksFromIE(net);
  374. expectNoFallbacksFromCUDA(net);
  375. }
  376. TEST_P(DNNTestNetwork, OpenFace)
  377. {
  378. #if defined(INF_ENGINE_RELEASE)
  379. #if INF_ENGINE_VER_MAJOR_EQ(2018050000)
  380. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  381. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  382. #endif
  383. #endif
  384. if (backend == DNN_BACKEND_HALIDE)
  385. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  386. const float l1 = (target == DNN_TARGET_MYRIAD) ? 0.0024 : 0.0;
  387. const float lInf = (target == DNN_TARGET_MYRIAD) ? 0.0071 : 0.0;
  388. processNet("dnn/openface_nn4.small2.v1.t7", "", Size(96, 96), "", "", l1, lInf);
  389. expectNoFallbacksFromCUDA(net);
  390. }
  391. TEST_P(DNNTestNetwork, opencv_face_detector)
  392. {
  393. if (backend == DNN_BACKEND_HALIDE)
  394. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  395. Mat img = imread(findDataFile("gpu/lbpcascade/er.png"));
  396. Mat inp = blobFromImage(img, 1.0, Size(), Scalar(104.0, 177.0, 123.0), false, false);
  397. processNet("dnn/opencv_face_detector.caffemodel", "dnn/opencv_face_detector.prototxt",
  398. inp, "detection_out");
  399. expectNoFallbacksFromIE(net);
  400. }
  401. TEST_P(DNNTestNetwork, Inception_v2_SSD_TensorFlow)
  402. {
  403. applyTestTag(
  404. (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
  405. CV_TEST_TAG_DEBUG_LONG
  406. );
  407. #if defined(INF_ENGINE_RELEASE)
  408. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD
  409. && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  410. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
  411. #endif
  412. #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2019020000)
  413. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  414. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  415. #endif
  416. if (backend == DNN_BACKEND_HALIDE)
  417. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  418. Mat sample = imread(findDataFile("dnn/street.png"));
  419. Mat inp = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
  420. float scoreDiff = 0.0, iouDiff = 0.0;
  421. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  422. {
  423. scoreDiff = 0.015;
  424. iouDiff = 0.0731;
  425. }
  426. else if (target == DNN_TARGET_CUDA_FP16)
  427. {
  428. scoreDiff = 0.015;
  429. iouDiff = 0.08;
  430. }
  431. processNet("dnn/ssd_inception_v2_coco_2017_11_17.pb", "dnn/ssd_inception_v2_coco_2017_11_17.pbtxt",
  432. inp, "detection_out", "", scoreDiff, iouDiff);
  433. expectNoFallbacksFromIE(net);
  434. }
  435. TEST_P(DNNTestNetwork, DenseNet_121)
  436. {
  437. applyTestTag(CV_TEST_TAG_MEMORY_512MB);
  438. if (backend == DNN_BACKEND_HALIDE)
  439. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  440. // Reference output values are in range [-3.807, 4.605]
  441. float l1 = 0.0, lInf = 0.0;
  442. if (target == DNN_TARGET_OPENCL_FP16)
  443. {
  444. l1 = 2e-2;
  445. lInf = 9e-2;
  446. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
  447. lInf = 0.1f;
  448. }
  449. else if (target == DNN_TARGET_MYRIAD)
  450. {
  451. l1 = 0.1;
  452. lInf = 0.6;
  453. }
  454. else if (target == DNN_TARGET_CUDA_FP16)
  455. {
  456. l1 = 0.008;
  457. lInf = 0.05;
  458. }
  459. processNet("dnn/DenseNet_121.caffemodel", "dnn/DenseNet_121.prototxt", Size(224, 224), "", "", l1, lInf);
  460. if (target != DNN_TARGET_MYRIAD || getInferenceEngineVPUType() != CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X)
  461. expectNoFallbacksFromIE(net);
  462. expectNoFallbacksFromCUDA(net);
  463. }
  464. TEST_P(DNNTestNetwork, FastNeuralStyle_eccv16)
  465. {
  466. applyTestTag(CV_TEST_TAG_MEMORY_512MB, CV_TEST_TAG_DEBUG_VERYLONG);
  467. if (backend == DNN_BACKEND_HALIDE)
  468. applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
  469. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD)
  470. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
  471. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD)
  472. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
  473. #if defined(INF_ENGINE_RELEASE)
  474. #if INF_ENGINE_VER_MAJOR_LE(2018050000)
  475. if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_OPENCL)
  476. applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
  477. #endif
  478. #endif
  479. Mat img = imread(findDataFile("dnn/googlenet_1.png"));
  480. Mat inp = blobFromImage(img, 1.0, Size(320, 240), Scalar(103.939, 116.779, 123.68), false, false);
  481. // Output image has values in range [-143.526, 148.539].
  482. float l1 = 4e-5, lInf = 2e-3;
  483. if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
  484. {
  485. l1 = 0.4;
  486. lInf = 7.45;
  487. }
  488. else if (target == DNN_TARGET_CUDA_FP16)
  489. {
  490. l1 = 0.3;
  491. lInf = 7.6;
  492. }
  493. processNet("dnn/fast_neural_style_eccv16_starry_night.t7", "", inp, "", "", l1, lInf);
  494. #if defined(HAVE_INF_ENGINE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
  495. expectNoFallbacksFromIE(net);
  496. #endif
  497. expectNoFallbacksFromCUDA(net);
  498. }
  499. INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets(true, true, false, true, true));
  500. }} // namespace