1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 #ifndef __OPENCV_TEST_COMMON_HPP__
6 #define __OPENCV_TEST_COMMON_HPP__
8 #include "opencv2/dnn/utils/inference_engine.hpp"
11 #include "opencv2/core/ocl.hpp"
15 namespace cv { namespace dnn {
16 CV__DNN_INLINE_NS_BEGIN
18 void PrintTo(const cv::dnn::Backend& v, std::ostream* os);
19 void PrintTo(const cv::dnn::Target& v, std::ostream* os);
20 using opencv_test::tuple;
21 using opencv_test::get;
22 void PrintTo(const tuple<cv::dnn::Backend, cv::dnn::Target> v, std::ostream* os);
25 }} // namespace cv::dnn
29 namespace opencv_test {
31 using namespace cv::dnn;
33 static inline const std::string &getOpenCVExtraDir()
35 return cvtest::TS::ptr()->get_data_path();
39 cv::InputArray ref, cv::InputArray test, const char *comment = "",
40 double l1 = 0.00001, double lInf = 0.0001);
42 std::vector<cv::Rect2d> matToBoxes(const cv::Mat& m);
44 void normAssertDetections(
45 const std::vector<int>& refClassIds,
46 const std::vector<float>& refScores,
47 const std::vector<cv::Rect2d>& refBoxes,
48 const std::vector<int>& testClassIds,
49 const std::vector<float>& testScores,
50 const std::vector<cv::Rect2d>& testBoxes,
51 const char *comment = "", double confThreshold = 0.0,
52 double scores_diff = 1e-5, double boxes_iou_diff = 1e-4);
54 // For SSD-based object detection networks which produce output of shape 1x1xNx7
55 // where N is a number of detections and an every detection is represented by
56 // a vector [batchId, classId, confidence, left, top, right, bottom].
57 void normAssertDetections(
58 cv::Mat ref, cv::Mat out, const char *comment = "",
59 double confThreshold = 0.0, double scores_diff = 1e-5,
60 double boxes_iou_diff = 1e-4);
62 bool readFileInMemory(const std::string& filename, std::string& content);
64 #ifdef HAVE_INF_ENGINE
65 bool validateVPUType();
68 testing::internal::ParamGenerator< tuple<Backend, Target> > dnnBackendsAndTargets(
69 bool withInferenceEngine = true,
70 bool withHalide = false,
71 bool withCpuOCV = true,
76 class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >
81 double default_l1, default_lInf;
85 backend = (dnn::Backend)(int)get<0>(GetParam());
86 target = (dnn::Target)(int)get<1>(GetParam());
87 getDefaultThresholds(backend, target, &default_l1, &default_lInf);
90 static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)
92 if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
104 static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)
106 if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)
108 if (inp && ref && inp->dims == 4 && ref->dims == 4 &&
109 inp->size[0] != 1 && inp->size[0] != ref->size[0])
110 throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");
115 void checkBackend(Mat* inp = 0, Mat* ref = 0)
117 checkBackend(backend, target, inp, ref);
124 // src/op_inf_engine.hpp
125 #define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
126 #define INF_ENGINE_VER_MAJOR_GE(ver) (((INF_ENGINE_RELEASE) / 10000) >= ((ver) / 10000))
127 #define INF_ENGINE_VER_MAJOR_LT(ver) (((INF_ENGINE_RELEASE) / 10000) < ((ver) / 10000))
128 #define INF_ENGINE_VER_MAJOR_LE(ver) (((INF_ENGINE_RELEASE) / 10000) <= ((ver) / 10000))
129 #define INF_ENGINE_VER_MAJOR_EQ(ver) (((INF_ENGINE_RELEASE) / 10000) == ((ver) / 10000))