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_roialign.cpp 3.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/roialign.h"
  16. #include "testutil.h"
  17. static int test_roialign(int w, int h, int c,
  18. int pooled_width, int pooled_height, float spatial_scale,
  19. int sampling_ratio, bool aligned, int version)
  20. {
  21. std::vector<ncnn::Mat> a;
  22. a.push_back(RandomMat(w, h, c));
  23. ncnn::Mat b(4);
  24. b[0] = RandomFloat(0.001, w - 2.001); //roi_x1
  25. b[2] = RandomFloat(b[0] + 1.001, w - 1.001); //roi_x2
  26. b[1] = RandomFloat(0.001, h - 2.001); //roi_y1
  27. b[3] = RandomFloat(b[2] + 1.001, h - 1.001); //roi_y2
  28. a.push_back(b);
  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. std::vector<ncnn::Mat> weights(0);
  37. ncnn::Option opt;
  38. opt.num_threads = 1;
  39. opt.use_vulkan_compute = true;
  40. opt.use_int8_inference = false;
  41. int ret = test_layer<ncnn::ROIAlign>("ROIAlign", pd, weights, opt, a);
  42. if (ret != 0)
  43. {
  44. 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);
  45. }
  46. return ret;
  47. }
  48. static int test_roialign_0()
  49. {
  50. int ret = 0;
  51. for (int sampling_ratio = 0; sampling_ratio <= 4 && ret == 0; ++sampling_ratio)
  52. {
  53. for (int aligned_i = 0; aligned_i < 2 && ret == 0; ++aligned_i)
  54. {
  55. for (int version = 0; version <= 1; ++version)
  56. {
  57. bool aligned = aligned_i;
  58. int lret = 0
  59. || test_roialign(112, 112, 16, 56, 56, 0.50000, sampling_ratio, aligned, version)
  60. || test_roialign(56, 56, 32, 28, 28, 0.25000, sampling_ratio, aligned, version)
  61. || test_roialign(28, 28, 64, 14, 14, 0.12500, sampling_ratio, aligned, version)
  62. || test_roialign(14, 14, 128, 27, 17, 0.06250, sampling_ratio, aligned, version)
  63. || test_roialign(7, 7, 256, 3, 3, 0.03125, sampling_ratio, aligned, version);
  64. ret |= lret;
  65. }
  66. }
  67. }
  68. if (ret != 0)
  69. return -1;
  70. return 0;
  71. }
  72. int main()
  73. {
  74. SRAND(7767517);
  75. return 0
  76. || test_roialign_0();
  77. }