@@ -243,10 +243,15 @@ TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
243
243
runTensorFlowNet (" l2_normalize_3d" );
244
244
}
245
245
246
- typedef testing::TestWithParam<Target> Test_TensorFlow_nets ;
246
+ class Test_TensorFlow_nets : public DNNTestLayer {} ;
247
247
248
248
TEST_P (Test_TensorFlow_nets, MobileNet_SSD)
249
249
{
250
+ checkBackend ();
251
+ if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_CPU) ||
252
+ (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
253
+ throw SkipTestException (" " );
254
+
250
255
std::string netPath = findDataFile (" dnn/ssd_mobilenet_v1_coco.pb" , false );
251
256
std::string netConfig = findDataFile (" dnn/ssd_mobilenet_v1_coco.pbtxt" , false );
252
257
std::string imgPath = findDataFile (" dnn/street.png" , false );
@@ -260,38 +265,39 @@ TEST_P(Test_TensorFlow_nets, MobileNet_SSD)
260
265
outNames[1 ] = " concat_1" ;
261
266
outNames[2 ] = " detection_out" ;
262
267
263
- std::vector<Mat> target (outNames.size ());
268
+ std::vector<Mat> refs (outNames.size ());
264
269
for (int i = 0 ; i < outNames.size (); ++i)
265
270
{
266
271
std::string path = findDataFile (" dnn/tensorflow/ssd_mobilenet_v1_coco." + outNames[i] + " .npy" , false );
267
- target [i] = blobFromNPY (path);
272
+ refs [i] = blobFromNPY (path);
268
273
}
269
274
270
275
Net net = readNetFromTensorflow (netPath, netConfig);
271
- net.setPreferableBackend (DNN_BACKEND_OPENCV );
272
- net.setPreferableTarget (GetParam () );
276
+ net.setPreferableBackend (backend );
277
+ net.setPreferableTarget (target );
273
278
274
279
net.setInput (inp);
275
280
276
281
std::vector<Mat> output;
277
282
net.forward (output, outNames);
278
283
279
- normAssert (target [0 ].reshape (1 , 1 ), output[0 ].reshape (1 , 1 ), " " , 1e-5 , 1.5e-4 );
280
- normAssert (target [1 ].reshape (1 , 1 ), output[1 ].reshape (1 , 1 ), " " , 1e-5 , 3e-4 );
281
- normAssertDetections (target [2 ], output[2 ], " " , 0.2 );
284
+ normAssert (refs [0 ].reshape (1 , 1 ), output[0 ].reshape (1 , 1 ), " " , 1e-5 , 1.5e-4 );
285
+ normAssert (refs [1 ].reshape (1 , 1 ), output[1 ].reshape (1 , 1 ), " " , 1e-5 , 3e-4 );
286
+ normAssertDetections (refs [2 ], output[2 ], " " , 0.2 );
282
287
}
283
288
284
289
TEST_P (Test_TensorFlow_nets, Inception_v2_SSD)
285
290
{
291
+ checkBackend ();
286
292
std::string proto = findDataFile (" dnn/ssd_inception_v2_coco_2017_11_17.pbtxt" , false );
287
293
std::string model = findDataFile (" dnn/ssd_inception_v2_coco_2017_11_17.pb" , false );
288
294
289
295
Net net = readNetFromTensorflow (model, proto);
290
296
Mat img = imread (findDataFile (" dnn/street.png" , false ));
291
297
Mat blob = blobFromImage (img, 1 .0f / 127.5 , Size (300 , 300 ), Scalar (127.5 , 127.5 , 127.5 ), true , false );
292
298
293
- net.setPreferableBackend (DNN_BACKEND_OPENCV );
294
- net.setPreferableTarget (GetParam () );
299
+ net.setPreferableBackend (backend );
300
+ net.setPreferableTarget (target );
295
301
296
302
net.setInput (blob);
297
303
// Output has shape 1x1xNx7 where N - number of detections.
@@ -302,16 +308,24 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
302
308
0 , 3 , 0.75838411 , 0.44668293 , 0.45907149 , 0.49459291 , 0.52197015 ,
303
309
0 , 10 , 0.95932811 , 0.38349164 , 0.32528657 , 0.40387636 , 0.39165527 ,
304
310
0 , 10 , 0.93973452 , 0.66561931 , 0.37841269 , 0.68074018 , 0.42907384 );
305
- normAssertDetections (ref, out, " " , 0.5 );
311
+ double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 5e-3 : default_l1;
312
+ double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.025 : default_lInf;
313
+ normAssertDetections (ref, out, " " , 0.5 , scoreDiff, iouDiff);
306
314
}
307
315
308
316
TEST_P (Test_TensorFlow_nets, Inception_v2_Faster_RCNN)
309
317
{
318
+ checkBackend ();
319
+ if (backend == DNN_BACKEND_INFERENCE_ENGINE ||
320
+ (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
321
+ throw SkipTestException (" " );
322
+
310
323
std::string proto = findDataFile (" dnn/faster_rcnn_inception_v2_coco_2018_01_28.pbtxt" , false );
311
324
std::string model = findDataFile (" dnn/faster_rcnn_inception_v2_coco_2018_01_28.pb" , false );
312
325
313
326
Net net = readNetFromTensorflow (model, proto);
314
- net.setPreferableBackend (DNN_BACKEND_OPENCV);
327
+ net.setPreferableBackend (backend);
328
+ net.setPreferableTarget (target);
315
329
Mat img = imread (findDataFile (" dnn/dog416.png" , false ));
316
330
Mat blob = blobFromImage (img, 1 .0f / 127.5 , Size (800 , 600 ), Scalar (127.5 , 127.5 , 127.5 ), true , false );
317
331
@@ -324,16 +338,20 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_Faster_RCNN)
324
338
325
339
TEST_P (Test_TensorFlow_nets, opencv_face_detector_uint8)
326
340
{
341
+ checkBackend ();
342
+ if (backend == DNN_BACKEND_INFERENCE_ENGINE &&
343
+ (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD))
344
+ throw SkipTestException (" " );
345
+
327
346
std::string proto = findDataFile (" dnn/opencv_face_detector.pbtxt" , false );
328
347
std::string model = findDataFile (" dnn/opencv_face_detector_uint8.pb" , false );
329
348
330
349
Net net = readNetFromTensorflow (model, proto);
331
350
Mat img = imread (findDataFile (" gpu/lbpcascade/er.png" , false ));
332
351
Mat blob = blobFromImage (img, 1.0 , Size (), Scalar (104.0 , 177.0 , 123.0 ), false , false );
333
352
334
- net.setPreferableBackend (DNN_BACKEND_OPENCV);
335
- net.setPreferableTarget (GetParam ());
336
-
353
+ net.setPreferableBackend (backend);
354
+ net.setPreferableTarget (target);
337
355
net.setInput (blob);
338
356
// Output has shape 1x1xNx7 where N - number of detections.
339
357
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
@@ -346,7 +364,9 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
346
364
0 , 1 , 0.98977017 , 0.23901358 , 0.09084064 , 0.29902688 , 0.1769477 ,
347
365
0 , 1 , 0.97203469 , 0.67965847 , 0.06876482 , 0.73999709 , 0.1513494 ,
348
366
0 , 1 , 0.95097077 , 0.51901293 , 0.45863652 , 0.5777427 , 0.5347801 );
349
- normAssertDetections (ref, out, " " , 0.9 , 3.4e-3 , 1e-2 );
367
+ double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 4e-3 : 3.4e-3 ;
368
+ double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.017 : 1e-2 ;
369
+ normAssertDetections (ref, out, " " , 0.9 , scoreDiff, iouDiff);
350
370
}
351
371
352
372
// inp = cv.imread('opencv_extra/testdata/cv/ximgproc/sources/08.png')
@@ -360,14 +380,19 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
360
380
// np.save('east_text_detection.geometry.npy', geometry)
361
381
TEST_P (Test_TensorFlow_nets, EAST_text_detection)
362
382
{
383
+ checkBackend ();
384
+ if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
385
+ throw SkipTestException (" " );
386
+
363
387
std::string netPath = findDataFile (" dnn/frozen_east_text_detection.pb" , false );
364
388
std::string imgPath = findDataFile (" cv/ximgproc/sources/08.png" , false );
365
389
std::string refScoresPath = findDataFile (" dnn/east_text_detection.scores.npy" , false );
366
390
std::string refGeometryPath = findDataFile (" dnn/east_text_detection.geometry.npy" , false );
367
391
368
392
Net net = readNet (findDataFile (" dnn/frozen_east_text_detection.pb" , false ));
369
393
370
- net.setPreferableTarget (GetParam ());
394
+ net.setPreferableBackend (backend);
395
+ net.setPreferableTarget (target);
371
396
372
397
Mat img = imread (imgPath);
373
398
Mat inp = blobFromImage (img, 1.0 , Size (), Scalar (123.68 , 116.78 , 103.94 ), true , false );
@@ -386,7 +411,7 @@ TEST_P(Test_TensorFlow_nets, EAST_text_detection)
386
411
normAssert (geometry, blobFromNPY (refGeometryPath), " geometry" , 1e-4 , 3e-3 );
387
412
}
388
413
389
- INSTANTIATE_TEST_CASE_P (/* */ , Test_TensorFlow_nets, availableDnnTargets ());
414
+ INSTANTIATE_TEST_CASE_P (/* */ , Test_TensorFlow_nets, dnnBackendsAndTargets ());
390
415
391
416
TEST_P (Test_TensorFlow_layers, fp16_weights)
392
417
{
0 commit comments