History

FATE/dnn: add unit test for layer maximum

Guo, Yejun committed 7 years ago

Commit 9ae42c11 parent b2683c63 files · +77 −0Browse files

Unified · Split

3 files
  1. tests/dnn/Makefile +1 −0
  2. tests/dnn/dnn-layer-maximum-test.c +71 −0
  3. tests/fate/dnn.mak +5 −0
tests/dnn/Makefile+1−0
@@ -1,6 +1,7 @@
11 DNNTESTPROGS += dnn-layer-pad
22 DNNTESTPROGS += dnn-layer-conv2d
33 DNNTESTPROGS += dnn-layer-depth2space
4+DNNTESTPROGS += dnn-layer-maximum
45
56 DNNTESTOBJS := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
67 DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
tests/dnn/dnn-layer-maximum-test.c+71−0
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (c) 2019 Guo Yejun
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include <stdio.h>
22+#include <string.h>
23+#include <math.h>
24+#include "libavfilter/dnn/dnn_backend_native_layer_maximum.h"
25+
26+#define EPSON 0.00001
27+
28+static int test(void)
29+{
30+ DnnLayerMaximumParams params;
31+ DnnOperand operands[2];
32+ int32_t input_indexes[1];
33+ float input[1*1*2*3] = {
34+ -3, 2.5, 2, -2.1, 7.8, 100
35+ };
36+ float *output;
37+
38+ params.val.y = 2.3;
39+
40+ operands[0].data = input;
41+ operands[0].dims[0] = 1;
42+ operands[0].dims[1] = 1;
43+ operands[0].dims[2] = 2;
44+ operands[0].dims[3] = 3;
45+ operands[1].data = NULL;
46+
47+ input_indexes[0] = 0;
48+ dnn_execute_layer_maximum(operands, input_indexes, 1, &params);
49+
50+ output = operands[1].data;
51+ for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
52+ float expected_output = input[i] > params.val.y ? input[i] : params.val.y;
53+ if (fabs(output[i] - expected_output) > EPSON) {
54+ printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
55+ av_freep(&output);
56+ return 1;
57+ }
58+ }
59+
60+ av_freep(&output);
61+ return 0;
62+
63+}
64+
65+int main(int argc, char **argv)
66+{
67+ if (test())
68+ return 1;
69+
70+ return 0;
71+}
tests/fate/dnn.mak+5−0
@@ -13,6 +13,11 @@ fate-dnn-layer-depth2space: $(DNNTESTSDIR)/dnn-layer-depth2space-test$(EXESUF) · 12 unmodified lines
1313 fate-dnn-layer-depth2space: CMD = run $(DNNTESTSDIR)/dnn-layer-depth2space-test$(EXESUF)
1414 fate-dnn-layer-depth2space: CMP = null
1515
16+FATE_DNN += fate-dnn-layer-maximum
17+fate-dnn-layer-maximum: $(DNNTESTSDIR)/dnn-layer-maximum-test$(EXESUF)
18+fate-dnn-layer-maximum: CMD = run $(DNNTESTSDIR)/dnn-layer-maximum-test$(EXESUF)
19+fate-dnn-layer-maximum: CMP = null
20+
1621 FATE-yes += $(FATE_DNN)
1722
1823 fate-dnn: $(FATE_DNN)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t