1 // Tencent is pleased to support the open source community by making ncnn available.
2 //
3 // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
4 //
5 // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // https://opensource.org/licenses/BSD-3-Clause
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 // specific language governing permissions and limitations under the License.
14
15 #include "layer/priorbox.h"
16 #include "testutil.h"
17
test_priorbox_caffe()18 static int test_priorbox_caffe()
19 {
20 ncnn::Mat min_sizes(1);
21 min_sizes[0] = 105.f;
22
23 ncnn::Mat max_sizes(1);
24 max_sizes[0] = 150.f;
25
26 ncnn::Mat aspect_ratios(2);
27 aspect_ratios[0] = 2.f;
28 aspect_ratios[1] = 3.f;
29
30 ncnn::ParamDict pd;
31 pd.set(0, min_sizes);
32 pd.set(1, max_sizes);
33 pd.set(2, aspect_ratios);
34 pd.set(3, 0.1f); // variances[0]
35 pd.set(4, 0.1f); // variances[1]
36 pd.set(5, 0.2f); // variances[2]
37 pd.set(6, 0.2f); // variances[3]
38 pd.set(7, 1); // flip
39 pd.set(8, 0); // clip
40 pd.set(9, -233); // image_width
41 pd.set(10, -233); // image_height
42 pd.set(11, -233.f); // step_width
43 pd.set(12, -233.f); // step_height
44 pd.set(13, 0.f); // offset
45 pd.set(14, 0.f); // step_mmdetection
46 pd.set(15, 0.f); // center_mmdetection
47
48 std::vector<ncnn::Mat> weights(0);
49
50 std::vector<ncnn::Mat> as(2);
51 as[0] = RandomMat(72, 72, 1);
52 as[1] = RandomMat(512, 512, 1);
53
54 int ret = test_layer<ncnn::PriorBox>("PriorBox", pd, weights, as, 1);
55 if (ret != 0)
56 {
57 fprintf(stderr, "test_priorbox_caffe failed\n");
58 }
59
60 return ret;
61 }
62
test_priorbox_mxnet()63 static int test_priorbox_mxnet()
64 {
65 ncnn::Mat min_sizes(2);
66 min_sizes[0] = 0.15f;
67 min_sizes[1] = 0.2121f;
68
69 ncnn::Mat max_sizes(0);
70
71 ncnn::Mat aspect_ratios(5);
72 aspect_ratios[0] = 1.f;
73 aspect_ratios[1] = 2.f;
74 aspect_ratios[2] = 0.5f;
75 aspect_ratios[3] = 3.f;
76 aspect_ratios[4] = 0.333333;
77
78 ncnn::ParamDict pd;
79 pd.set(0, min_sizes);
80 pd.set(1, max_sizes);
81 pd.set(2, aspect_ratios);
82 pd.set(3, 0.1f); // variances[0]
83 pd.set(4, 0.1f); // variances[1]
84 pd.set(5, 0.2f); // variances[2]
85 pd.set(6, 0.2f); // variances[3]
86 pd.set(7, 0); // flip
87 pd.set(8, 0); // clip
88 pd.set(9, -233); // image_width
89 pd.set(10, -233); // image_height
90 pd.set(11, -233.f); // step_width
91 pd.set(12, -233.f); // step_height
92 pd.set(13, 0.5f); // offset
93 pd.set(14, 0.f); // step_mmdetection
94 pd.set(15, 0.f); // center_mmdetection
95
96 std::vector<ncnn::Mat> weights(0);
97
98 std::vector<ncnn::Mat> as(1);
99 as[0] = RandomMat(72, 72, 1);
100
101 int ret = test_layer<ncnn::PriorBox>("PriorBox", pd, weights, as, 1);
102 if (ret != 0)
103 {
104 fprintf(stderr, "test_priorbox_mxnet failed\n");
105 }
106
107 return ret;
108 }
109
main()110 int main()
111 {
112 SRAND(7767517);
113
114 return 0
115 || test_priorbox_caffe()
116 || test_priorbox_mxnet();
117 }
118