Elffuss BraidHub

kikocis/ncnn public

d7a5f98c0f60 · 3.1 KiBRawPermalink
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 "testutil.h"
16
17static int test_priorbox_caffe()
18{
19 ncnn::Mat min_sizes(1);
20 min_sizes[0] = 105.f;
21
22 ncnn::Mat max_sizes(1);
23 max_sizes[0] = 150.f;
24
25 ncnn::Mat aspect_ratios(2);
26 aspect_ratios[0] = 2.f;
27 aspect_ratios[1] = 3.f;
28
29 ncnn::ParamDict pd;
30 pd.set(0, min_sizes);
31 pd.set(1, max_sizes);
32 pd.set(2, aspect_ratios);
33 pd.set(3, 0.1f); // variances[0]
34 pd.set(4, 0.1f); // variances[1]
35 pd.set(5, 0.2f); // variances[2]
36 pd.set(6, 0.2f); // variances[3]
37 pd.set(7, 1); // flip
38 pd.set(8, 0); // clip
39 pd.set(9, -233); // image_width
40 pd.set(10, -233); // image_height
41 pd.set(11, -233.f); // step_width
42 pd.set(12, -233.f); // step_height
43 pd.set(13, 0.f); // offset
44 pd.set(14, 0.f); // step_mmdetection
45 pd.set(15, 0.f); // center_mmdetection
46
47 std::vector<ncnn::Mat> weights(0);
48
49 std::vector<ncnn::Mat> as(2);
50 as[0] = RandomMat(72, 72, 1);
51 as[1] = RandomMat(512, 512, 1);
52
53 int ret = test_layer("PriorBox", pd, weights, as, 1);
54 if (ret != 0)
55 {
56 fprintf(stderr, "test_priorbox_caffe failed\n");
57 }
58
59 return ret;
60}
61
62static int test_priorbox_mxnet()
63{
64 ncnn::Mat min_sizes(2);
65 min_sizes[0] = 0.15f;
66 min_sizes[1] = 0.2121f;
67
68 ncnn::Mat max_sizes(0);
69
70 ncnn::Mat aspect_ratios(5);
71 aspect_ratios[0] = 1.f;
72 aspect_ratios[1] = 2.f;
73 aspect_ratios[2] = 0.5f;
74 aspect_ratios[3] = 3.f;
75 aspect_ratios[4] = 0.333333;
76
77 ncnn::ParamDict pd;
78 pd.set(0, min_sizes);
79 pd.set(1, max_sizes);
80 pd.set(2, aspect_ratios);
81 pd.set(3, 0.1f); // variances[0]
82 pd.set(4, 0.1f); // variances[1]
83 pd.set(5, 0.2f); // variances[2]
84 pd.set(6, 0.2f); // variances[3]
85 pd.set(7, 0); // flip
86 pd.set(8, 0); // clip
87 pd.set(9, -233); // image_width
88 pd.set(10, -233); // image_height
89 pd.set(11, -233.f); // step_width
90 pd.set(12, -233.f); // step_height
91 pd.set(13, 0.5f); // offset
92 pd.set(14, 0.f); // step_mmdetection
93 pd.set(15, 0.f); // center_mmdetection
94
95 std::vector<ncnn::Mat> weights(0);
96
97 std::vector<ncnn::Mat> as(1);
98 as[0] = RandomMat(72, 72, 1);
99
100 int ret = test_layer("PriorBox", pd, weights, as, 1);
101 if (ret != 0)
102 {
103 fprintf(stderr, "test_priorbox_mxnet failed\n");
104 }
105
106 return ret;
107}
108
109int main()
110{
111 SRAND(7767517);
112
113 return 0
114 || test_priorbox_caffe()
115 || test_priorbox_mxnet();
116}