From 7e9d5d0439bcc12bf1cf81c0c24cff0c5c3a63c7 Mon Sep 17 00:00:00 2001 From: monkeyking Date: Sat, 7 Mar 2020 18:59:33 +0800 Subject: [PATCH 1/2] ncnn: test: Add support for ROIPooling test --- tests/CMakeLists.txt | 1 + tests/test_roipooling.cpp | 129 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 tests/test_roipooling.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 42a9438bc..196594c9c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,7 @@ ncnn_add_layer_test(Padding) ncnn_add_layer_test(Permute) ncnn_add_layer_test(PixelShuffle) ncnn_add_layer_test(Pooling) +ncnn_add_layer_test(ROIPooling) ncnn_add_layer_test(ReLU) ncnn_add_layer_test(ELU) ncnn_add_layer_test(Reorg) diff --git a/tests/test_roipooling.cpp b/tests/test_roipooling.cpp new file mode 100644 index 000000000..0839a2260 --- /dev/null +++ b/tests/test_roipooling.cpp @@ -0,0 +1,129 @@ +// Tencent is pleased to support the open source community by making ncnn available. +// +// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#include "testutil.h" + +#include "layer.h" +#include "layer/roipooling.h" + +static int RandomInt(float a = -2.f, float b = 2.f) +{ + return RandomFloat( a, b ) / 1; +} + +static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale) +{ + std::vector a; + int num_rois = RandomInt(2, 1000); + for(int i=0; i weights(0); + + ncnn::Option opt; + opt.num_threads = 1; + opt.use_vulkan_compute = true; + opt.use_fp16_packed = false; + opt.use_fp16_storage = false; + opt.use_fp16_arithmetic = false; + opt.use_int8_storage = false; + opt.use_int8_arithmetic = false; + + int ret = test_layer("ROIPooling", pd, weights, opt, a); + if (ret != 0) + { + fprintf(stderr, "test_roipooling failed base_w=%d base_h=%d base_c=%d num_rois=%d pooled_width=%d pooled_height=%d spatial_scale=%4f.3\n", w, h, c, num_rois, pooled_width, pooled_height, spatial_scale); + } + + return ret; +} + +static int test_roipooling_0() +{ + for (int i=0; i<11; i++) + { + int ret = 0 + || test_roipooling(2, 2, 81, 4, 4, 0.0156) + || test_roipooling(4, 4, 27, 7, 7, 0.0312) + || test_roipooling(9, 9, 9, 14, 14, 0.0625) + || test_roipooling(15, 21, 81, 8, 6, 0.0123) + || test_roipooling(17, 23, 27, 27, 17, 0.0370) + || test_roipooling(19, 25, 9, 80, 53, 0.1111) + ; + + if (ret != 0) + return -1; + } + + return 0; +} + +static int test_roipooling_1() +{ + for (int i=0; i<11; i++) + { + int ret = 0 + || test_roipooling(2, 2, 27, 4, 4, 0.0156) + || test_roipooling(4, 4, 9, 7, 7, 0.0312) + || test_roipooling(9, 9, 3, 14, 14, 0.0625) + || test_roipooling(4, 21, 27, 12, 9, 0.0123) + || test_roipooling(17, 23, 9, 38, 29, 0.0370) + || test_roipooling(105, 65, 3, 113, 85, 0.1111) + ; + + if (ret != 0) + return -1; + } + + return 0; +} + +static int test_roipooling_2() +{ + for (int i=0; i<11; i++) + { + int ret = 0 + || test_roipooling(4, 7, 1, 4, 5, 0.0156) + || test_roipooling(6, 11, 2, 6, 7, 0.0312) + || test_roipooling(9, 17, 3, 14, 17, 0.0625) + || test_roipooling(13, 19, 4, 15, 18, 0.1250) + || test_roipooling(15, 21, 7, 18, 21, 0.0123) + || test_roipooling(17, 23, 8, 21, 25, 0.0370) + || test_roipooling(19, 25, 15, 21, 26, 0.1111) + || test_roipooling(23, 31, 16, 25, 34, 0.3333) + ; + + if (ret != 0) + return -1; + } + + return 0; +} + +int main() +{ + SRAND(7767517); + + return 0 + || test_roipooling_0() + || test_roipooling_1() + || test_roipooling_2() + ; +} From 8763badbe06cebb02f45b1bc99cc55dd489490ea Mon Sep 17 00:00:00 2001 From: Monkeyking Date: Sat, 7 Mar 2020 23:15:54 +0800 Subject: [PATCH 2/2] test: Fix bottom_blob of ROIPooling test --- tests/test_roipooling.cpp | 83 ++++++++------------------------------- 1 file changed, 17 insertions(+), 66 deletions(-) diff --git a/tests/test_roipooling.cpp b/tests/test_roipooling.cpp index 0839a2260..85264daa3 100644 --- a/tests/test_roipooling.cpp +++ b/tests/test_roipooling.cpp @@ -17,18 +17,17 @@ #include "layer.h" #include "layer/roipooling.h" -static int RandomInt(float a = -2.f, float b = 2.f) -{ - return RandomFloat( a, b ) / 1; -} static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale) { std::vector a; - int num_rois = RandomInt(2, 1000); - for(int i=0; i("ROIPooling", pd, weights, opt, a); if (ret != 0) { - fprintf(stderr, "test_roipooling failed base_w=%d base_h=%d base_c=%d num_rois=%d pooled_width=%d pooled_height=%d spatial_scale=%4f.3\n", w, h, c, num_rois, pooled_width, pooled_height, spatial_scale); + fprintf(stderr, "test_roipooling 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); } return ret; @@ -57,62 +56,16 @@ static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_hei static int test_roipooling_0() { - for (int i=0; i<11; i++) - { - int ret = 0 - || test_roipooling(2, 2, 81, 4, 4, 0.0156) - || test_roipooling(4, 4, 27, 7, 7, 0.0312) - || test_roipooling(9, 9, 9, 14, 14, 0.0625) - || test_roipooling(15, 21, 81, 8, 6, 0.0123) - || test_roipooling(17, 23, 27, 27, 17, 0.0370) - || test_roipooling(19, 25, 9, 80, 53, 0.1111) - ; - - if (ret != 0) - return -1; - } - - return 0; -} - -static int test_roipooling_1() -{ - for (int i=0; i<11; i++) - { - int ret = 0 - || test_roipooling(2, 2, 27, 4, 4, 0.0156) - || test_roipooling(4, 4, 9, 7, 7, 0.0312) - || test_roipooling(9, 9, 3, 14, 14, 0.0625) - || test_roipooling(4, 21, 27, 12, 9, 0.0123) - || test_roipooling(17, 23, 9, 38, 29, 0.0370) - || test_roipooling(105, 65, 3, 113, 85, 0.1111) - ; - - if (ret != 0) - return -1; - } - - return 0; -} - -static int test_roipooling_2() -{ - for (int i=0; i<11; i++) - { - int ret = 0 - || test_roipooling(4, 7, 1, 4, 5, 0.0156) - || test_roipooling(6, 11, 2, 6, 7, 0.0312) - || test_roipooling(9, 17, 3, 14, 17, 0.0625) - || test_roipooling(13, 19, 4, 15, 18, 0.1250) - || test_roipooling(15, 21, 7, 18, 21, 0.0123) - || test_roipooling(17, 23, 8, 21, 25, 0.0370) - || test_roipooling(19, 25, 15, 21, 26, 0.1111) - || test_roipooling(23, 31, 16, 25, 34, 0.3333) - ; + int ret = 0 + || test_roipooling(112, 112, 16 , 56, 56, 0.50000) + || test_roipooling(56 , 56 , 32 , 28, 28, 0.25000) + || test_roipooling(28 , 28 , 64 , 14, 14, 0.12500) + || test_roipooling(14 , 14 , 128, 27, 17, 0.06250) + || test_roipooling(7 , 7 , 256, 3, 3, 0.03125) + ; - if (ret != 0) - return -1; - } + if (ret != 0) + return -1; return 0; } @@ -123,7 +76,5 @@ int main() return 0 || test_roipooling_0() - || test_roipooling_1() - || test_roipooling_2() ; }