Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/test/test_caffe_importer.cpp
16344 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "test_precomp.hpp"
43
#include "npy_blob.hpp"
44
#include <opencv2/dnn/shape_utils.hpp>
45
46
namespace opencv_test { namespace {
47
48
template<typename TString>
49
static std::string _tf(TString filename)
50
{
51
return (getOpenCVExtraDir() + "/dnn/") + filename;
52
}
53
54
class Test_Caffe_nets : public DNNTestLayer
55
{
56
public:
57
void testFaster(const std::string& proto, const std::string& model, const Mat& ref,
58
double scoreDiff = 0.0, double iouDiff = 0.0)
59
{
60
checkBackend();
61
Net net = readNetFromCaffe(findDataFile("dnn/" + proto, false),
62
findDataFile("dnn/" + model, false));
63
net.setPreferableBackend(backend);
64
net.setPreferableTarget(target);
65
Mat img = imread(findDataFile("dnn/dog416.png", false));
66
resize(img, img, Size(800, 600));
67
Mat blob = blobFromImage(img, 1.0, Size(), Scalar(102.9801, 115.9465, 122.7717), false, false);
68
Mat imInfo = (Mat_<float>(1, 3) << img.rows, img.cols, 1.6f);
69
70
net.setInput(blob, "data");
71
net.setInput(imInfo, "im_info");
72
// Output has shape 1x1xNx7 where N - number of detections.
73
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
74
Mat out = net.forward();
75
scoreDiff = scoreDiff ? scoreDiff : default_l1;
76
iouDiff = iouDiff ? iouDiff : default_lInf;
77
normAssertDetections(ref, out, ("model name: " + model).c_str(), 0.8, scoreDiff, iouDiff);
78
}
79
};
80
81
TEST(Test_Caffe, memory_read)
82
{
83
const string proto = findDataFile("dnn/bvlc_googlenet.prototxt", false);
84
const string model = findDataFile("dnn/bvlc_googlenet.caffemodel", false);
85
86
string dataProto;
87
ASSERT_TRUE(readFileInMemory(proto, dataProto));
88
string dataModel;
89
ASSERT_TRUE(readFileInMemory(model, dataModel));
90
91
Net net = readNetFromCaffe(dataProto.c_str(), dataProto.size());
92
net.setPreferableBackend(DNN_BACKEND_OPENCV);
93
ASSERT_FALSE(net.empty());
94
95
Net net2 = readNetFromCaffe(dataProto.c_str(), dataProto.size(),
96
dataModel.c_str(), dataModel.size());
97
ASSERT_FALSE(net2.empty());
98
}
99
100
TEST(Test_Caffe, read_gtsrb)
101
{
102
Net net = readNetFromCaffe(_tf("gtsrb.prototxt"));
103
ASSERT_FALSE(net.empty());
104
}
105
106
TEST(Test_Caffe, read_googlenet)
107
{
108
Net net = readNetFromCaffe(_tf("bvlc_googlenet.prototxt"));
109
ASSERT_FALSE(net.empty());
110
}
111
112
typedef testing::TestWithParam<tuple<bool, Target> > Reproducibility_AlexNet;
113
TEST_P(Reproducibility_AlexNet, Accuracy)
114
{
115
bool readFromMemory = get<0>(GetParam());
116
Net net;
117
{
118
const string proto = findDataFile("dnn/bvlc_alexnet.prototxt", false);
119
const string model = findDataFile("dnn/bvlc_alexnet.caffemodel", false);
120
if (readFromMemory)
121
{
122
string dataProto;
123
ASSERT_TRUE(readFileInMemory(proto, dataProto));
124
string dataModel;
125
ASSERT_TRUE(readFileInMemory(model, dataModel));
126
127
net = readNetFromCaffe(dataProto.c_str(), dataProto.size(),
128
dataModel.c_str(), dataModel.size());
129
}
130
else
131
net = readNetFromCaffe(proto, model);
132
ASSERT_FALSE(net.empty());
133
}
134
135
int targetId = get<1>(GetParam());
136
const float l1 = 1e-5;
137
const float lInf = (targetId == DNN_TARGET_OPENCL_FP16) ? 3e-3 : 1e-4;
138
139
net.setPreferableBackend(DNN_BACKEND_OPENCV);
140
net.setPreferableTarget(targetId);
141
142
Mat sample = imread(_tf("grace_hopper_227.png"));
143
ASSERT_TRUE(!sample.empty());
144
145
net.setInput(blobFromImage(sample, 1.0f, Size(227, 227), Scalar(), false), "data");
146
Mat out = net.forward("prob");
147
Mat ref = blobFromNPY(_tf("caffe_alexnet_prob.npy"));
148
normAssert(ref, out, "", l1, lInf);
149
}
150
151
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_AlexNet, Combine(testing::Bool(),
152
Values(DNN_TARGET_CPU, DNN_TARGET_OPENCL, DNN_TARGET_OPENCL_FP16)));
153
154
#if !defined(_WIN32) || defined(_WIN64)
155
TEST(Reproducibility_FCN, Accuracy)
156
{
157
Net net;
158
{
159
const string proto = findDataFile("dnn/fcn8s-heavy-pascal.prototxt", false);
160
const string model = findDataFile("dnn/fcn8s-heavy-pascal.caffemodel", false);
161
net = readNetFromCaffe(proto, model);
162
ASSERT_FALSE(net.empty());
163
}
164
net.setPreferableBackend(DNN_BACKEND_OPENCV);
165
166
Mat sample = imread(_tf("street.png"));
167
ASSERT_TRUE(!sample.empty());
168
169
std::vector<int> layerIds;
170
std::vector<size_t> weights, blobs;
171
net.getMemoryConsumption(shape(1,3,227,227), layerIds, weights, blobs);
172
173
net.setInput(blobFromImage(sample, 1.0f, Size(500, 500), Scalar(), false), "data");
174
Mat out = net.forward("score");
175
176
Mat refData = imread(_tf("caffe_fcn8s_prob.png"), IMREAD_ANYDEPTH);
177
int shape[] = {1, 21, 500, 500};
178
Mat ref(4, shape, CV_32FC1, refData.data);
179
180
normAssert(ref, out);
181
}
182
#endif
183
184
TEST(Reproducibility_SSD, Accuracy)
185
{
186
Net net;
187
{
188
const string proto = findDataFile("dnn/ssd_vgg16.prototxt", false);
189
const string model = findDataFile("dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel", false);
190
net = readNetFromCaffe(proto, model);
191
ASSERT_FALSE(net.empty());
192
}
193
net.setPreferableBackend(DNN_BACKEND_OPENCV);
194
195
Mat sample = imread(_tf("street.png"));
196
ASSERT_TRUE(!sample.empty());
197
198
if (sample.channels() == 4)
199
cvtColor(sample, sample, COLOR_BGRA2BGR);
200
201
Mat in_blob = blobFromImage(sample, 1.0f, Size(300, 300), Scalar(), false);
202
net.setInput(in_blob, "data");
203
Mat out = net.forward("detection_out");
204
205
Mat ref = blobFromNPY(_tf("ssd_out.npy"));
206
normAssertDetections(ref, out);
207
}
208
209
typedef testing::TestWithParam<Target> Reproducibility_MobileNet_SSD;
210
TEST_P(Reproducibility_MobileNet_SSD, Accuracy)
211
{
212
const string proto = findDataFile("dnn/MobileNetSSD_deploy.prototxt", false);
213
const string model = findDataFile("dnn/MobileNetSSD_deploy.caffemodel", false);
214
Net net = readNetFromCaffe(proto, model);
215
int targetId = GetParam();
216
const float l1 = (targetId == DNN_TARGET_OPENCL_FP16) ? 1.5e-4 : 1e-5;
217
const float lInf = (targetId == DNN_TARGET_OPENCL_FP16) ? 4e-4 : 1e-4;
218
219
net.setPreferableBackend(DNN_BACKEND_OPENCV);
220
net.setPreferableTarget(targetId);
221
222
Mat sample = imread(_tf("street.png"));
223
224
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
225
net.setInput(inp);
226
Mat out = net.forward();
227
228
const float scores_diff = (targetId == DNN_TARGET_OPENCL_FP16) ? 4e-4 : 1e-5;
229
const float boxes_iou_diff = (targetId == DNN_TARGET_OPENCL_FP16) ? 5e-3 : 1e-4;
230
Mat ref = blobFromNPY(_tf("mobilenet_ssd_caffe_out.npy"));
231
normAssertDetections(ref, out, "", 0.0, scores_diff, boxes_iou_diff);
232
233
// Check that detections aren't preserved.
234
inp.setTo(0.0f);
235
net.setInput(inp);
236
out = net.forward();
237
out = out.reshape(1, out.total() / 7);
238
239
const int numDetections = out.rows;
240
ASSERT_NE(numDetections, 0);
241
for (int i = 0; i < numDetections; ++i)
242
{
243
float confidence = out.ptr<float>(i)[2];
244
ASSERT_EQ(confidence, 0);
245
}
246
247
// Check batching mode.
248
ref = ref.reshape(1, numDetections);
249
inp = blobFromImages(std::vector<Mat>(2, sample), 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
250
net.setInput(inp);
251
Mat outBatch = net.forward();
252
253
// Output blob has a shape 1x1x2Nx7 where N is a number of detection for
254
// a single sample in batch. The first numbers of detection vectors are batch id.
255
outBatch = outBatch.reshape(1, outBatch.total() / 7);
256
EXPECT_EQ(outBatch.rows, 2 * numDetections);
257
normAssert(outBatch.rowRange(0, numDetections), ref, "", l1, lInf);
258
normAssert(outBatch.rowRange(numDetections, 2 * numDetections).colRange(1, 7), ref.colRange(1, 7),
259
"", l1, lInf);
260
}
261
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_MobileNet_SSD,
262
Values(DNN_TARGET_CPU, DNN_TARGET_OPENCL, DNN_TARGET_OPENCL_FP16));
263
264
typedef testing::TestWithParam<Target> Reproducibility_ResNet50;
265
TEST_P(Reproducibility_ResNet50, Accuracy)
266
{
267
Net net = readNetFromCaffe(findDataFile("dnn/ResNet-50-deploy.prototxt", false),
268
findDataFile("dnn/ResNet-50-model.caffemodel", false));
269
270
int targetId = GetParam();
271
net.setPreferableBackend(DNN_BACKEND_OPENCV);
272
net.setPreferableTarget(targetId);
273
274
float l1 = (targetId == DNN_TARGET_OPENCL_FP16) ? 3e-5 : 1e-5;
275
float lInf = (targetId == DNN_TARGET_OPENCL_FP16) ? 6e-3 : 1e-4;
276
277
Mat input = blobFromImage(imread(_tf("googlenet_0.png")), 1.0f, Size(224,224), Scalar(), false);
278
ASSERT_TRUE(!input.empty());
279
280
net.setInput(input);
281
Mat out = net.forward();
282
283
Mat ref = blobFromNPY(_tf("resnet50_prob.npy"));
284
normAssert(ref, out, "", l1, lInf);
285
286
if (targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16)
287
{
288
UMat out_umat;
289
net.forward(out_umat);
290
normAssert(ref, out_umat, "out_umat", l1, lInf);
291
292
std::vector<UMat> out_umats;
293
net.forward(out_umats);
294
normAssert(ref, out_umats[0], "out_umat_vector", l1, lInf);
295
}
296
}
297
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_ResNet50,
298
Values(DNN_TARGET_CPU, DNN_TARGET_OPENCL, DNN_TARGET_OPENCL_FP16));
299
300
typedef testing::TestWithParam<Target> Reproducibility_SqueezeNet_v1_1;
301
TEST_P(Reproducibility_SqueezeNet_v1_1, Accuracy)
302
{
303
Net net = readNetFromCaffe(findDataFile("dnn/squeezenet_v1.1.prototxt", false),
304
findDataFile("dnn/squeezenet_v1.1.caffemodel", false));
305
306
int targetId = GetParam();
307
net.setPreferableBackend(DNN_BACKEND_OPENCV);
308
net.setPreferableTarget(targetId);
309
310
Mat input = blobFromImage(imread(_tf("googlenet_0.png")), 1.0f, Size(227,227), Scalar(), false, true);
311
ASSERT_TRUE(!input.empty());
312
313
Mat out;
314
if (targetId == DNN_TARGET_OPENCL)
315
{
316
// Firstly set a wrong input blob and run the model to receive a wrong output.
317
// Then set a correct input blob to check CPU->GPU synchronization is working well.
318
net.setInput(input * 2.0f);
319
out = net.forward();
320
}
321
net.setInput(input);
322
out = net.forward();
323
324
Mat ref = blobFromNPY(_tf("squeezenet_v1.1_prob.npy"));
325
normAssert(ref, out);
326
}
327
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_SqueezeNet_v1_1, availableDnnTargets());
328
329
TEST(Reproducibility_AlexNet_fp16, Accuracy)
330
{
331
const float l1 = 1e-5;
332
const float lInf = 3e-3;
333
334
const string proto = findDataFile("dnn/bvlc_alexnet.prototxt", false);
335
const string model = findDataFile("dnn/bvlc_alexnet.caffemodel", false);
336
337
shrinkCaffeModel(model, "bvlc_alexnet.caffemodel_fp16");
338
Net net = readNetFromCaffe(proto, "bvlc_alexnet.caffemodel_fp16");
339
net.setPreferableBackend(DNN_BACKEND_OPENCV);
340
341
Mat sample = imread(findDataFile("dnn/grace_hopper_227.png", false));
342
343
net.setInput(blobFromImage(sample, 1.0f, Size(227, 227), Scalar(), false));
344
Mat out = net.forward();
345
Mat ref = blobFromNPY(findDataFile("dnn/caffe_alexnet_prob.npy", false));
346
normAssert(ref, out, "", l1, lInf);
347
}
348
349
TEST(Reproducibility_GoogLeNet_fp16, Accuracy)
350
{
351
const float l1 = 1e-5;
352
const float lInf = 3e-3;
353
354
const string proto = findDataFile("dnn/bvlc_googlenet.prototxt", false);
355
const string model = findDataFile("dnn/bvlc_googlenet.caffemodel", false);
356
357
shrinkCaffeModel(model, "bvlc_googlenet.caffemodel_fp16");
358
Net net = readNetFromCaffe(proto, "bvlc_googlenet.caffemodel_fp16");
359
net.setPreferableBackend(DNN_BACKEND_OPENCV);
360
361
std::vector<Mat> inpMats;
362
inpMats.push_back( imread(_tf("googlenet_0.png")) );
363
inpMats.push_back( imread(_tf("googlenet_1.png")) );
364
ASSERT_TRUE(!inpMats[0].empty() && !inpMats[1].empty());
365
366
net.setInput(blobFromImages(inpMats, 1.0f, Size(), Scalar(), false), "data");
367
Mat out = net.forward("prob");
368
369
Mat ref = blobFromNPY(_tf("googlenet_prob.npy"));
370
normAssert(out, ref, "", l1, lInf);
371
}
372
373
// https://github.com/richzhang/colorization
374
TEST_P(Test_Caffe_nets, Colorization)
375
{
376
checkBackend();
377
Mat inp = blobFromNPY(_tf("colorization_inp.npy"));
378
Mat ref = blobFromNPY(_tf("colorization_out.npy"));
379
Mat kernel = blobFromNPY(_tf("colorization_pts_in_hull.npy"));
380
381
const string proto = findDataFile("dnn/colorization_deploy_v2.prototxt", false);
382
const string model = findDataFile("dnn/colorization_release_v2.caffemodel", false);
383
Net net = readNetFromCaffe(proto, model);
384
net.setPreferableBackend(backend);
385
net.setPreferableTarget(target);
386
387
net.getLayer(net.getLayerId("class8_ab"))->blobs.push_back(kernel);
388
net.getLayer(net.getLayerId("conv8_313_rh"))->blobs.push_back(Mat(1, 313, CV_32F, 2.606));
389
390
net.setInput(inp);
391
Mat out = net.forward();
392
393
// Reference output values are in range [-29.1, 69.5]
394
const double l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.25 : 4e-4;
395
const double lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 5.3 : 3e-3;
396
normAssert(out, ref, "", l1, lInf);
397
}
398
399
TEST_P(Test_Caffe_nets, DenseNet_121)
400
{
401
checkBackend();
402
const string proto = findDataFile("dnn/DenseNet_121.prototxt", false);
403
const string model = findDataFile("dnn/DenseNet_121.caffemodel", false);
404
405
Mat inp = imread(_tf("dog416.png"));
406
inp = blobFromImage(inp, 1.0 / 255, Size(224, 224), Scalar(), true, true);
407
Mat ref = blobFromNPY(_tf("densenet_121_output.npy"));
408
409
Net net = readNetFromCaffe(proto, model);
410
net.setPreferableBackend(backend);
411
net.setPreferableTarget(target);
412
413
net.setInput(inp);
414
Mat out = net.forward();
415
416
// Reference is an array of 1000 values from a range [-6.16, 7.9]
417
float l1 = default_l1, lInf = default_lInf;
418
if (target == DNN_TARGET_OPENCL_FP16)
419
{
420
l1 = 0.017; lInf = 0.0795;
421
}
422
else if (target == DNN_TARGET_MYRIAD)
423
{
424
l1 = 0.097; lInf = 0.52;
425
}
426
normAssert(out, ref, "", l1, lInf);
427
}
428
429
TEST(Test_Caffe, multiple_inputs)
430
{
431
const string proto = findDataFile("dnn/layers/net_input.prototxt", false);
432
Net net = readNetFromCaffe(proto);
433
net.setPreferableBackend(DNN_BACKEND_OPENCV);
434
435
Mat first_image(10, 11, CV_32FC3);
436
Mat second_image(10, 11, CV_32FC3);
437
randu(first_image, -1, 1);
438
randu(second_image, -1, 1);
439
440
first_image = blobFromImage(first_image);
441
second_image = blobFromImage(second_image);
442
443
Mat first_image_blue_green = slice(first_image, Range::all(), Range(0, 2), Range::all(), Range::all());
444
Mat first_image_red = slice(first_image, Range::all(), Range(2, 3), Range::all(), Range::all());
445
Mat second_image_blue_green = slice(second_image, Range::all(), Range(0, 2), Range::all(), Range::all());
446
Mat second_image_red = slice(second_image, Range::all(), Range(2, 3), Range::all(), Range::all());
447
448
net.setInput(first_image_blue_green, "old_style_input_blue_green");
449
net.setInput(first_image_red, "different_name_for_red");
450
net.setInput(second_image_blue_green, "input_layer_blue_green");
451
net.setInput(second_image_red, "old_style_input_red");
452
Mat out = net.forward();
453
454
normAssert(out, first_image + second_image);
455
}
456
457
TEST(Test_Caffe, shared_weights)
458
{
459
const string proto = findDataFile("dnn/layers/shared_weights.prototxt", false);
460
const string model = findDataFile("dnn/layers/shared_weights.caffemodel", false);
461
462
Net net = readNetFromCaffe(proto, model);
463
464
Mat input_1 = (Mat_<float>(2, 2) << 0., 2., 4., 6.);
465
Mat input_2 = (Mat_<float>(2, 2) << 1., 3., 5., 7.);
466
467
Mat blob_1 = blobFromImage(input_1);
468
Mat blob_2 = blobFromImage(input_2);
469
470
net.setInput(blob_1, "input_1");
471
net.setInput(blob_2, "input_2");
472
473
Mat sum = net.forward();
474
475
EXPECT_EQ(sum.at<float>(0,0), 12.);
476
EXPECT_EQ(sum.at<float>(0,1), 16.);
477
}
478
479
typedef testing::TestWithParam<tuple<std::string, Target> > opencv_face_detector;
480
TEST_P(opencv_face_detector, Accuracy)
481
{
482
std::string proto = findDataFile("dnn/opencv_face_detector.prototxt", false);
483
std::string model = findDataFile(get<0>(GetParam()), false);
484
dnn::Target targetId = (dnn::Target)(int)get<1>(GetParam());
485
486
Net net = readNetFromCaffe(proto, model);
487
Mat img = imread(findDataFile("gpu/lbpcascade/er.png", false));
488
Mat blob = blobFromImage(img, 1.0, Size(), Scalar(104.0, 177.0, 123.0), false, false);
489
490
net.setPreferableBackend(DNN_BACKEND_OPENCV);
491
net.setPreferableTarget(targetId);
492
493
net.setInput(blob);
494
// Output has shape 1x1xNx7 where N - number of detections.
495
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
496
Mat out = net.forward();
497
Mat ref = (Mat_<float>(6, 7) << 0, 1, 0.99520785, 0.80997437, 0.16379407, 0.87996572, 0.26685631,
498
0, 1, 0.9934696, 0.2831718, 0.50738752, 0.345781, 0.5985168,
499
0, 1, 0.99096733, 0.13629119, 0.24892329, 0.19756334, 0.3310290,
500
0, 1, 0.98977017, 0.23901358, 0.09084064, 0.29902688, 0.1769477,
501
0, 1, 0.97203469, 0.67965847, 0.06876482, 0.73999709, 0.1513494,
502
0, 1, 0.95097077, 0.51901293, 0.45863652, 0.5777427, 0.5347801);
503
normAssertDetections(ref, out, "", 0.5, 1e-5, 2e-4);
504
}
505
INSTANTIATE_TEST_CASE_P(Test_Caffe, opencv_face_detector,
506
Combine(
507
Values("dnn/opencv_face_detector.caffemodel",
508
"dnn/opencv_face_detector_fp16.caffemodel"),
509
Values(DNN_TARGET_CPU, DNN_TARGET_OPENCL)
510
)
511
);
512
513
TEST_P(Test_Caffe_nets, FasterRCNN_vgg16)
514
{
515
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
516
throw SkipTestException("");
517
static Mat ref = (Mat_<float>(3, 7) << 0, 2, 0.949398, 99.2454, 210.141, 601.205, 462.849,
518
0, 7, 0.997022, 481.841, 92.3218, 722.685, 175.953,
519
0, 12, 0.993028, 133.221, 189.377, 350.994, 563.166);
520
testFaster("faster_rcnn_vgg16.prototxt", "VGG16_faster_rcnn_final.caffemodel", ref);
521
}
522
523
TEST_P(Test_Caffe_nets, FasterRCNN_zf)
524
{
525
if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16) ||
526
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
527
throw SkipTestException("");
528
static Mat ref = (Mat_<float>(3, 7) << 0, 2, 0.90121, 120.407, 115.83, 570.586, 528.395,
529
0, 7, 0.988779, 469.849, 75.1756, 718.64, 186.762,
530
0, 12, 0.967198, 138.588, 206.843, 329.766, 553.176);
531
testFaster("faster_rcnn_zf.prototxt", "ZF_faster_rcnn_final.caffemodel", ref);
532
}
533
534
TEST_P(Test_Caffe_nets, RFCN)
535
{
536
if ((backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16) ||
537
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
538
throw SkipTestException("");
539
double scoreDiff = (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) ? 4e-3 : default_l1;
540
double iouDiff = (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) ? 8e-2 : default_lInf;
541
static Mat ref = (Mat_<float>(2, 7) << 0, 7, 0.991359, 491.822, 81.1668, 702.573, 178.234,
542
0, 12, 0.94786, 132.093, 223.903, 338.077, 566.16);
543
testFaster("rfcn_pascal_voc_resnet50.prototxt", "resnet50_rfcn_final.caffemodel", ref, scoreDiff, iouDiff);
544
}
545
546
INSTANTIATE_TEST_CASE_P(/**/, Test_Caffe_nets, dnnBackendsAndTargets());
547
548
}} // namespace
549
550