Skip to content

Commit 0a61ebd

Browse files
committed
Replace DNNTarget and DNNBackend in tests
1 parent e1c3237 commit 0a61ebd

File tree

5 files changed

+27
-61
lines changed

5 files changed

+27
-61
lines changed

modules/dnn/test/test_backends.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
namespace opencv_test { namespace {
1212

13-
CV_ENUM(DNNBackend, DNN_BACKEND_DEFAULT, DNN_BACKEND_HALIDE, DNN_BACKEND_INFERENCE_ENGINE)
14-
CV_ENUM(DNNTarget, DNN_TARGET_CPU, DNN_TARGET_OPENCL)
15-
1613
static void loadNet(const std::string& weights, const std::string& proto,
1714
const std::string& framework, Net* net)
1815
{

modules/dnn/test/test_caffe_importer.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,9 @@
4242
#include "test_precomp.hpp"
4343
#include "npy_blob.hpp"
4444
#include <opencv2/dnn/shape_utils.hpp>
45-
#include <opencv2/core/ocl.hpp>
46-
#include <opencv2/ts/ocl_test.hpp>
4745

4846
namespace opencv_test { namespace {
4947

50-
CV_ENUM(DNNTarget, DNN_TARGET_CPU, DNN_TARGET_OPENCL)
51-
static testing::internal::ParamGenerator<DNNTarget> availableBackends()
52-
{
53-
static std::vector<DNNTarget> targets;
54-
if (targets.empty())
55-
{
56-
targets.push_back(DNN_TARGET_CPU);
57-
#ifdef HAVE_OPENCL
58-
if (cv::ocl::useOpenCL())
59-
targets.push_back(DNN_TARGET_OPENCL);
60-
#endif
61-
}
62-
return testing::ValuesIn(targets);
63-
}
64-
6548
template<typename TString>
6649
static std::string _tf(TString filename)
6750
{
@@ -132,7 +115,7 @@ TEST_P(Reproducibility_AlexNet, Accuracy)
132115
normAssert(ref, out);
133116
}
134117

135-
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_AlexNet, Combine(testing::Bool(), availableBackends()));
118+
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_AlexNet, Combine(testing::Bool(), availableDnnTargets()));
136119

137120
#if !defined(_WIN32) || defined(_WIN64)
138121
TEST(Reproducibility_FCN, Accuracy)
@@ -232,7 +215,7 @@ TEST_P(Reproducibility_MobileNet_SSD, Accuracy)
232215
normAssert(outBatch.rowRange(0, numDetections), ref);
233216
normAssert(outBatch.rowRange(numDetections, 2 * numDetections).colRange(1, 7), ref.colRange(1, 7));
234217
}
235-
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_MobileNet_SSD, availableBackends());
218+
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_MobileNet_SSD, availableDnnTargets());
236219

237220
typedef testing::TestWithParam<DNNTarget> Reproducibility_ResNet50;
238221
TEST_P(Reproducibility_ResNet50, Accuracy)
@@ -263,7 +246,7 @@ TEST_P(Reproducibility_ResNet50, Accuracy)
263246
normAssert(ref, out_umats[0], "out_umat_vector");
264247
}
265248
}
266-
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_ResNet50, availableBackends());
249+
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_ResNet50, availableDnnTargets());
267250

268251
typedef testing::TestWithParam<DNNTarget> Reproducibility_SqueezeNet_v1_1;
269252
TEST_P(Reproducibility_SqueezeNet_v1_1, Accuracy)
@@ -291,7 +274,7 @@ TEST_P(Reproducibility_SqueezeNet_v1_1, Accuracy)
291274
Mat ref = blobFromNPY(_tf("squeezenet_v1.1_prob.npy"));
292275
normAssert(ref, out);
293276
}
294-
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_SqueezeNet_v1_1, availableBackends());
277+
INSTANTIATE_TEST_CASE_P(/**/, Reproducibility_SqueezeNet_v1_1, availableDnnTargets());
295278

296279
TEST(Reproducibility_AlexNet_fp16, Accuracy)
297280
{

modules/dnn/test/test_precomp.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,31 @@
4444
#include "opencv2/ts.hpp"
4545
#include "opencv2/ts/ts_perf.hpp"
4646
#include "opencv2/core/utility.hpp"
47+
#include "opencv2/core/ocl.hpp"
4748

4849
#include "opencv2/dnn.hpp"
4950
#include "test_common.hpp"
5051

5152
namespace opencv_test {
5253
using namespace cv::dnn;
54+
55+
CV_ENUM(DNNBackend, DNN_BACKEND_DEFAULT, DNN_BACKEND_HALIDE, DNN_BACKEND_INFERENCE_ENGINE)
56+
CV_ENUM(DNNTarget, DNN_TARGET_CPU, DNN_TARGET_OPENCL)
57+
58+
static testing::internal::ParamGenerator<DNNTarget> availableDnnTargets()
59+
{
60+
static std::vector<DNNTarget> targets;
61+
if (targets.empty())
62+
{
63+
targets.push_back(DNN_TARGET_CPU);
64+
#ifdef HAVE_OPENCL
65+
if (cv::ocl::useOpenCL())
66+
targets.push_back(DNN_TARGET_OPENCL);
67+
#endif
68+
}
69+
return testing::ValuesIn(targets);
70+
}
71+
5372
}
5473

5574
#endif

modules/dnn/test/test_tf_importer.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Test for Tensorflow models loading
1111

1212
#include "test_precomp.hpp"
1313
#include "npy_blob.hpp"
14-
#include <opencv2/core/ocl.hpp>
15-
#include <opencv2/ts/ocl_test.hpp>
1614

1715
namespace opencv_test
1816
{
@@ -26,21 +24,6 @@ static std::string _tf(TString filename)
2624
return (getOpenCVExtraDir() + "/dnn/") + filename;
2725
}
2826

29-
CV_ENUM(DNNTarget, DNN_TARGET_CPU, DNN_TARGET_OPENCL)
30-
static testing::internal::ParamGenerator<DNNTarget> availableBackends()
31-
{
32-
static std::vector<DNNTarget> targets;
33-
if (targets.empty())
34-
{
35-
targets.push_back(DNN_TARGET_CPU);
36-
#ifdef HAVE_OPENCL
37-
if (cv::ocl::useOpenCL())
38-
targets.push_back(DNN_TARGET_OPENCL);
39-
#endif
40-
}
41-
return testing::ValuesIn(targets);
42-
}
43-
4427
TEST(Test_TensorFlow, read_inception)
4528
{
4629
Net net;
@@ -204,7 +187,7 @@ TEST_P(Test_TensorFlow_layers, reshape)
204187
runTensorFlowNet("flatten", targetId, true);
205188
}
206189

207-
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_layers, availableBackends());
190+
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_layers, availableDnnTargets());
208191

209192
typedef testing::TestWithParam<DNNTarget> Test_TensorFlow_nets;
210193

@@ -302,7 +285,7 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
302285
normAssert(out.reshape(1, out.total() / 7).rowRange(0, 6).colRange(2, 7), ref, "", 2.8e-4, 3.4e-3);
303286
}
304287

305-
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_nets, availableBackends());
288+
INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_nets, availableDnnTargets());
306289

307290
TEST(Test_TensorFlow, defun)
308291
{

modules/dnn/test/test_torch_importer.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "test_precomp.hpp"
4343
#include "npy_blob.hpp"
4444
#include <opencv2/dnn/shape_utils.hpp>
45-
#include <opencv2/ts/ocl_test.hpp>
4645

4746
namespace opencv_test
4847
{
@@ -62,21 +61,6 @@ static std::string _tf(TStr filename, bool inTorchDir = true)
6261
return findDataFile(path, false);
6362
}
6463

65-
CV_ENUM(DNNTarget, DNN_TARGET_CPU, DNN_TARGET_OPENCL)
66-
static testing::internal::ParamGenerator<DNNTarget> availableBackends()
67-
{
68-
static std::vector<DNNTarget> targets;
69-
if (targets.empty())
70-
{
71-
targets.push_back(DNN_TARGET_CPU);
72-
#ifdef HAVE_OPENCL
73-
if (cv::ocl::useOpenCL())
74-
targets.push_back(DNN_TARGET_OPENCL);
75-
#endif
76-
}
77-
return testing::ValuesIn(targets);
78-
}
79-
8064
TEST(Torch_Importer, simple_read)
8165
{
8266
Net net;
@@ -221,7 +205,7 @@ TEST_P(Test_Torch_layers, net_non_spatial)
221205
runTorchNet("net_non_spatial", GetParam(), "", false, true);
222206
}
223207

224-
INSTANTIATE_TEST_CASE_P(/**/, Test_Torch_layers, availableBackends());
208+
INSTANTIATE_TEST_CASE_P(/**/, Test_Torch_layers, availableDnnTargets());
225209

226210
typedef testing::TestWithParam<DNNTarget> Test_Torch_nets;
227211

@@ -323,7 +307,7 @@ TEST_P(Test_Torch_nets, FastNeuralStyle_accuracy)
323307
}
324308
}
325309

326-
INSTANTIATE_TEST_CASE_P(/**/, Test_Torch_nets, availableBackends());
310+
INSTANTIATE_TEST_CASE_P(/**/, Test_Torch_nets, availableDnnTargets());
327311

328312
// TODO: fix OpenCL and add to the rest of tests
329313
TEST(Torch_Importer, run_paralel)

0 commit comments

Comments
 (0)