2017-06-26 18:35:51 +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.
|
|
|
|
//
|
2019-03-29 21:42:58 +08:00
|
|
|
// Copyright (C) 2017-2019, Intel Corporation, all rights reserved.
|
2017-06-26 18:35:51 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
|
|
|
|
// This tests doesn't require any external data. They just compare outputs of
|
|
|
|
// layers using different computation backends. Input and parameters are random.
|
|
|
|
|
2017-06-29 20:42:09 +08:00
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
namespace opencv_test { namespace {
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace cv::dnn;
|
|
|
|
using namespace testing;
|
|
|
|
|
2019-12-20 21:36:32 +08:00
|
|
|
static void test(Mat& input, Net& net, Backend backendId, Target targetId, bool skipCheck = false, bool randInput = true, double l1 = 0.0, double lInf = 0.0)
|
2017-06-26 18:35:51 +08:00
|
|
|
{
|
2018-06-27 21:34:36 +08:00
|
|
|
DNNTestLayer::checkBackend(backendId, targetId);
|
2019-12-13 23:29:39 +08:00
|
|
|
if (randInput)
|
|
|
|
randu(input, -1.0f, 1.0f);
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
net.setInput(input);
|
2018-06-01 15:54:12 +08:00
|
|
|
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
2018-06-27 21:34:36 +08:00
|
|
|
Mat outputDefault = net.forward().clone();
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
net.setPreferableBackend(backendId);
|
|
|
|
net.setPreferableTarget(targetId);
|
|
|
|
Mat outputHalide = net.forward().clone();
|
|
|
|
|
2018-07-25 21:53:37 +08:00
|
|
|
if (skipCheck)
|
|
|
|
return;
|
|
|
|
|
2019-12-20 21:36:32 +08:00
|
|
|
double default_l1, default_lInf;
|
|
|
|
DNNTestLayer::getDefaultThresholds(backendId, targetId, &default_l1, &default_lInf);
|
|
|
|
if (l1 == 0.0)
|
|
|
|
l1 = default_l1;
|
|
|
|
if (lInf == 0.0)
|
|
|
|
lInf = default_lInf;
|
2018-06-27 21:34:36 +08:00
|
|
|
normAssert(outputDefault, outputHalide, "", l1, lInf);
|
2021-11-26 03:56:27 +08:00
|
|
|
if (cvtest::debugLevel > 0 || testing::Test::HasFailure())
|
|
|
|
{
|
|
|
|
std::cout << "l1=" << l1 << " lInf=" << lInf << std::endl;
|
|
|
|
std::cout << outputDefault.reshape(1, outputDefault.total()).t() << std::endl;
|
|
|
|
std::cout << outputHalide.reshape(1, outputDefault.total()).t() << std::endl;
|
|
|
|
}
|
2018-06-27 21:34:36 +08:00
|
|
|
}
|
|
|
|
|
2019-12-20 21:36:32 +08:00
|
|
|
static void test(LayerParams& params, Mat& input, Backend backendId, Target targetId, bool skipCheck = false, double l1 = 0.0, double lInf = 0.0)
|
2018-06-27 21:34:36 +08:00
|
|
|
{
|
|
|
|
Net net;
|
|
|
|
net.addLayerToPrev(params.name, params.type, params);
|
2019-12-20 21:36:32 +08:00
|
|
|
test(input, net, backendId, targetId, skipCheck, true, l1, lInf);
|
2018-06-27 21:34:36 +08:00
|
|
|
}
|
|
|
|
|
2018-08-30 22:53:41 +08:00
|
|
|
static inline testing::internal::ParamGenerator<tuple<Backend, Target> > dnnBackendsAndTargetsWithHalide()
|
2018-06-27 21:34:36 +08:00
|
|
|
{
|
2018-08-30 22:53:41 +08:00
|
|
|
return dnnBackendsAndTargets(true, true, false); // OpenCV/CPU is used as reference
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
class Test_Halide_layers : public DNNTestLayer {};
|
|
|
|
|
2017-09-22 17:12:03 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Padding
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-06-27 21:34:36 +08:00
|
|
|
TEST_P(Test_Halide_layers, Padding)
|
2017-09-22 17:12:03 +08:00
|
|
|
{
|
|
|
|
static const int kNumRuns = 10;
|
|
|
|
std::vector<int> paddings(8);
|
2018-05-22 21:31:01 +08:00
|
|
|
cv::RNG& rng = cv::theRNG();
|
2017-09-22 17:12:03 +08:00
|
|
|
for (int t = 0; t < kNumRuns; ++t)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < paddings.size(); ++i)
|
2018-05-22 21:31:01 +08:00
|
|
|
paddings[i] = rng(5);
|
2017-09-22 17:12:03 +08:00
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("paddings", DictValue::arrayInt<int*>(&paddings[0], paddings.size()));
|
|
|
|
lp.type = "Padding";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1 + (int)rng(10), 1 + (int)rng(10), 1 + (int)rng(10), 1 + (int)rng(10)};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(lp, input, backend, target);
|
2017-09-22 17:12:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convolution
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3i, Size, Size, Size, Size, Size, bool, tuple<Backend, Target> > > Convolution;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Convolution, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam())[0];
|
|
|
|
int outChannels = get<0>(GetParam())[1];
|
|
|
|
int group = get<0>(GetParam())[2];
|
|
|
|
Size inSize = get<1>(GetParam());
|
|
|
|
Size kernel = get<2>(GetParam());
|
|
|
|
Size stride = get<3>(GetParam());
|
|
|
|
Size pad = get<4>(GetParam());
|
|
|
|
Size dilation = get<5>(GetParam());
|
|
|
|
bool hasBias = get<6>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<7>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<7>(GetParam()));
|
2018-06-27 21:34:36 +08:00
|
|
|
|
2018-07-25 21:53:37 +08:00
|
|
|
bool skipCheck = false;
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {outChannels, inChannels / group, kernel.height, kernel.width};
|
|
|
|
Mat weights(4, &sz[0], CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(weights, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("kernel_w", kernel.width);
|
|
|
|
lp.set("kernel_h", kernel.height);
|
|
|
|
lp.set("pad_w", pad.width);
|
|
|
|
lp.set("pad_h", pad.height);
|
|
|
|
lp.set("stride_w", stride.width);
|
|
|
|
lp.set("stride_h", stride.height);
|
|
|
|
lp.set("dilation_w", dilation.width);
|
|
|
|
lp.set("dilation_h", dilation.height);
|
|
|
|
lp.set("num_output", outChannels);
|
|
|
|
lp.set("group", group);
|
|
|
|
lp.set("bias_term", hasBias);
|
|
|
|
lp.type = "Convolution";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
lp.blobs.push_back(weights);
|
|
|
|
if (hasBias)
|
|
|
|
{
|
2018-06-27 21:34:36 +08:00
|
|
|
Mat bias(1, outChannels, CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(bias, -1.0f, 1.0f);
|
|
|
|
lp.blobs.push_back(bias);
|
|
|
|
}
|
2018-06-27 21:34:36 +08:00
|
|
|
int inpSz[] = {1, inChannels, inSize.height, inSize.width};
|
|
|
|
Mat input(4, &inpSz[0], CV_32F);
|
2018-07-25 21:53:37 +08:00
|
|
|
test(lp, input, backendId, targetId, skipCheck);
|
|
|
|
if (skipCheck)
|
|
|
|
throw SkipTestException("Skip checks in unstable test");
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Convolution, Combine(
|
|
|
|
/*in channels, out channels, group*/
|
|
|
|
Values(Vec3i(6, 4, 1), Vec3i(6, 9, 1),
|
|
|
|
Vec3i(6, 4, 2), Vec3i(6, 9, 3)),
|
|
|
|
/*in size*/ Values(Size(5, 6)),
|
|
|
|
/*kernel*/ Values(Size(3, 1), Size(1, 3)),
|
|
|
|
/*stride*/ Values(Size(1, 1), Size(2, 2)),
|
|
|
|
/*pad*/ Values(Size(1, 0), Size(0, 1)),
|
|
|
|
/*dilation*/ Values(Size(1, 1), Size(2, 2)),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*has bias*/ Bool(),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Deconvolution
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3i, Size, Size, Size, Size, Vec4i, bool, tuple<Backend, Target> > > Deconvolution;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Deconvolution, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam())[0];
|
|
|
|
int outChannels = get<0>(GetParam())[1];
|
|
|
|
int group = get<0>(GetParam())[2];
|
|
|
|
Size inSize = get<1>(GetParam());
|
|
|
|
Size kernel = get<2>(GetParam());
|
|
|
|
Size pad = get<3>(GetParam());
|
|
|
|
Size dilation = get<4>(GetParam());
|
|
|
|
Size stride = Size(get<5>(GetParam())[0], get<5>(GetParam())[1]);
|
|
|
|
Size adjPad = Size(get<5>(GetParam())[2], get<5>(GetParam())[3]);
|
|
|
|
bool hasBias = get<6>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<7>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<7>(GetParam()));
|
2019-03-29 21:42:58 +08:00
|
|
|
|
2022-03-31 03:03:38 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16)
|
|
|
|
&& inChannels == 6 && outChannels == 4 && group == 1
|
|
|
|
&& kernel == Size(3, 1) && pad == Size(0, 1)
|
|
|
|
&& stride == Size(1, 1) && dilation == Size(1, 1))
|
|
|
|
applyTestTag(targetId == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
|
|
|
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
|
|
|
|
);
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16)
|
|
|
|
&& inChannels == 6 && outChannels == 4 && group == 1
|
|
|
|
&& kernel == Size(1, 3) && pad == Size(1, 0)
|
|
|
|
&& stride == Size(1, 1) && dilation == Size(1, 1))
|
|
|
|
applyTestTag(targetId == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16,
|
|
|
|
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
2019-04-01 20:00:25 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD
|
2019-03-29 21:42:58 +08:00
|
|
|
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
|
|
|
&& inChannels == 6 && outChannels == 4 && group == 1
|
|
|
|
&& kernel == Size(1, 3) && pad == Size(1, 0)
|
|
|
|
&& stride == Size(1, 1) && dilation == Size(1, 1))
|
2019-06-15 20:17:25 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
2019-03-29 21:42:58 +08:00
|
|
|
#endif
|
|
|
|
|
2019-12-20 21:36:32 +08:00
|
|
|
if (targetId == DNN_TARGET_CUDA_FP16)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA_FP16);
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {inChannels, outChannels / group, kernel.height, kernel.width};
|
|
|
|
Mat weights(4, &sz[0], CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(weights, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("kernel_w", kernel.width);
|
|
|
|
lp.set("kernel_h", kernel.height);
|
|
|
|
lp.set("pad_w", pad.width);
|
|
|
|
lp.set("pad_h", pad.height);
|
|
|
|
lp.set("stride_w", stride.width);
|
|
|
|
lp.set("stride_h", stride.height);
|
|
|
|
lp.set("dilation_w", dilation.width);
|
|
|
|
lp.set("dilation_h", dilation.height);
|
|
|
|
lp.set("adj_w", adjPad.width);
|
|
|
|
lp.set("adj_h", adjPad.height);
|
|
|
|
lp.set("num_output", outChannels);
|
|
|
|
lp.set("group", group);
|
|
|
|
lp.set("bias_term", hasBias);
|
|
|
|
lp.type = "Deconvolution";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
lp.blobs.push_back(weights);
|
|
|
|
if (hasBias)
|
|
|
|
{
|
2018-06-27 21:34:36 +08:00
|
|
|
Mat bias(1, outChannels, CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(bias, -1.0f, 1.0f);
|
|
|
|
lp.blobs.push_back(bias);
|
|
|
|
}
|
2018-06-27 21:34:36 +08:00
|
|
|
int inpSz[] = {1, inChannels, inSize.height, inSize.width};
|
|
|
|
Mat input(4, &inpSz[0], CV_32F);
|
|
|
|
test(lp, input, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Deconvolution, Combine(
|
|
|
|
/*in channels, out channels, group*/
|
2017-09-27 23:58:50 +08:00
|
|
|
Values(Vec3i(6, 4, 1), Vec3i(6, 9, 3)),
|
2017-06-26 18:35:51 +08:00
|
|
|
/*in size*/ Values(Size(5, 6)),
|
|
|
|
/*kernel*/ Values(Size(3, 1), Size(1, 3)),
|
|
|
|
/*pad*/ Values(Size(1, 0), Size(0, 1)),
|
2019-05-28 23:24:25 +08:00
|
|
|
/*dilation*/ Values(Size(1, 1)),
|
2017-06-26 18:35:51 +08:00
|
|
|
/*stride, adj. pad*/ Values(Vec4i(1,1, 0,0), Vec4i(2,2, 1,0), Vec4i(1,2, 0,1)),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*has bias*/ Bool(),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LRN
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3i, int, Vec3f, bool, std::string, tuple<Backend, Target> > > LRN;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(LRN, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam())[0];
|
|
|
|
Size inSize = Size(get<0>(GetParam())[1], get<0>(GetParam())[2]);
|
|
|
|
int localSize = get<1>(GetParam());
|
|
|
|
float alpha = get<2>(GetParam())[0];
|
|
|
|
float beta = get<2>(GetParam())[1];
|
|
|
|
float bias = get<2>(GetParam())[2];
|
|
|
|
bool normBySize = get<3>(GetParam());
|
|
|
|
std::string nrmType = get<4>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<5>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<5>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2021-11-30 20:08:35 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
2019-03-25 17:49:02 +08:00
|
|
|
if ((inSize.width == 5 || inSize.height == 5) && targetId == DNN_TARGET_MYRIAD &&
|
|
|
|
nrmType == "ACROSS_CHANNELS")
|
2019-06-15 20:17:25 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD);
|
2021-11-30 20:08:35 +08:00
|
|
|
#endif
|
2019-03-25 17:49:02 +08:00
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams lp;
|
|
|
|
lp.set("norm_region", nrmType);
|
|
|
|
lp.set("local_size", localSize);
|
|
|
|
lp.set("alpha", alpha);
|
|
|
|
lp.set("beta", beta);
|
|
|
|
lp.set("bias", bias);
|
|
|
|
lp.set("norm_by_size", normBySize);
|
|
|
|
lp.type = "LRN";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inChannels, inSize.height, inSize.width};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
2021-03-25 00:14:23 +08:00
|
|
|
|
|
|
|
double l1 = 0.0, lInf = 0.0;
|
|
|
|
// The OpenCL kernels use the native_ math functions which have
|
|
|
|
// implementation defined accuracy, so we use relaxed thresholds. See
|
|
|
|
// https://github.com/opencv/opencv/issues/9821 for more details.
|
|
|
|
if (targetId == DNN_TARGET_OPENCL)
|
|
|
|
{
|
|
|
|
l1 = 0.01;
|
|
|
|
lInf = 0.01;
|
|
|
|
}
|
|
|
|
test(lp, input, backendId, targetId, false, l1, lInf);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, LRN, Combine(
|
|
|
|
/*input ch,w,h*/ Values(Vec3i(6, 5, 8), Vec3i(7, 11, 6)),
|
|
|
|
/*local size*/ Values(3, 5),
|
|
|
|
Values(Vec3f(0.9f, 1.0f, 1.1f), Vec3f(0.9f, 1.1f, 1.0f),
|
2019-02-21 16:42:55 +08:00
|
|
|
/*alpha, beta, bias*/ Vec3f(1.0f, 0.9f, 1.1f), Vec3f(1.0f, 1.1f, 0.9f),
|
|
|
|
Vec3f(1.1f, 0.9f, 1.0f), Vec3f(1.1f, 1.0f, 0.9f)),
|
2017-06-26 18:35:51 +08:00
|
|
|
/*norm_by_size*/ Bool(),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*norm_type*/ Values("ACROSS_CHANNELS", "WITHIN_CHANNEL"),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Average pooling
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<int, Size, Size, Size, tuple<Backend, Target> > > AvePooling;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(AvePooling, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam());
|
|
|
|
Size outSize = get<1>(GetParam());; // Input size will be computed from parameters.
|
|
|
|
Size kernel = get<2>(GetParam());
|
|
|
|
Size stride = get<3>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<4>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<4>(GetParam()));
|
2019-03-29 21:42:58 +08:00
|
|
|
|
2019-06-14 23:17:02 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD
|
2019-03-29 21:42:58 +08:00
|
|
|
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
|
|
|
&& kernel == Size(1, 1) && (stride == Size(1, 1) || stride == Size(2, 2)))
|
2019-06-15 20:17:25 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
2019-03-29 21:42:58 +08:00
|
|
|
#endif
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
const int inWidth = (outSize.width - 1) * stride.width + kernel.width;
|
|
|
|
const int inHeight = (outSize.height - 1) * stride.height + kernel.height;
|
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("pool", "ave");
|
|
|
|
lp.set("kernel_w", kernel.width);
|
|
|
|
lp.set("kernel_h", kernel.height);
|
|
|
|
lp.set("stride_w", stride.width);
|
|
|
|
lp.set("stride_h", stride.height);
|
|
|
|
lp.type = "Pooling";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inChannels, inHeight, inWidth};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(lp, input, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, AvePooling, Combine(
|
|
|
|
/*in channels*/ Values(3, 4),
|
|
|
|
/*out size*/ Values(Size(1, 1), Size(2, 2), Size(3, 2), Size(4, 7)),
|
|
|
|
/*kernel*/ Values(Size(1, 1), Size(2, 2), Size(3, 3), Size(3, 2)),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*stride*/ Values(Size(1, 1), Size(2, 2), Size(3, 2)),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Maximum pooling
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<int, Size, Size, Size, Size, tuple<Backend, Target> > > MaxPooling;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(MaxPooling, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam());
|
|
|
|
Size inSize = get<1>(GetParam());
|
|
|
|
Size kernel = get<2>(GetParam());
|
|
|
|
Size stride = get<3>(GetParam());
|
|
|
|
Size pad = get<4>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<5>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<5>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2023-08-04 16:28:51 +08:00
|
|
|
// https://github.com/openvinotoolkit/openvino/issues/18731
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && stride != Size(1, 1))
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
2019-03-29 21:42:58 +08:00
|
|
|
|
2019-04-01 20:00:25 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD
|
2019-03-29 21:42:58 +08:00
|
|
|
&& getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
|
|
|
|
&& (stride == Size(1, 1) || stride == Size(2, 2))
|
|
|
|
&& (pad == Size(0, 1) || pad == Size(1, 1))
|
|
|
|
)
|
2019-12-02 21:16:06 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 17:01:25 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_MYRIAD)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
|
|
|
#endif
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams lp;
|
|
|
|
lp.set("pool", "max");
|
|
|
|
lp.set("kernel_w", kernel.width);
|
|
|
|
lp.set("kernel_h", kernel.height);
|
|
|
|
lp.set("stride_w", stride.width);
|
|
|
|
lp.set("stride_h", stride.height);
|
|
|
|
lp.set("pad_w", pad.width);
|
|
|
|
lp.set("pad_h", pad.height);
|
|
|
|
lp.type = "Pooling";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inChannels, inSize.height, inSize.width};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(lp, input, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, MaxPooling, Combine(
|
|
|
|
/*in channels*/ Values(3, 4),
|
|
|
|
/*in size*/ Values(Size(5, 5), Size(7, 6)),
|
|
|
|
/*kernel*/ Values(Size(2, 2), Size(3, 3), Size(3, 2)),
|
|
|
|
/*stride*/ Values(Size(1, 1), Size(2, 2), Size(3, 2)),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*pad*/ Values(Size(0, 0), Size(1, 1), Size(0, 1)),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Fully-connected
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2023-08-16 20:46:11 +08:00
|
|
|
typedef TestWithParam<tuple<int, int, Size, int, bool, tuple<Backend, Target> > > FullyConnected;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(FullyConnected, Accuracy)
|
|
|
|
{
|
2023-08-16 20:46:11 +08:00
|
|
|
int batch = get<0>(GetParam());
|
|
|
|
int inChannels = get<1>(GetParam());
|
|
|
|
Size inSize = get<2>(GetParam());
|
|
|
|
int outChannels = get<3>(GetParam());
|
|
|
|
bool hasBias = get<4>(GetParam());
|
|
|
|
Backend backendId = get<0>(get<5>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<5>(GetParam()));
|
2021-11-30 20:08:35 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
2019-12-24 18:34:33 +08:00
|
|
|
if ((backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ||
|
|
|
|
backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && (targetId == DNN_TARGET_OPENCL_FP16 ||
|
2019-08-29 15:52:02 +08:00
|
|
|
(targetId == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X))) {
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16);
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X);
|
|
|
|
}
|
2021-11-30 20:08:35 +08:00
|
|
|
#endif
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
Mat weights(outChannels, inChannels * inSize.height * inSize.width, CV_32F);
|
|
|
|
randu(weights, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
Mat bias(1, outChannels, CV_32F);
|
|
|
|
randu(bias, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("num_output", outChannels);
|
|
|
|
lp.set("bias_term", hasBias);
|
|
|
|
lp.blobs.push_back(weights);
|
|
|
|
lp.blobs.push_back(bias);
|
|
|
|
lp.type = "InnerProduct";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2023-08-16 20:46:11 +08:00
|
|
|
int sz[] = {batch, inChannels, inSize.height, inSize.width};
|
2018-06-27 21:34:36 +08:00
|
|
|
Mat input(4, &sz[0], CV_32F);
|
2019-12-20 21:36:32 +08:00
|
|
|
|
|
|
|
double l1 = 0.0;
|
2021-11-30 20:08:35 +08:00
|
|
|
double lInf = 0.0;
|
|
|
|
#if defined(INF_ENGINE_RELEASE)
|
|
|
|
if (targetId == DNN_TARGET_MYRIAD)
|
|
|
|
{
|
|
|
|
l1 = 0.015;
|
|
|
|
lInf = 0.025;
|
|
|
|
}
|
2021-12-03 20:32:49 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_OPENCL_FP16)
|
2021-11-30 20:08:35 +08:00
|
|
|
{
|
|
|
|
l1 = 0.01;
|
|
|
|
}
|
2023-08-04 16:28:51 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_OPENCL)
|
|
|
|
{
|
|
|
|
l1 = 5e-3;
|
|
|
|
lInf = 7e-3;
|
|
|
|
}
|
2021-11-30 20:08:35 +08:00
|
|
|
#endif
|
2019-12-20 21:36:32 +08:00
|
|
|
if (targetId == DNN_TARGET_CUDA_FP16)
|
|
|
|
l1 = 0.015;
|
2021-12-03 20:32:49 +08:00
|
|
|
|
2021-11-30 20:08:35 +08:00
|
|
|
test(lp, input, backendId, targetId, false, l1, lInf);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, FullyConnected, Combine(
|
2023-08-16 20:46:11 +08:00
|
|
|
/*batch*/ Values(1, 2, 4, 8, 16),
|
2017-06-26 18:35:51 +08:00
|
|
|
/*in channels*/ Values(3, 4),
|
|
|
|
/*in size*/ Values(Size(5, 4), Size(4, 5), Size(1, 1)),
|
|
|
|
/*out channels*/ Values(3, 4),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*has bias*/ Bool(),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SoftMax
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<int, tuple<Backend, Target> > > SoftMax;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(SoftMax, Accuracy)
|
|
|
|
{
|
|
|
|
int inChannels = get<0>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams lp;
|
2020-03-22 23:50:15 +08:00
|
|
|
lp.type = "Softmax";
|
2017-06-26 18:35:51 +08:00
|
|
|
lp.name = "testLayer";
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inChannels, 1, 1};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(lp, input, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, SoftMax, Combine(
|
|
|
|
Values(3, 4, 5, 1024),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
|
|
|
));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Max pooling - unpooling
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2018-06-27 21:34:36 +08:00
|
|
|
TEST_P(Test_Halide_layers, MaxPoolUnpool)
|
2017-06-26 18:35:51 +08:00
|
|
|
{
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
|
|
|
if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH);
|
2018-06-27 21:34:36 +08:00
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams pool;
|
|
|
|
pool.set("pool", "max");
|
|
|
|
pool.set("kernel_w", 2);
|
|
|
|
pool.set("kernel_h", 2);
|
|
|
|
pool.set("stride_w", 2);
|
|
|
|
pool.set("stride_h", 2);
|
|
|
|
pool.set("pad_w", 0);
|
|
|
|
pool.set("pad_h", 0);
|
|
|
|
pool.type = "Pooling";
|
|
|
|
pool.name = "testPool";
|
|
|
|
|
|
|
|
LayerParams unpool;
|
|
|
|
unpool.set("pool_k_w", 2);
|
|
|
|
unpool.set("pool_k_h", 2);
|
|
|
|
unpool.set("pool_stride_w", 2);
|
|
|
|
unpool.set("pool_stride_h", 2);
|
|
|
|
unpool.set("pool_pad_w", 0);
|
|
|
|
unpool.set("pool_pad_h", 0);
|
|
|
|
unpool.type = "MaxUnpool";
|
|
|
|
unpool.name = "testUnpool";
|
|
|
|
|
|
|
|
Net net;
|
|
|
|
int poolId = net.addLayer(pool.name, pool.type, pool);
|
|
|
|
net.connect(0, 0, poolId, 0);
|
|
|
|
|
|
|
|
int unpoolId = net.addLayer(unpool.name, unpool.type, unpool);
|
|
|
|
net.connect(poolId, 0, unpoolId, 0);
|
|
|
|
net.connect(poolId, 1, unpoolId, 1);
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, 1, 4, 4};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(input, net, backend, target);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AvePooling + in-place layers
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static const int kNumChannels = 3;
|
|
|
|
|
2019-12-20 21:36:32 +08:00
|
|
|
void testInPlaceActivation(LayerParams& lp, Backend backendId, Target targetId, double l1 = 0.0, double lInf = 0.0)
|
2017-06-26 18:35:51 +08:00
|
|
|
{
|
|
|
|
EXPECT_FALSE(lp.name.empty());
|
|
|
|
|
|
|
|
LayerParams pool;
|
|
|
|
pool.set("pool", "ave");
|
|
|
|
pool.set("kernel_w", 2);
|
|
|
|
pool.set("kernel_h", 2);
|
|
|
|
pool.set("stride_w", 2);
|
|
|
|
pool.set("stride_h", 2);
|
|
|
|
pool.type = "Pooling";
|
2019-01-14 14:55:44 +08:00
|
|
|
pool.name = "ave_pool";
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
Net net;
|
|
|
|
int poolId = net.addLayer(pool.name, pool.type, pool);
|
|
|
|
net.connect(0, 0, poolId, 0);
|
|
|
|
net.addLayerToPrev(lp.name, lp.type, lp);
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, kNumChannels, 10, 10};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
2019-12-20 21:36:32 +08:00
|
|
|
test(input, net, backendId, targetId, false, true, l1, lInf);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<bool, bool, float, tuple<Backend, Target> > > BatchNorm;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(BatchNorm, Accuracy)
|
|
|
|
{
|
|
|
|
bool hasWeights = get<0>(GetParam());
|
|
|
|
bool hasBias = get<1>(GetParam());
|
|
|
|
float epsilon = get<2>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<3>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<3>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("has_weight", hasWeights);
|
|
|
|
lp.set("has_bias", hasBias);
|
|
|
|
lp.set("eps", epsilon);
|
|
|
|
lp.type = "BatchNorm";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
|
|
|
|
lp.blobs.reserve(4);
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2018-06-27 21:34:36 +08:00
|
|
|
lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
|
2017-06-26 18:35:51 +08:00
|
|
|
if (hasBias || hasWeights)
|
2018-06-27 21:34:36 +08:00
|
|
|
lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
for (int i = 0; i < lp.blobs.size(); ++i)
|
|
|
|
randu(lp.blobs[i], 0.0f, 1.0f);
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, BatchNorm, Combine(
|
|
|
|
/*has weights*/ Bool(),
|
|
|
|
/*has bias*/ Bool(),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*epsilon*/ Values(1e-3f, 1e-5f),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<float, tuple<Backend, Target> > > ReLU;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(ReLU, Accuracy)
|
|
|
|
{
|
|
|
|
float negativeSlope = get<0>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2019-10-04 15:29:27 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019020000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD && negativeSlope < 0)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
2019-09-03 23:58:57 +08:00
|
|
|
#endif
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams lp;
|
|
|
|
lp.set("negative_slope", negativeSlope);
|
|
|
|
lp.type = "ReLU";
|
|
|
|
lp.name = "testLayer";
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, ReLU, Combine(
|
|
|
|
/*negative slope*/ Values(2.0f, 0.3f, -0.1f, 0.0f),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<std::string, tuple<Backend, Target> > > NoParamActivation;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(NoParamActivation, Accuracy)
|
|
|
|
{
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
2022-03-31 03:03:38 +08:00
|
|
|
std::string layer_type = get<0>(GetParam());
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
LayerParams lp;
|
2022-03-31 03:03:38 +08:00
|
|
|
lp.type = layer_type;
|
2017-06-26 18:35:51 +08:00
|
|
|
lp.name = "testLayer";
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, NoParamActivation, Combine(
|
2019-12-01 16:00:58 +08:00
|
|
|
/*type*/ Values("TanH", "Sigmoid", "AbsVal", "BNLL", "Swish", "Mish"),
|
2018-06-27 21:34:36 +08:00
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3f, tuple<Backend, Target> > > Power;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Power, Accuracy)
|
|
|
|
{
|
|
|
|
float power = get<0>(GetParam())[0];
|
|
|
|
float scale = get<0>(GetParam())[1];
|
|
|
|
float shift = get<0>(GetParam())[2];
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("power", power);
|
|
|
|
lp.set("scale", scale);
|
|
|
|
lp.set("shift", shift);
|
|
|
|
lp.type = "Power";
|
|
|
|
lp.name = "testLayer";
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Power, Combine(
|
2017-06-26 18:35:51 +08:00
|
|
|
/*power, scale, shift*/ Values(Vec3f(0.9f, 1.0f, 1.1f), Vec3f(0.9f, 1.1f, 1.0f),
|
|
|
|
Vec3f(1.0f, 0.9f, 1.1f), Vec3f(1.0f, 1.1f, 0.9f),
|
2018-06-27 21:34:36 +08:00
|
|
|
Vec3f(1.1f, 0.9f, 1.0f), Vec3f(1.1f, 1.0f, 0.9f)),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
|
|
|
));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2021-02-21 00:46:00 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3f, tuple<Backend, Target> > > Exp;
|
|
|
|
TEST_P(Exp, Accuracy)
|
|
|
|
{
|
|
|
|
float base = get<0>(GetParam())[0];
|
|
|
|
float scale = get<0>(GetParam())[1];
|
|
|
|
float shift = get<0>(GetParam())[2];
|
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("base", base);
|
|
|
|
lp.set("scale", scale);
|
|
|
|
lp.set("shift", shift);
|
|
|
|
lp.type = "Exp";
|
|
|
|
lp.name = "testLayer";
|
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Exp, Combine(
|
|
|
|
/*base, scale, shift*/ Values(Vec3f(0.9f, -1.0f, 1.1f), Vec3f(0.9f, 1.1f, -1.0f),
|
|
|
|
Vec3f(-1.0f, 0.9f, 1.1f), Vec3f(-1.0f, 1.1f, 0.9f),
|
|
|
|
Vec3f(1.1f, 0.9f, -1.0f), Vec3f(1.1f, -1.0f, 0.9f)),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
|
|
|
));
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
TEST_P(Test_Halide_layers, ChannelsPReLU)
|
2017-06-26 18:35:51 +08:00
|
|
|
{
|
|
|
|
LayerParams lp;
|
|
|
|
lp.type = "ChannelsPReLU";
|
|
|
|
lp.name = "testLayer";
|
2018-06-27 21:34:36 +08:00
|
|
|
lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(lp.blobs[0], -1.0f, 1.0f);
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backend, target);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<bool, tuple<Backend, Target> > > Scale;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Scale, Accuracy)
|
|
|
|
{
|
|
|
|
bool hasBias = get<0>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<1>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<1>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
LayerParams lp;
|
|
|
|
lp.set("bias_term", hasBias);
|
|
|
|
lp.type = "Scale";
|
|
|
|
lp.name = "testLayer";
|
2018-06-27 21:34:36 +08:00
|
|
|
lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(lp.blobs[0], -1.0f, 1.0f);
|
|
|
|
if (hasBias)
|
|
|
|
{
|
2018-06-27 21:34:36 +08:00
|
|
|
lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(lp.blobs[1], -1.0f, 1.0f);
|
|
|
|
}
|
2018-06-27 21:34:36 +08:00
|
|
|
testInPlaceActivation(lp, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Scale, Combine(
|
|
|
|
Bool(),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
|
|
|
));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Concat layer
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// input --- conv --- concat --- output
|
|
|
|
// `--- conv ----^ ^ ^
|
|
|
|
// `---- ... ------' '
|
|
|
|
// `-----------------'
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3i, Vec3i, tuple<Backend, Target> > > Concat;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Concat, Accuracy)
|
|
|
|
{
|
|
|
|
Vec3i inSize = get<0>(GetParam());
|
|
|
|
Vec3i numChannels = get<1>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<2>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<2>(GetParam()));
|
2017-06-26 18:35:51 +08:00
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD
|
2019-03-29 21:42:58 +08:00
|
|
|
&& inSize == Vec3i(1, 4, 5) && numChannels == Vec3i(1, 6, 2)
|
|
|
|
)
|
2019-12-02 21:16:06 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION); // crash
|
2019-03-29 21:42:58 +08:00
|
|
|
#endif
|
|
|
|
|
2019-04-01 20:00:25 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_CPU
|
2019-03-29 21:42:58 +08:00
|
|
|
&& inSize == Vec3i(1, 4, 5) && numChannels == Vec3i(1, 6, 2)
|
|
|
|
)
|
2019-12-02 21:16:06 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION); // TODO: IE_CPU
|
2019-03-29 21:42:58 +08:00
|
|
|
#endif
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
Net net;
|
|
|
|
|
2017-07-04 22:23:47 +08:00
|
|
|
std::vector<int> convLayerIds;
|
|
|
|
convLayerIds.reserve(numChannels.channels);
|
2017-06-26 18:35:51 +08:00
|
|
|
for (int i = 0, n = numChannels.channels; i < n; ++i)
|
|
|
|
{
|
|
|
|
if (!numChannels[i])
|
|
|
|
break;
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {numChannels[i], inSize[0], 1, 1};
|
|
|
|
Mat weights(4, &sz[0], CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(weights, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
LayerParams convParam;
|
|
|
|
convParam.set("kernel_w", 1);
|
|
|
|
convParam.set("kernel_h", 1);
|
|
|
|
convParam.set("num_output", numChannels[i]);
|
|
|
|
convParam.set("bias_term", false);
|
|
|
|
convParam.type = "Convolution";
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "convLayer" << i;
|
|
|
|
convParam.name = ss.str();
|
|
|
|
convParam.blobs.push_back(weights);
|
|
|
|
|
2017-07-04 22:23:47 +08:00
|
|
|
int layerId = net.addLayer(convParam.name, convParam.type, convParam);
|
|
|
|
convLayerIds.push_back(layerId);
|
|
|
|
net.connect(0, 0, layerId, 0);
|
2017-06-27 19:52:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LayerParams concatParam;
|
|
|
|
concatParam.type = "Concat";
|
|
|
|
concatParam.name = "testLayer";
|
|
|
|
int concatId = net.addLayer(concatParam.name, concatParam.type, concatParam);
|
|
|
|
net.connect(0, 0, concatId, 0);
|
|
|
|
for (int i = 0; i < convLayerIds.size(); ++i)
|
|
|
|
{
|
|
|
|
net.connect(convLayerIds[i], 0, concatId, i + 1);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inSize[0], inSize[1], inSize[2]};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
|
|
|
test(input, net, backendId, targetId);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Concat, Combine(
|
|
|
|
/*input size*/ Values(Vec3i(1, 4, 5), Vec3i(2, 8, 6)),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*channels*/ Values(Vec3i(2, 0, 0), Vec3i(3, 4, 0), Vec3i(1, 6, 2)),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Element-wise layers
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// input --- conv --- eltwise --- output
|
|
|
|
// `--- conv ----^ ^ ^
|
|
|
|
// `---- ... ------' '
|
|
|
|
// `-----------------'
|
2018-07-10 20:00:42 +08:00
|
|
|
typedef TestWithParam<tuple<Vec3i, std::string, int, bool, tuple<Backend, Target> > > Eltwise;
|
2017-06-26 18:35:51 +08:00
|
|
|
TEST_P(Eltwise, Accuracy)
|
|
|
|
{
|
|
|
|
Vec3i inSize = get<0>(GetParam());
|
|
|
|
std::string op = get<1>(GetParam());
|
|
|
|
int numConv = get<2>(GetParam());
|
2017-07-10 17:58:11 +08:00
|
|
|
bool weighted = get<3>(GetParam());
|
2018-07-25 21:51:11 +08:00
|
|
|
Backend backendId = get<0>(get<4>(GetParam()));
|
|
|
|
Target targetId = get<1>(get<4>(GetParam()));
|
2018-06-27 21:34:36 +08:00
|
|
|
|
2021-11-26 03:56:27 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
|
|
|
|
// accuracy
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_OPENCL &&
|
|
|
|
inSize == Vec3i(1, 4, 5) && op == "sum" && numConv == 1 && !weighted)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_OPENCL &&
|
|
|
|
inSize == Vec3i(2, 8, 6) && op == "sum" && numConv == 1 && !weighted)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
|
|
|
#endif
|
|
|
|
|
2019-03-29 21:42:58 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2018050000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_MYRIAD &&
|
2019-03-29 21:42:58 +08:00
|
|
|
inSize == Vec3i(1, 4, 5))
|
2019-12-02 21:16:06 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
2019-03-29 21:42:58 +08:00
|
|
|
#endif
|
|
|
|
|
2021-11-30 20:08:35 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && numConv > 1)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
2019-02-11 22:13:39 +08:00
|
|
|
#endif
|
|
|
|
|
2021-11-30 20:08:35 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_OPENCL &&
|
2019-10-01 23:29:47 +08:00
|
|
|
op == "sum" && numConv == 1 && !weighted)
|
2019-12-02 21:16:06 +08:00
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);
|
|
|
|
#endif
|
|
|
|
|
2021-11-30 20:08:35 +08:00
|
|
|
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
|
2019-12-02 21:16:06 +08:00
|
|
|
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && numConv > 1)
|
|
|
|
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
2019-10-01 23:29:47 +08:00
|
|
|
#endif
|
|
|
|
|
2019-12-13 23:29:39 +08:00
|
|
|
bool convInputShift = 1;
|
|
|
|
int numEltwiseInputs = numConv;
|
|
|
|
if (op == "div")
|
|
|
|
{
|
|
|
|
numConv = 1;
|
|
|
|
convInputShift = 0; // first input is convolution
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:35:51 +08:00
|
|
|
Net net;
|
|
|
|
|
2017-06-27 19:52:46 +08:00
|
|
|
std::vector<int> convLayerIds(numConv);
|
2017-06-26 18:35:51 +08:00
|
|
|
for (int i = 0; i < numConv; ++i)
|
|
|
|
{
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {inSize[0], inSize[0], 1, 1};
|
|
|
|
Mat weights(4, &sz[0], CV_32F);
|
2017-06-26 18:35:51 +08:00
|
|
|
randu(weights, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
LayerParams convParam;
|
|
|
|
convParam.set("kernel_w", 1);
|
|
|
|
convParam.set("kernel_h", 1);
|
|
|
|
convParam.set("num_output", inSize[0]);
|
|
|
|
convParam.set("bias_term", false);
|
|
|
|
convParam.type = "Convolution";
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "convLayer" << i;
|
|
|
|
convParam.name = ss.str();
|
|
|
|
convParam.blobs.push_back(weights);
|
|
|
|
|
2017-06-27 19:52:46 +08:00
|
|
|
convLayerIds[i] = net.addLayer(convParam.name, convParam.type, convParam);
|
|
|
|
net.connect(0, 0, convLayerIds[i], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerParams eltwiseParam;
|
2017-07-10 17:58:11 +08:00
|
|
|
eltwiseParam.set("operation", op);
|
|
|
|
if (op == "sum" && weighted)
|
|
|
|
{
|
2018-05-22 21:31:01 +08:00
|
|
|
RNG& rng = cv::theRNG();
|
2017-07-10 17:58:11 +08:00
|
|
|
std::vector<float> coeff(1 + numConv);
|
|
|
|
for (int i = 0; i < coeff.size(); ++i)
|
|
|
|
{
|
2017-07-20 21:43:11 +08:00
|
|
|
coeff[i] = rng.uniform(-2.0f, 2.0f);
|
2017-07-10 17:58:11 +08:00
|
|
|
}
|
|
|
|
eltwiseParam.set("coeff", DictValue::arrayReal<float*>(&coeff[0], coeff.size()));
|
|
|
|
}
|
2017-06-27 19:52:46 +08:00
|
|
|
eltwiseParam.type = "Eltwise";
|
|
|
|
eltwiseParam.name = "testLayer";
|
|
|
|
int eltwiseId = net.addLayer(eltwiseParam.name, eltwiseParam.type, eltwiseParam);
|
2019-12-13 23:29:39 +08:00
|
|
|
if (convInputShift == 1)
|
|
|
|
net.connect(0, 0, eltwiseId, 0);
|
2017-06-27 19:52:46 +08:00
|
|
|
for (int i = 0; i < numConv; ++i)
|
|
|
|
{
|
2019-12-13 23:29:39 +08:00
|
|
|
net.connect(convLayerIds[i], 0, eltwiseId, i + convInputShift);
|
|
|
|
}
|
|
|
|
if (convInputShift == 0)
|
|
|
|
net.connect(0, 0, eltwiseId, numConv);
|
|
|
|
for (int i = numConv; i < numEltwiseInputs; ++i)
|
|
|
|
{
|
|
|
|
net.connect(0, 0, eltwiseId, i + 1);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {1, inSize[0], inSize[1], inSize[2]};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
2019-12-13 23:29:39 +08:00
|
|
|
if (op == "div")
|
|
|
|
randu(input, 1.0f, 1.0f); // ensure no divisor value has absouluate value of less than 0.5
|
|
|
|
test(input, net, backendId, targetId, /*skipCheck*/false, (op == "div") ? false : true);
|
2017-06-26 18:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Eltwise, Combine(
|
|
|
|
/*input size*/ Values(Vec3i(1, 4, 5), Vec3i(2, 8, 6)),
|
2021-09-22 20:17:37 +08:00
|
|
|
/*operation*/ Values("prod", "sum", "div", "max", "min"),
|
2017-07-10 17:58:11 +08:00
|
|
|
/*num convs*/ Values(1, 2, 3),
|
2018-06-27 21:34:36 +08:00
|
|
|
/*weighted(for sum only)*/ Bool(),
|
|
|
|
dnnBackendsAndTargetsWithHalide()
|
2017-06-26 18:35:51 +08:00
|
|
|
));
|
2017-09-06 15:34:07 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Mixed backends
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2018-06-27 21:34:36 +08:00
|
|
|
#ifdef HAVE_HALIDE
|
2017-09-06 15:34:07 +08:00
|
|
|
TEST(MixedBackends_Halide_Default_Halide, Accuracy)
|
|
|
|
{
|
|
|
|
// Just a layer that supports Halide backend.
|
|
|
|
LayerParams lrn;
|
|
|
|
lrn.type = "LRN";
|
|
|
|
lrn.name = "testLRN";
|
|
|
|
|
|
|
|
// Some of layers that doesn't supports Halide backend yet.
|
|
|
|
LayerParams mvn;
|
|
|
|
mvn.type = "MVN";
|
|
|
|
mvn.name = "testMVN";
|
|
|
|
|
|
|
|
// Halide layer again.
|
|
|
|
LayerParams lrn2;
|
|
|
|
lrn2.type = "LRN";
|
|
|
|
lrn2.name = "testLRN2";
|
|
|
|
|
|
|
|
Net net;
|
|
|
|
int lrnId = net.addLayer(lrn.name, lrn.type, lrn);
|
|
|
|
net.connect(0, 0, lrnId, 0);
|
|
|
|
net.addLayerToPrev(mvn.name, mvn.type, mvn);
|
|
|
|
net.addLayerToPrev(lrn2.name, lrn2.type, lrn2);
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
int sz[] = {4, 3, 5, 6};
|
|
|
|
Mat input(4, &sz[0], CV_32F);
|
2017-09-06 15:34:07 +08:00
|
|
|
randu(input, -1.0f, 1.0f);
|
|
|
|
net.setInput(input);
|
2018-06-01 15:54:12 +08:00
|
|
|
net.setPreferableBackend(DNN_BACKEND_OPENCV);
|
2017-09-06 15:34:07 +08:00
|
|
|
Mat outputDefault = net.forward().clone();
|
|
|
|
|
|
|
|
net.setPreferableBackend(DNN_BACKEND_HALIDE);
|
|
|
|
net.setInput(input);
|
|
|
|
Mat outputHalide = net.forward().clone();
|
|
|
|
normAssert(outputDefault, outputHalide);
|
|
|
|
|
|
|
|
net.setPreferableTarget(DNN_TARGET_OPENCL);
|
|
|
|
net.setInput(input);
|
|
|
|
outputHalide = net.forward().clone();
|
|
|
|
normAssert(outputDefault, outputHalide);
|
|
|
|
}
|
2017-06-26 18:35:51 +08:00
|
|
|
#endif // HAVE_HALIDE
|
|
|
|
|
2018-06-27 21:34:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_Halide_layers, dnnBackendsAndTargetsWithHalide());
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
}} // namespace
|