| 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.h" |
| 16 | #include "testutil.h" |
| 17 | |
| 18 | static int test_roialign(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale, int sampling_ratio, bool aligned, int version) |
| 19 | { |
| 20 | std::vector<ncnn::Mat> a; |
| 21 | a.push_back(RandomMat(w, h, c)); |
| 22 | ncnn::Mat b(4); |
| 23 | b[0] = RandomFloat(0.001, w - 2.001); //roi_x1 |
| 24 | b[2] = RandomFloat(b[0] + 1.001, w - 1.001); //roi_x2 |
| 25 | b[1] = RandomFloat(0.001, h - 2.001); //roi_y1 |
| 26 | b[3] = RandomFloat(b[2] + 1.001, h - 1.001); //roi_y2 |
| 27 | a.push_back(b); |
| 28 | |
| 29 | ncnn::ParamDict pd; |
| 30 | pd.set(0, pooled_width); // pooled_width |
| 31 | pd.set(1, pooled_height); // pooled_height |
| 32 | pd.set(2, spatial_scale); // spatial_scale |
| 33 | pd.set(3, sampling_ratio); // sampling_ratio |
| 34 | pd.set(4, aligned); // aligned |
| 35 | pd.set(5, version); // version |
| 36 | |
| 37 | std::vector<ncnn::Mat> weights(0); |
| 38 | |
| 39 | int ret = test_layer("ROIAlign", pd, weights, a); |
| 40 | if (ret != 0) |
| 41 | { |
| 42 | fprintf(stderr, "test_roialign failed base_w=%d base_h=%d base_c=%d pooled_width=%d pooled_height=%d spatial_scale=%4f.3\n", w, h, c, pooled_width, pooled_height, spatial_scale); |
| 43 | } |
| 44 | |
| 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | static int test_roialign_0() |
| 49 | { |
| 50 | return 0 |
| 51 | || test_roialign(56, 56, 1, 28, 28, 0.50000, 0, 0, 0) |
| 52 | || test_roialign(28, 28, 3, 14, 14, 0.25000, 1, 1, 1) |
| 53 | || test_roialign(14, 14, 4, 7, 7, 0.12500, 2, 0, 1) |
| 54 | || test_roialign(14, 14, 8, 7, 7, 0.06250, 3, 1, 0) |
| 55 | || test_roialign(7, 7, 12, 3, 3, 0.03125, 4, 0, 0) |
| 56 | || test_roialign(7, 7, 16, 3, 3, 0.03125, 4, 1, 1); |
| 57 | } |
| 58 | |
| 59 | int main() |
| 60 | { |
| 61 | SRAND(7767517); |
| 62 | |
| 63 | return 0 |
| 64 | || test_roialign_0(); |
| 65 | } |