@@ -23,9 +23,9 @@ class DNNTestNetwork : public TestWithParam <tuple<DNNBackend, DNNTarget> >
2323 }
2424
2525 void processNet (const std::string& weights, const std::string& proto,
26- Size inpSize, const std::string& outputLayer,
26+ Size inpSize, const std::string& outputLayer = " " ,
2727 const std::string& halideScheduler = " " ,
28- double l1 = 1e-5 , double lInf = 1e-4 )
28+ double l1 = 0.0 , double lInf = 0.0 )
2929 {
3030 // Create a common input blob.
3131 int blobSize[] = {1 , 3 , inpSize.height , inpSize.width };
@@ -36,9 +36,9 @@ class DNNTestNetwork : public TestWithParam <tuple<DNNBackend, DNNTarget> >
3636 }
3737
3838 void processNet (std::string weights, std::string proto,
39- Mat inp, const std::string& outputLayer,
39+ Mat inp, const std::string& outputLayer = " " ,
4040 std::string halideScheduler = " " ,
41- double l1 = 1e-5 , double lInf = 1e-4 )
41+ double l1 = 0.0 , double lInf = 0.0 )
4242 {
4343 if (backend == DNN_BACKEND_DEFAULT && target == DNN_TARGET_OPENCL)
4444 {
@@ -49,6 +49,16 @@ class DNNTestNetwork : public TestWithParam <tuple<DNNBackend, DNNTarget> >
4949 throw SkipTestException (" OpenCL is not available/disabled in OpenCV" );
5050 }
5151 }
52+ if (target == DNN_TARGET_OPENCL_FP16)
53+ {
54+ l1 = l1 == 0.0 ? 4e-3 : l1;
55+ lInf = lInf == 0.0 ? 2e-2 : lInf;
56+ }
57+ else
58+ {
59+ l1 = l1 == 0.0 ? 1e-5 : l1;
60+ lInf = lInf == 0.0 ? 1e-4 : lInf;
61+ }
5262 weights = findDataFile (weights, false );
5363 if (!proto.empty ())
5464 proto = findDataFile (proto, false );
@@ -71,31 +81,28 @@ class DNNTestNetwork : public TestWithParam <tuple<DNNBackend, DNNTarget> >
7181 Mat out = net.forward (outputLayer).clone ();
7282
7383 if (outputLayer == " detection_out" )
74- normAssertDetections (outDefault, out, " First run" , 0.2 );
84+ normAssertDetections (outDefault, out, " First run" , 0.2 , l1, lInf );
7585 else
7686 normAssert (outDefault, out, " First run" , l1, lInf);
7787
7888 // Test 2: change input.
79- inp *= 0 .1f ;
89+ float * inpData = (float *)inp.data ;
90+ for (int i = 0 ; i < inp.size [0 ] * inp.size [1 ]; ++i)
91+ {
92+ Mat slice (inp.size [2 ], inp.size [3 ], CV_32F, inpData);
93+ cv::flip (slice, slice, 1 );
94+ inpData += slice.total ();
95+ }
8096 netDefault.setInput (inp);
8197 net.setInput (inp);
8298 outDefault = netDefault.forward (outputLayer).clone ();
8399 out = net.forward (outputLayer).clone ();
84100
85101 if (outputLayer == " detection_out" )
86- checkDetections (outDefault, out, " Second run" , l1, lInf);
102+ normAssertDetections (outDefault, out, " Second run" , 0.2 , l1, lInf);
87103 else
88104 normAssert (outDefault, out, " Second run" , l1, lInf);
89105 }
90-
91- void checkDetections (const Mat& out, const Mat& ref, const std::string& msg,
92- float l1, float lInf, int top = 5 )
93- {
94- top = std::min (std::min (top, out.size [2 ]), out.size [3 ]);
95- std::vector<cv::Range> range (4 , cv::Range::all ());
96- range[2 ] = cv::Range (0 , top);
97- normAssert (out (range), ref (range));
98- }
99106};
100107
101108TEST_P (DNNTestNetwork, AlexNet)
@@ -110,8 +117,6 @@ TEST_P(DNNTestNetwork, AlexNet)
110117
111118TEST_P (DNNTestNetwork, ResNet_50)
112119{
113- if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16)
114- throw SkipTestException (" " );
115120 processNet (" dnn/ResNet-50-model.caffemodel" , " dnn/ResNet-50-deploy.prototxt" ,
116121 Size (224 , 224 ), " prob" ,
117122 target == DNN_TARGET_OPENCL ? " dnn/halide_scheduler_opencl_resnet_50.yml" :
@@ -120,8 +125,6 @@ TEST_P(DNNTestNetwork, ResNet_50)
120125
121126TEST_P (DNNTestNetwork, SqueezeNet_v1_1)
122127{
123- if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16)
124- throw SkipTestException (" " );
125128 processNet (" dnn/squeezenet_v1.1.caffemodel" , " dnn/squeezenet_v1.1.prototxt" ,
126129 Size (227 , 227 ), " prob" ,
127130 target == DNN_TARGET_OPENCL ? " dnn/halide_scheduler_opencl_squeezenet_v1_1.yml" :
@@ -130,8 +133,6 @@ TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
130133
131134TEST_P (DNNTestNetwork, GoogLeNet)
132135{
133- if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16)
134- throw SkipTestException (" " );
135136 processNet (" dnn/bvlc_googlenet.caffemodel" , " dnn/bvlc_googlenet.prototxt" ,
136137 Size (224 , 224 ), " prob" );
137138}
@@ -180,7 +181,7 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
180181{
181182 if (backend == DNN_BACKEND_DEFAULT && target == DNN_TARGET_OPENCL ||
182183 backend == DNN_BACKEND_HALIDE && target == DNN_TARGET_CPU ||
183- backend == DNN_BACKEND_INFERENCE_ENGINE)
184+ backend == DNN_BACKEND_INFERENCE_ENGINE && target != DNN_TARGET_CPU )
184185 throw SkipTestException (" " );
185186 processNet (" dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel" ,
186187 " dnn/ssd_vgg16.prototxt" , Size (300 , 300 ), " detection_out" );
@@ -189,30 +190,24 @@ TEST_P(DNNTestNetwork, SSD_VGG16)
189190TEST_P (DNNTestNetwork, OpenPose_pose_coco)
190191{
191192 if (backend == DNN_BACKEND_HALIDE) throw SkipTestException (" " );
192- double l1 = target == DNN_TARGET_OPENCL_FP16 ? 3e-5 : 1e-5 ;
193- double lInf = target == DNN_TARGET_OPENCL_FP16 ? 3e-3 : 1e-4 ;
194193 processNet (" dnn/openpose_pose_coco.caffemodel" , " dnn/openpose_pose_coco.prototxt" ,
195- Size (368 , 368 ), " " , " " , l1, lInf );
194+ Size (368 , 368 ));
196195}
197196
198197TEST_P (DNNTestNetwork, OpenPose_pose_mpi)
199198{
200199 if (backend == DNN_BACKEND_HALIDE) throw SkipTestException (" " );
201- double l1 = target == DNN_TARGET_OPENCL_FP16 ? 4e-5 : 1e-5 ;
202- double lInf = target == DNN_TARGET_OPENCL_FP16 ? 7e-3 : 1e-4 ;
203200 processNet (" dnn/openpose_pose_mpi.caffemodel" , " dnn/openpose_pose_mpi.prototxt" ,
204- Size (368 , 368 ), " " , " " , l1, lInf );
201+ Size (368 , 368 ));
205202}
206203
207204TEST_P (DNNTestNetwork, OpenPose_pose_mpi_faster_4_stages)
208205{
209206 if (backend == DNN_BACKEND_HALIDE) throw SkipTestException (" " );
210- double l1 = target == DNN_TARGET_OPENCL_FP16 ? 5e-5 : 1e-5 ;
211- double lInf = target == DNN_TARGET_OPENCL_FP16 ? 5e-3 : 1e-4 ;
212207 // The same .caffemodel but modified .prototxt
213208 // See https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/src/openpose/pose/poseParameters.cpp
214209 processNet (" dnn/openpose_pose_mpi.caffemodel" , " dnn/openpose_pose_mpi_faster_4_stages.prototxt" ,
215- Size (368 , 368 ), " " , " " , l1, lInf );
210+ Size (368 , 368 ));
216211}
217212
218213TEST_P (DNNTestNetwork, OpenFace)
0 commit comments