42
42
#include " test_precomp.hpp"
43
43
#include " npy_blob.hpp"
44
44
#include < opencv2/dnn/shape_utils.hpp>
45
+ #include < opencv2/core/ocl.hpp>
46
+ #include < opencv2/ts/ocl_test.hpp>
45
47
46
48
namespace cvtest
47
49
{
@@ -119,6 +121,43 @@ TEST_P(Reproducibility_AlexNet, Accuracy)
119
121
120
122
INSTANTIATE_TEST_CASE_P (Test_Caffe, Reproducibility_AlexNet, testing::Values(true , false ));
121
123
124
+ typedef testing::TestWithParam<tuple<bool > > Reproducibility_OCL_AlexNet;
125
+ OCL_TEST_P (Reproducibility_OCL_AlexNet, Accuracy)
126
+ {
127
+ bool readFromMemory = get<0 >(GetParam ());
128
+ Net net;
129
+ {
130
+ const string proto = findDataFile (" dnn/bvlc_alexnet.prototxt" , false );
131
+ const string model = findDataFile (" dnn/bvlc_alexnet.caffemodel" , false );
132
+ if (readFromMemory)
133
+ {
134
+ string dataProto;
135
+ ASSERT_TRUE (readFileInMemory (proto, dataProto));
136
+ string dataModel;
137
+ ASSERT_TRUE (readFileInMemory (model, dataModel));
138
+
139
+ net = readNetFromCaffe (dataProto.c_str (), dataProto.size (),
140
+ dataModel.c_str (), dataModel.size ());
141
+ }
142
+ else
143
+ net = readNetFromCaffe (proto, model);
144
+ ASSERT_FALSE (net.empty ());
145
+ }
146
+
147
+ net.setPreferableBackend (DNN_BACKEND_DEFAULT);
148
+ net.setPreferableTarget (DNN_TARGET_OPENCL);
149
+
150
+ Mat sample = imread (_tf (" grace_hopper_227.png" ));
151
+ ASSERT_TRUE (!sample.empty ());
152
+
153
+ net.setInput (blobFromImage (sample, 1 .0f , Size (227 , 227 ), Scalar (), false ), " data" );
154
+ Mat out = net.forward (" prob" );
155
+ Mat ref = blobFromNPY (_tf (" caffe_alexnet_prob.npy" ));
156
+ normAssert (ref, out);
157
+ }
158
+
159
+ OCL_INSTANTIATE_TEST_CASE_P (Test_Caffe, Reproducibility_OCL_AlexNet, testing::Values(true , false ));
160
+
122
161
#if !defined(_WIN32) || defined(_WIN64)
123
162
TEST (Reproducibility_FCN, Accuracy)
124
163
{
@@ -201,6 +240,38 @@ TEST(Reproducibility_MobileNet_SSD, Accuracy)
201
240
}
202
241
}
203
242
243
+ OCL_TEST (Reproducibility_MobileNet_SSD, Accuracy)
244
+ {
245
+ const string proto = findDataFile (" dnn/MobileNetSSD_deploy.prototxt" , false );
246
+ const string model = findDataFile (" dnn/MobileNetSSD_deploy.caffemodel" , false );
247
+ Net net = readNetFromCaffe (proto, model);
248
+
249
+ net.setPreferableBackend (DNN_BACKEND_DEFAULT);
250
+ net.setPreferableTarget (DNN_TARGET_OPENCL);
251
+
252
+ Mat sample = imread (_tf (" street.png" ));
253
+
254
+ Mat inp = blobFromImage (sample, 1 .0f / 127.5 , Size (300 , 300 ), Scalar (127.5 , 127.5 , 127.5 ), false );
255
+ net.setInput (inp);
256
+ Mat out = net.forward ();
257
+
258
+ Mat ref = blobFromNPY (_tf (" mobilenet_ssd_caffe_out.npy" ));
259
+ normAssert (ref, out);
260
+
261
+ // Check that detections aren't preserved.
262
+ inp.setTo (0 .0f );
263
+ net.setInput (inp);
264
+ out = net.forward ();
265
+
266
+ const int numDetections = out.size [2 ];
267
+ ASSERT_NE (numDetections, 0 );
268
+ for (int i = 0 ; i < numDetections; ++i)
269
+ {
270
+ float confidence = out.ptr <float >(0 , 0 , i)[2 ];
271
+ ASSERT_EQ (confidence, 0 );
272
+ }
273
+ }
274
+
204
275
TEST (Reproducibility_ResNet50, Accuracy)
205
276
{
206
277
Net net = readNetFromCaffe (findDataFile (" dnn/ResNet-50-deploy.prototxt" , false ),
@@ -216,6 +287,24 @@ TEST(Reproducibility_ResNet50, Accuracy)
216
287
normAssert (ref, out);
217
288
}
218
289
290
+ OCL_TEST (Reproducibility_ResNet50, Accuracy)
291
+ {
292
+ Net net = readNetFromCaffe (findDataFile (" dnn/ResNet-50-deploy.prototxt" , false ),
293
+ findDataFile (" dnn/ResNet-50-model.caffemodel" , false ));
294
+
295
+ net.setPreferableBackend (DNN_BACKEND_DEFAULT);
296
+ net.setPreferableTarget (DNN_TARGET_OPENCL);
297
+
298
+ Mat input = blobFromImage (imread (_tf (" googlenet_0.png" )), 1 .0f , Size (224 ,224 ), Scalar (), false );
299
+ ASSERT_TRUE (!input.empty ());
300
+
301
+ net.setInput (input);
302
+ Mat out = net.forward ();
303
+
304
+ Mat ref = blobFromNPY (_tf (" resnet50_prob.npy" ));
305
+ normAssert (ref, out);
306
+ }
307
+
219
308
TEST (Reproducibility_SqueezeNet_v1_1, Accuracy)
220
309
{
221
310
Net net = readNetFromCaffe (findDataFile (" dnn/squeezenet_v1.1.prototxt" , false ),
@@ -231,6 +320,24 @@ TEST(Reproducibility_SqueezeNet_v1_1, Accuracy)
231
320
normAssert (ref, out);
232
321
}
233
322
323
+ OCL_TEST (Reproducibility_SqueezeNet_v1_1, Accuracy)
324
+ {
325
+ Net net = readNetFromCaffe (findDataFile (" dnn/squeezenet_v1.1.prototxt" , false ),
326
+ findDataFile (" dnn/squeezenet_v1.1.caffemodel" , false ));
327
+
328
+ net.setPreferableBackend (DNN_BACKEND_DEFAULT);
329
+ net.setPreferableTarget (DNN_TARGET_OPENCL);
330
+
331
+ Mat input = blobFromImage (imread (_tf (" googlenet_0.png" )), 1 .0f , Size (227 ,227 ), Scalar (), false );
332
+ ASSERT_TRUE (!input.empty ());
333
+
334
+ net.setInput (input);
335
+ Mat out = net.forward ();
336
+
337
+ Mat ref = blobFromNPY (_tf (" squeezenet_v1.1_prob.npy" ));
338
+ normAssert (ref, out);
339
+ }
340
+
234
341
TEST (Reproducibility_AlexNet_fp16, Accuracy)
235
342
{
236
343
const float l1 = 1e-5 ;
0 commit comments