Browse Source

ncnn: test: Add support for ROIPooling test (#1596)

* ncnn: test: Add support for ROIPooling test

* test: Fix bottom_blob of ROIPooling test
tags/20200413
nihui GitHub 6 years ago
parent
commit
d045918080
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 0 deletions
  1. +1
    -0
      tests/CMakeLists.txt
  2. +80
    -0
      tests/test_roipooling.cpp

+ 1
- 0
tests/CMakeLists.txt View File

@@ -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)


+ 80
- 0
tests/test_roipooling.cpp View File

@@ -0,0 +1,80 @@
// 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 test_roipooling(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale)
{
std::vector<ncnn::Mat> a;
a.push_back(RandomMat(w, h, c));
ncnn::Mat b(4);
b[0] = RandomFloat(0.001 , w-2.001); //roi_x1
b[2] = RandomFloat(b[0]+1.001, w-1.001); //roi_x2
b[1] = RandomFloat(0.001 , h-2.001); //roi_y1
b[3] = RandomFloat(b[2]+1.001, h-1.001); //roi_y2
a.push_back(b);

ncnn::ParamDict pd;
pd.set(0, pooled_width); // pooled_width
pd.set(1, pooled_height); // pooled_height
pd.set(2, spatial_scale); // spatial_scale

std::vector<ncnn::Mat> 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<ncnn::ROIPooling>("ROIPooling", pd, weights, opt, a);
if (ret != 0)
{
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;
}

static int test_roipooling_0()
{
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;

return 0;
}

int main()
{
SRAND(7767517);

return 0
|| test_roipooling_0()
;
}

Loading…
Cancel
Save