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 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "layer.h"
  4. #include "testutil.h"
  5. 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)
  6. {
  7. std::vector<ncnn::Mat> a;
  8. a.push_back(RandomMat(w, h, c));
  9. ncnn::Mat b(4);
  10. b[0] = RandomFloat(0.001, w - 2.001); //roi_x1
  11. b[2] = RandomFloat(b[0] + 1.001, w - 1.001); //roi_x2
  12. b[1] = RandomFloat(0.001, h - 2.001); //roi_y1
  13. b[3] = RandomFloat(b[2] + 1.001, h - 1.001); //roi_y2
  14. a.push_back(b);
  15. ncnn::ParamDict pd;
  16. pd.set(0, pooled_width); // pooled_width
  17. pd.set(1, pooled_height); // pooled_height
  18. pd.set(2, spatial_scale); // spatial_scale
  19. pd.set(3, sampling_ratio); // sampling_ratio
  20. pd.set(4, aligned); // aligned
  21. pd.set(5, version); // version
  22. std::vector<ncnn::Mat> weights(0);
  23. int ret = test_layer("ROIAlign", pd, weights, a);
  24. if (ret != 0)
  25. {
  26. 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);
  27. }
  28. return ret;
  29. }
  30. static int test_roialign_0()
  31. {
  32. return 0
  33. || test_roialign(56, 56, 1, 28, 28, 0.50000, 0, 0, 0)
  34. || test_roialign(28, 28, 3, 14, 14, 0.25000, 1, 1, 1)
  35. || test_roialign(14, 14, 4, 7, 7, 0.12500, 2, 0, 1)
  36. || test_roialign(14, 14, 8, 7, 7, 0.06250, 3, 1, 0)
  37. || test_roialign(7, 7, 12, 3, 3, 0.03125, 4, 0, 0)
  38. || test_roialign(7, 7, 16, 3, 3, 0.03125, 4, 1, 1);
  39. }
  40. int main()
  41. {
  42. SRAND(7767517);
  43. return 0
  44. || test_roialign_0();
  45. }