2019-03-29 21:42:58 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
#ifndef __OPENCV_TEST_COMMON_HPP__
|
|
|
|
#define __OPENCV_TEST_COMMON_HPP__
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
#include "opencv2/dnn/utils/inference_engine.hpp"
|
|
|
|
|
2018-08-30 22:53:41 +08:00
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
#include "opencv2/core/ocl.hpp"
|
|
|
|
#endif
|
|
|
|
|
2019-12-02 21:16:06 +08:00
|
|
|
// src/op_inf_engine.hpp
|
|
|
|
#define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
|
|
|
|
#define INF_ENGINE_VER_MAJOR_GE(ver) (((INF_ENGINE_RELEASE) / 10000) >= ((ver) / 10000))
|
|
|
|
#define INF_ENGINE_VER_MAJOR_LT(ver) (((INF_ENGINE_RELEASE) / 10000) < ((ver) / 10000))
|
|
|
|
#define INF_ENGINE_VER_MAJOR_LE(ver) (((INF_ENGINE_RELEASE) / 10000) <= ((ver) / 10000))
|
|
|
|
#define INF_ENGINE_VER_MAJOR_EQ(ver) (((INF_ENGINE_RELEASE) / 10000) == ((ver) / 10000))
|
|
|
|
|
|
|
|
|
2019-06-15 20:17:25 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_HALIDE "dnn_skip_halide"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_OPENCL "dnn_skip_ocl"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 "dnn_skip_ocl_fp16"
|
2019-12-02 21:16:06 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER "dnn_skip_ie_nn_builder"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_NGRAPH "dnn_skip_ie_ngraph"
|
2019-06-15 20:17:25 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE "dnn_skip_ie"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_2018R5 "dnn_skip_ie_2018r5"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_2019R1 "dnn_skip_ie_2019r1"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_2019R1_1 "dnn_skip_ie_2019r1_1"
|
2019-07-25 14:57:49 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_2019R2 "dnn_skip_ie_2019r2"
|
2019-10-04 15:29:27 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_2019R3 "dnn_skip_ie_2019r3"
|
2019-06-15 20:17:25 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_OPENCL "dnn_skip_ie_ocl"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 "dnn_skip_ie_ocl_fp16"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2 "dnn_skip_ie_myriad2"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X "dnn_skip_ie_myriadx"
|
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_MYRIAD CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2, CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X
|
2021-03-20 19:20:02 +08:00
|
|
|
#define CV_TEST_TAG_DNN_SKIP_IE_ARM_CPU "dnn_skip_ie_arm_cpu"
|
2019-06-15 20:17:25 +08:00
|
|
|
|
|
|
|
|
2019-12-02 21:16:06 +08:00
|
|
|
#ifdef HAVE_INF_ENGINE
|
|
|
|
#if INF_ENGINE_VER_MAJOR_EQ(2018050000)
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2018R5
|
|
|
|
#elif INF_ENGINE_VER_MAJOR_EQ(2019010000)
|
|
|
|
# if INF_ENGINE_RELEASE < 2019010100
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R1
|
|
|
|
# else
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R1_1
|
|
|
|
# endif
|
|
|
|
#elif INF_ENGINE_VER_MAJOR_EQ(2019020000)
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R2
|
|
|
|
#elif INF_ENGINE_VER_MAJOR_EQ(2019030000)
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE, CV_TEST_TAG_DNN_SKIP_IE_2019R3
|
|
|
|
#endif
|
|
|
|
#endif // HAVE_INF_ENGINE
|
|
|
|
|
|
|
|
#ifndef CV_TEST_TAG_DNN_SKIP_IE_VERSION
|
|
|
|
# define CV_TEST_TAG_DNN_SKIP_IE_VERSION CV_TEST_TAG_DNN_SKIP_IE
|
|
|
|
#endif
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
|
2018-08-02 22:59:45 +08:00
|
|
|
namespace cv { namespace dnn {
|
|
|
|
CV__DNN_EXPERIMENTAL_NS_BEGIN
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
void PrintTo(const cv::dnn::Backend& v, std::ostream* os);
|
|
|
|
void PrintTo(const cv::dnn::Target& v, std::ostream* os);
|
2018-08-02 22:59:45 +08:00
|
|
|
using opencv_test::tuple;
|
|
|
|
using opencv_test::get;
|
2019-03-29 21:42:58 +08:00
|
|
|
void PrintTo(const tuple<cv::dnn::Backend, cv::dnn::Target> v, std::ostream* os);
|
2018-08-02 22:59:45 +08:00
|
|
|
|
|
|
|
CV__DNN_EXPERIMENTAL_NS_END
|
2019-03-29 21:42:58 +08:00
|
|
|
}} // namespace cv::dnn
|
2018-08-02 22:59:45 +08:00
|
|
|
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
namespace opencv_test {
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2019-06-15 20:17:25 +08:00
|
|
|
void initDNNTests();
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
using namespace cv::dnn;
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
static inline const std::string &getOpenCVExtraDir()
|
2018-04-18 22:26:54 +08:00
|
|
|
{
|
2019-03-29 21:42:58 +08:00
|
|
|
return cvtest::TS::ptr()->get_data_path();
|
2018-04-18 22:26:54 +08:00
|
|
|
}
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
void normAssert(
|
|
|
|
cv::InputArray ref, cv::InputArray test, const char *comment = "",
|
|
|
|
double l1 = 0.00001, double lInf = 0.0001);
|
2018-04-18 22:26:54 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
std::vector<cv::Rect2d> matToBoxes(const cv::Mat& m);
|
2018-04-18 22:26:54 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
void normAssertDetections(
|
|
|
|
const std::vector<int>& refClassIds,
|
|
|
|
const std::vector<float>& refScores,
|
|
|
|
const std::vector<cv::Rect2d>& refBoxes,
|
|
|
|
const std::vector<int>& testClassIds,
|
|
|
|
const std::vector<float>& testScores,
|
|
|
|
const std::vector<cv::Rect2d>& testBoxes,
|
|
|
|
const char *comment = "", double confThreshold = 0.0,
|
|
|
|
double scores_diff = 1e-5, double boxes_iou_diff = 1e-4);
|
2018-04-18 22:26:54 +08:00
|
|
|
|
|
|
|
// For SSD-based object detection networks which produce output of shape 1x1xNx7
|
|
|
|
// where N is a number of detections and an every detection is represented by
|
|
|
|
// a vector [batchId, classId, confidence, left, top, right, bottom].
|
2019-03-29 21:42:58 +08:00
|
|
|
void normAssertDetections(
|
|
|
|
cv::Mat ref, cv::Mat out, const char *comment = "",
|
|
|
|
double confThreshold = 0.0, double scores_diff = 1e-5,
|
|
|
|
double boxes_iou_diff = 1e-4);
|
2018-04-18 22:26:54 +08:00
|
|
|
|
2019-05-29 20:29:31 +08:00
|
|
|
void readFileContent(const std::string& filename, CV_OUT std::vector<char>& content);
|
2017-10-28 00:01:41 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
#ifdef HAVE_INF_ENGINE
|
|
|
|
bool validateVPUType();
|
|
|
|
#endif
|
2018-08-30 22:53:41 +08:00
|
|
|
|
2018-12-05 23:11:45 +08:00
|
|
|
testing::internal::ParamGenerator< tuple<Backend, Target> > dnnBackendsAndTargets(
|
2018-08-30 22:53:41 +08:00
|
|
|
bool withInferenceEngine = true,
|
|
|
|
bool withHalide = false,
|
2019-12-02 21:16:06 +08:00
|
|
|
bool withCpuOCV = true,
|
|
|
|
bool withNgraph = true
|
2019-03-29 21:42:58 +08:00
|
|
|
);
|
2018-08-30 22:53:41 +08:00
|
|
|
|
2019-12-02 21:16:06 +08:00
|
|
|
testing::internal::ParamGenerator< tuple<Backend, Target> > dnnBackendsAndTargetsIE();
|
|
|
|
|
2018-11-15 04:25:23 +08:00
|
|
|
|
|
|
|
class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
dnn::Backend backend;
|
|
|
|
dnn::Target target;
|
|
|
|
double default_l1, default_lInf;
|
|
|
|
|
|
|
|
DNNTestLayer()
|
|
|
|
{
|
|
|
|
backend = (dnn::Backend)(int)get<0>(GetParam());
|
|
|
|
target = (dnn::Target)(int)get<1>(GetParam());
|
|
|
|
getDefaultThresholds(backend, target, &default_l1, &default_lInf);
|
|
|
|
}
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)
|
|
|
|
{
|
|
|
|
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)
|
|
|
|
{
|
|
|
|
*l1 = 4e-3;
|
|
|
|
*lInf = 2e-2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*l1 = 1e-5;
|
|
|
|
*lInf = 1e-4;
|
|
|
|
}
|
|
|
|
}
|
2018-11-15 04:25:23 +08:00
|
|
|
|
2018-12-05 23:11:45 +08:00
|
|
|
static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)
|
|
|
|
{
|
2019-12-02 21:16:06 +08:00
|
|
|
if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
|
|
|
&& target == DNN_TARGET_MYRIAD)
|
2019-03-29 21:42:58 +08:00
|
|
|
{
|
|
|
|
if (inp && ref && inp->dims == 4 && ref->dims == 4 &&
|
|
|
|
inp->size[0] != 1 && inp->size[0] != ref->size[0])
|
2019-06-15 20:17:25 +08:00
|
|
|
{
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
2019-03-29 21:42:58 +08:00
|
|
|
throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");
|
2019-06-15 20:17:25 +08:00
|
|
|
}
|
2019-03-29 21:42:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-15 04:25:23 +08:00
|
|
|
|
2019-12-02 21:16:06 +08:00
|
|
|
void expectNoFallbacks(Net& net, bool raiseError = true)
|
2019-04-19 19:54:08 +08:00
|
|
|
{
|
|
|
|
// Check if all the layers are supported with current backend and target.
|
|
|
|
// Some layers might be fused so their timings equal to zero.
|
|
|
|
std::vector<double> timings;
|
|
|
|
net.getPerfProfile(timings);
|
|
|
|
std::vector<String> names = net.getLayerNames();
|
|
|
|
CV_Assert(names.size() == timings.size());
|
|
|
|
|
2019-12-02 21:16:06 +08:00
|
|
|
bool hasFallbacks = false;
|
2019-04-19 19:54:08 +08:00
|
|
|
for (int i = 0; i < names.size(); ++i)
|
|
|
|
{
|
|
|
|
Ptr<dnn::Layer> l = net.getLayer(net.getLayerId(names[i]));
|
|
|
|
bool fused = !timings[i];
|
|
|
|
if ((!l->supportBackend(backend) || l->preferableTarget != target) && !fused)
|
2019-12-02 21:16:06 +08:00
|
|
|
{
|
|
|
|
hasFallbacks = true;
|
|
|
|
std::cout << "FALLBACK: Layer [" << l->type << "]:[" << l->name << "] is expected to has backend implementation" << endl;
|
|
|
|
}
|
2019-04-19 19:54:08 +08:00
|
|
|
}
|
2019-12-02 21:16:06 +08:00
|
|
|
if (hasFallbacks && raiseError)
|
|
|
|
CV_Error(Error::StsNotImplemented, "Implementation fallbacks are not expected in this test");
|
2019-04-19 19:54:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void expectNoFallbacksFromIE(Net& net)
|
|
|
|
{
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
2019-04-19 19:54:08 +08:00
|
|
|
expectNoFallbacks(net);
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
|
|
|
expectNoFallbacks(net, false);
|
2019-04-19 19:54:08 +08:00
|
|
|
}
|
|
|
|
|
2018-11-15 04:25:23 +08:00
|
|
|
protected:
|
|
|
|
void checkBackend(Mat* inp = 0, Mat* ref = 0)
|
|
|
|
{
|
|
|
|
checkBackend(backend, target, inp, ref);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
#endif
|