Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/test/test_precomp.hpp
16339 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
#ifndef __OPENCV_TEST_PRECOMP_HPP__
42
#define __OPENCV_TEST_PRECOMP_HPP__
43
44
#include "opencv2/ts.hpp"
45
#include "opencv2/ts/ts_perf.hpp"
46
#include "opencv2/core/utility.hpp"
47
#include "opencv2/core/ocl.hpp"
48
49
#include "opencv2/dnn.hpp"
50
#include "test_common.hpp"
51
52
namespace opencv_test {
53
using namespace cv::dnn;
54
55
static testing::internal::ParamGenerator<Target> availableDnnTargets()
56
{
57
static std::vector<Target> targets;
58
if (targets.empty())
59
{
60
targets.push_back(DNN_TARGET_CPU);
61
#ifdef HAVE_OPENCL
62
if (cv::ocl::useOpenCL())
63
targets.push_back(DNN_TARGET_OPENCL);
64
#endif
65
}
66
return testing::ValuesIn(targets);
67
}
68
69
class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >
70
{
71
public:
72
dnn::Backend backend;
73
dnn::Target target;
74
double default_l1, default_lInf;
75
76
DNNTestLayer()
77
{
78
backend = (dnn::Backend)(int)get<0>(GetParam());
79
target = (dnn::Target)(int)get<1>(GetParam());
80
getDefaultThresholds(backend, target, &default_l1, &default_lInf);
81
}
82
83
static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)
84
{
85
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
86
{
87
*l1 = 4e-3;
88
*lInf = 2e-2;
89
}
90
else
91
{
92
*l1 = 1e-5;
93
*lInf = 1e-4;
94
}
95
}
96
97
static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)
98
{
99
if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))
100
{
101
#ifdef HAVE_OPENCL
102
if (!cv::ocl::useOpenCL())
103
#endif
104
{
105
throw SkipTestException("OpenCL is not available/disabled in OpenCV");
106
}
107
}
108
if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
109
{
110
if (!checkMyriadTarget())
111
{
112
throw SkipTestException("Myriad is not available/disabled in OpenCV");
113
}
114
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018030000
115
if (inp && ref && inp->size[0] != 1)
116
{
117
// Myriad plugin supports only batch size 1. Slice a single sample.
118
if (inp->size[0] == ref->size[0])
119
{
120
std::vector<cv::Range> range(inp->dims, Range::all());
121
range[0] = Range(0, 1);
122
*inp = inp->operator()(range);
123
124
range = std::vector<cv::Range>(ref->dims, Range::all());
125
range[0] = Range(0, 1);
126
*ref = ref->operator()(range);
127
}
128
else
129
throw SkipTestException("Myriad plugin supports only batch size 1");
130
}
131
#else
132
if (inp && ref && inp->dims == 4 && ref->dims == 4 &&
133
inp->size[0] != 1 && inp->size[0] != ref->size[0])
134
throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");
135
136
#endif
137
}
138
}
139
140
protected:
141
void checkBackend(Mat* inp = 0, Mat* ref = 0)
142
{
143
checkBackend(backend, target, inp, ref);
144
}
145
};
146
147
} // namespace
148
#endif
149
150