Commit 3d60a9b9 authored by Xuanda Yang's avatar Xuanda Yang Committed by Alexander Alekhin

Merge pull request #16156 from TH3CHARLie:3.4

* Eltwise::DIV support in Halide backend

* fix typo

* remove div from generated test suite to pass CI, switching to manual test...

* ensure divisor not near to zero

* use randu

* dnn(test): update test data for Eltwise.Accuracy/DIV layer test
parent 60f81032
...@@ -638,6 +638,12 @@ public: ...@@ -638,6 +638,12 @@ public:
for (int i = 2; i < inputBuffers.size(); ++i) for (int i = 2; i < inputBuffers.size(); ++i)
topExpr *= inputBuffers[i](x, y, c, n); topExpr *= inputBuffers[i](x, y, c, n);
break; break;
case DIV:
topExpr = inputBuffers[0](x, y, c, n) /
inputBuffers[1](x, y, c, n);
for (int i = 2; i < inputBuffers.size(); ++i)
topExpr /= inputBuffers[i](x, y, c, n);
break;
case MAX: case MAX:
topExpr = max(inputBuffers[0](x, y, c, n), topExpr = max(inputBuffers[0](x, y, c, n),
inputBuffers[1](x, y, c, n)); inputBuffers[1](x, y, c, n));
......
...@@ -16,10 +16,11 @@ using namespace cv; ...@@ -16,10 +16,11 @@ using namespace cv;
using namespace cv::dnn; using namespace cv::dnn;
using namespace testing; using namespace testing;
static void test(Mat& input, Net& net, Backend backendId, Target targetId, bool skipCheck = false) static void test(Mat& input, Net& net, Backend backendId, Target targetId, bool skipCheck = false, bool randInput = true)
{ {
DNNTestLayer::checkBackend(backendId, targetId); DNNTestLayer::checkBackend(backendId, targetId);
randu(input, -1.0f, 1.0f); if (randInput)
randu(input, -1.0f, 1.0f);
net.setInput(input); net.setInput(input);
net.setPreferableBackend(DNN_BACKEND_OPENCV); net.setPreferableBackend(DNN_BACKEND_OPENCV);
...@@ -776,6 +777,14 @@ TEST_P(Eltwise, Accuracy) ...@@ -776,6 +777,14 @@ TEST_P(Eltwise, Accuracy)
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
#endif #endif
bool convInputShift = 1;
int numEltwiseInputs = numConv;
if (op == "div")
{
numConv = 1;
convInputShift = 0; // first input is convolution
}
Net net; Net net;
std::vector<int> convLayerIds(numConv); std::vector<int> convLayerIds(numConv);
...@@ -815,20 +824,29 @@ TEST_P(Eltwise, Accuracy) ...@@ -815,20 +824,29 @@ TEST_P(Eltwise, Accuracy)
eltwiseParam.type = "Eltwise"; eltwiseParam.type = "Eltwise";
eltwiseParam.name = "testLayer"; eltwiseParam.name = "testLayer";
int eltwiseId = net.addLayer(eltwiseParam.name, eltwiseParam.type, eltwiseParam); int eltwiseId = net.addLayer(eltwiseParam.name, eltwiseParam.type, eltwiseParam);
net.connect(0, 0, eltwiseId, 0); if (convInputShift == 1)
net.connect(0, 0, eltwiseId, 0);
for (int i = 0; i < numConv; ++i) for (int i = 0; i < numConv; ++i)
{ {
net.connect(convLayerIds[i], 0, eltwiseId, i + 1); 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);
} }
int sz[] = {1, inSize[0], inSize[1], inSize[2]}; int sz[] = {1, inSize[0], inSize[1], inSize[2]};
Mat input(4, &sz[0], CV_32F); Mat input(4, &sz[0], CV_32F);
test(input, net, backendId, targetId); 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);
} }
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Eltwise, Combine( INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Eltwise, Combine(
/*input size*/ Values(Vec3i(1, 4, 5), Vec3i(2, 8, 6)), /*input size*/ Values(Vec3i(1, 4, 5), Vec3i(2, 8, 6)),
/*operation*/ Values("prod", "sum", "max"), /*operation*/ Values("prod", "sum", "div", "max"),
/*num convs*/ Values(1, 2, 3), /*num convs*/ Values(1, 2, 3),
/*weighted(for sum only)*/ Bool(), /*weighted(for sum only)*/ Bool(),
dnnBackendsAndTargetsWithHalide() dnnBackendsAndTargetsWithHalide()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment