1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
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
8
// https://opensource.org/licenses/BSD-3-Clause
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.
17
static int test_groupnorm(const ncnn::Mat& a, int group, float eps, int affine)
35
std::vector<ncnn::Mat> weights(2);
36
weights[0] = RandomMat(channels);
37
weights[1] = RandomMat(channels);
39
int ret = test_layer("GroupNorm", pd, weights, a);
42
fprintf(stderr, "test_groupnorm failed a.dims=%d a=(%d %d %d) group=%d eps=%f\n", a.dims, a.w, a.h, a.c, group, eps);
48
static int test_groupnorm_0()
51
|| test_groupnorm(RandomMat(3, 6, 4, 2), 1, 0.01f, 0)
52
|| test_groupnorm(RandomMat(2, 3, 3, 8), 2, 0.002f, 0)
53
|| test_groupnorm(RandomMat(3, 4, 5, 6), 3, 0.01f, 0)
54
|| test_groupnorm(RandomMat(4, 5, 6, 12), 4, 0.02f, 0)
55
|| test_groupnorm(RandomMat(5, 6, 7, 24), 2, 0.001f, 0)
56
|| test_groupnorm(RandomMat(2, 8, 9, 24), 3, 0.0001f, 0)
57
|| test_groupnorm(RandomMat(3, 6, 4, 2), 1, 0.01f, 1)
58
|| test_groupnorm(RandomMat(2, 3, 3, 8), 2, 0.002f, 1)
59
|| test_groupnorm(RandomMat(3, 4, 5, 6), 3, 0.01f, 1)
60
|| test_groupnorm(RandomMat(4, 5, 6, 12), 4, 0.02f, 1)
61
|| test_groupnorm(RandomMat(5, 6, 7, 24), 2, 0.001f, 1)
62
|| test_groupnorm(RandomMat(2, 8, 9, 24), 3, 0.0001f, 1);
65
static int test_groupnorm_1()
68
|| test_groupnorm(RandomMat(6, 4, 2), 1, 0.01f, 0)
69
|| test_groupnorm(RandomMat(3, 3, 8), 2, 0.002f, 0)
70
|| test_groupnorm(RandomMat(4, 5, 6), 3, 0.01f, 0)
71
|| test_groupnorm(RandomMat(5, 6, 12), 4, 0.02f, 0)
72
|| test_groupnorm(RandomMat(6, 7, 24), 2, 0.001f, 0)
73
|| test_groupnorm(RandomMat(8, 9, 24), 3, 0.0001f, 0)
74
|| test_groupnorm(RandomMat(6, 4, 2), 1, 0.01f, 1)
75
|| test_groupnorm(RandomMat(3, 3, 8), 2, 0.002f, 1)
76
|| test_groupnorm(RandomMat(4, 5, 6), 3, 0.01f, 1)
77
|| test_groupnorm(RandomMat(5, 6, 12), 4, 0.02f, 1)
78
|| test_groupnorm(RandomMat(6, 7, 24), 2, 0.001f, 1)
79
|| test_groupnorm(RandomMat(8, 9, 24), 3, 0.0001f, 1);
82
static int test_groupnorm_2()
85
|| test_groupnorm(RandomMat(24, 2), 1, 0.01f, 0)
86
|| test_groupnorm(RandomMat(23, 8), 2, 0.002f, 0)
87
|| test_groupnorm(RandomMat(25, 6), 3, 0.01f, 0)
88
|| test_groupnorm(RandomMat(26, 12), 4, 0.02f, 0)
89
|| test_groupnorm(RandomMat(27, 24), 2, 0.001f, 0)
90
|| test_groupnorm(RandomMat(29, 24), 3, 0.0001f, 0)
91
|| test_groupnorm(RandomMat(24, 2), 1, 0.01f, 1)
92
|| test_groupnorm(RandomMat(23, 8), 2, 0.002f, 1)
93
|| test_groupnorm(RandomMat(25, 6), 3, 0.01f, 1)
94
|| test_groupnorm(RandomMat(26, 12), 4, 0.02f, 1)
95
|| test_groupnorm(RandomMat(27, 24), 2, 0.001f, 1)
96
|| test_groupnorm(RandomMat(29, 24), 3, 0.0001f, 1);
99
static int test_groupnorm_3()
102
|| test_groupnorm(RandomMat(12), 1, 0.01f, 0)
103
|| test_groupnorm(RandomMat(18), 2, 0.002f, 0)
104
|| test_groupnorm(RandomMat(36), 3, 0.01f, 0)
105
|| test_groupnorm(RandomMat(212), 4, 0.02f, 0)
106
|| test_groupnorm(RandomMat(124), 2, 0.001f, 0)
107
|| test_groupnorm(RandomMat(324), 3, 0.0001f, 0)
108
|| test_groupnorm(RandomMat(12), 1, 0.01f, 1)
109
|| test_groupnorm(RandomMat(18), 2, 0.002f, 1)
110
|| test_groupnorm(RandomMat(36), 3, 0.01f, 1)
111
|| test_groupnorm(RandomMat(212), 4, 0.02f, 1)
112
|| test_groupnorm(RandomMat(124), 2, 0.001f, 1)
113
|| test_groupnorm(RandomMat(324), 3, 0.0001f, 1);
121
|| test_groupnorm_0()
122
|| test_groupnorm_1()
123
|| test_groupnorm_2()
124
|| test_groupnorm_3();