You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_roipooling.cpp 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "layer.h"
  15. #include "layer/roipooling.h"
  16. #include "testutil.h"
  17. static int test_roipooling(int w, int h, int c, int pooled_width, int pooled_height, float spatial_scale)
  18. {
  19. std::vector<ncnn::Mat> a;
  20. a.push_back(RandomMat(w, h, c));
  21. ncnn::Mat b(4);
  22. b[0] = RandomFloat(0.001, w - 2.001); //roi_x1
  23. b[2] = RandomFloat(b[0] + 1.001, w - 1.001); //roi_x2
  24. b[1] = RandomFloat(0.001, h - 2.001); //roi_y1
  25. b[3] = RandomFloat(b[2] + 1.001, h - 1.001); //roi_y2
  26. a.push_back(b);
  27. ncnn::ParamDict pd;
  28. pd.set(0, pooled_width); // pooled_width
  29. pd.set(1, pooled_height); // pooled_height
  30. pd.set(2, spatial_scale); // spatial_scale
  31. std::vector<ncnn::Mat> weights(0);
  32. ncnn::Option opt;
  33. opt.num_threads = 1;
  34. opt.use_vulkan_compute = true;
  35. opt.use_int8_inference = false;
  36. int ret = test_layer<ncnn::ROIPooling>("ROIPooling", pd, weights, opt, a);
  37. if (ret != 0)
  38. {
  39. 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);
  40. }
  41. return ret;
  42. }
  43. static int test_roipooling_0()
  44. {
  45. int ret = 0
  46. || test_roipooling(112, 112, 16, 56, 56, 0.50000)
  47. || test_roipooling(56, 56, 32, 28, 28, 0.25000)
  48. || test_roipooling(28, 28, 64, 14, 14, 0.12500)
  49. || test_roipooling(14, 14, 128, 27, 17, 0.06250)
  50. || test_roipooling(7, 7, 256, 3, 3, 0.03125);
  51. if (ret != 0)
  52. return -1;
  53. return 0;
  54. }
  55. int main()
  56. {
  57. SRAND(7767517);
  58. return 0
  59. || test_roipooling_0();
  60. }