1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #14682 from l-bat:axpy_layer

* Add Axpy layer

* Fix test

* fix caffe importer
This commit is contained in:
Lubov Batanina
2019-06-05 00:18:06 +03:00
committed by Alexander Alekhin
parent f1fb002682
commit 3efd2df87f
3 changed files with 65 additions and 1 deletions
+43
View File
@@ -109,6 +109,49 @@ TEST(Test_Caffe, read_googlenet)
ASSERT_FALSE(net.empty());
}
TEST_P(Test_Caffe_nets, Axpy)
{
if (backend == DNN_BACKEND_INFERENCE_ENGINE)
throw SkipTestException("");
String proto = _tf("axpy.prototxt");
Net net = readNetFromCaffe(proto);
checkBackend();
net.setPreferableBackend(backend);
net.setPreferableTarget(target);
int size[] = {1, 2, 3, 4};
int scale_size[] = {1, 2, 1, 1};
Mat scale(4, &scale_size[0], CV_32F);
Mat shift(4, &size[0], CV_32F);
Mat inp(4, &size[0], CV_32F);
randu(scale, -1.0f, 1.0f);
randu(shift, -1.0f, 1.0f);
randu(inp, -1.0f, 1.0f);
net.setInput(scale, "scale");
net.setInput(shift, "shift");
net.setInput(inp, "data");
Mat out = net.forward();
Mat ref(4, &size[0], inp.type());
for (int i = 0; i < inp.size[1]; i++) {
for (int h = 0; h < inp.size[2]; h++) {
for (int w = 0; w < inp.size[3]; w++) {
int idx[] = {0, i, h, w};
int scale_idx[] = {0, i, 0, 0};
ref.at<float>(idx) = inp.at<float>(idx) * scale.at<float>(scale_idx) +
shift.at<float>(idx);
}
}
}
float l1 = (target == DNN_TARGET_OPENCL_FP16) ? 2e-4 : 1e-5;
float lInf = (target == DNN_TARGET_OPENCL_FP16) ? 1e-3 : 1e-4;
normAssert(ref, out, "", l1, lInf);
}
typedef testing::TestWithParam<tuple<bool, Target> > Reproducibility_AlexNet;
TEST_P(Reproducibility_AlexNet, Accuracy)
{