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_crop_2.cpp 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_crop(const ncnn::Mat& a, int woffset, int hoffset, int doffset, int coffset, const ncnn::Mat& ref)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, woffset);
  8. pd.set(1, hoffset);
  9. pd.set(13, doffset);
  10. pd.set(2, coffset);
  11. pd.set(3, 0); // outw
  12. pd.set(4, 0); // outh
  13. pd.set(14, 0); // outd
  14. pd.set(5, 0); // outc
  15. pd.set(6, 0); // woffset2
  16. pd.set(7, 0); // hoffset2
  17. pd.set(15, 0); // doffset2
  18. pd.set(8, 0); // coffset2
  19. std::vector<ncnn::Mat> weights(0);
  20. std::vector<ncnn::Mat> ab(2);
  21. ab[0] = a;
  22. ab[1] = ref;
  23. int ret = test_layer("Crop", pd, weights, ab);
  24. if (ret != 0)
  25. {
  26. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d) woffset=%d hoffset=%d doffset=%d coffset=%d ref.dims=%d ref=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c, woffset, hoffset, doffset, coffset, ref.dims, ref.w, ref.h, ref.d, ref.c);
  27. }
  28. return ret;
  29. }
  30. static int test_crop_2(const ncnn::Mat& a)
  31. {
  32. return 0
  33. || test_crop(a, 0, 0, 0, 0, a)
  34. || test_crop(a, 0, 0, 0, 0, ncnn::Mat(27))
  35. || test_crop(a, 11, 0, 0, 0, ncnn::Mat(7))
  36. || test_crop(a, 12, 0, 0, 0, ncnn::Mat(12))
  37. || test_crop(a, 16, 0, 0, 0, ncnn::Mat(16));
  38. }
  39. static int test_crop_5(const ncnn::Mat& a)
  40. {
  41. return 0
  42. || test_crop(a, 0, 0, 0, 0, a)
  43. || test_crop(a, 0, 12, 0, 0, ncnn::Mat(8, 7))
  44. || test_crop(a, 5, 0, 0, 0, ncnn::Mat(7, 27))
  45. || test_crop(a, 5, 11, 0, 0, ncnn::Mat(5, 12))
  46. || test_crop(a, 6, 12, 0, 0, ncnn::Mat(4, 16))
  47. || test_crop(a, 4, 8, 0, 0, ncnn::Mat(6, 7));
  48. }
  49. static int test_crop_8(const ncnn::Mat& a)
  50. {
  51. return 0
  52. || test_crop(a, 0, 0, 0, 0, a)
  53. || test_crop(a, 0, 5, 0, 0, ncnn::Mat(6, 6))
  54. || test_crop(a, 6, 0, 0, 0, ncnn::Mat(8, 8))
  55. || test_crop(a, 5, 2, 0, 0, ncnn::Mat(6, 3))
  56. || test_crop(a, 6, 3, 0, 0, ncnn::Mat(8, 4))
  57. || test_crop(a, 4, 4, 0, 0, ncnn::Mat(7, 5))
  58. || test_crop(a, 5, 3, 0, 11, ncnn::Mat(7, 3, 7))
  59. || test_crop(a, 6, 4, 0, 12, ncnn::Mat(6, 4, 12))
  60. || test_crop(a, 4, 2, 0, 8, ncnn::Mat(5, 5, 16));
  61. }
  62. static int test_crop_11(const ncnn::Mat& a)
  63. {
  64. return 0
  65. || test_crop(a, 0, 0, 0, 0, a)
  66. || test_crop(a, 0, 5, 0, 0, ncnn::Mat(6, 6, 6))
  67. || test_crop(a, 6, 0, 0, 0, ncnn::Mat(8, 8, 8))
  68. || test_crop(a, 5, 5, 5, 0, ncnn::Mat(6, 6, 6))
  69. || test_crop(a, 6, 6, 6, 0, ncnn::Mat(8, 8, 8))
  70. || test_crop(a, 4, 4, 4, 0, ncnn::Mat(5, 5, 5))
  71. || test_crop(a, 3, 3, 3, 11, ncnn::Mat(3, 3, 3, 7))
  72. || test_crop(a, 4, 4, 4, 12, ncnn::Mat(6, 6, 6, 12))
  73. || test_crop(a, 5, 5, 5, 8, ncnn::Mat(8, 8, 8, 16));
  74. }
  75. int main()
  76. {
  77. SRAND(776757);
  78. return 0
  79. || test_crop_2(RandomMat(112))
  80. || test_crop_2(RandomMat(126))
  81. || test_crop_2(RandomMat(127))
  82. || test_crop_5(RandomMat(20, 48))
  83. || test_crop_5(RandomMat(15, 36))
  84. || test_crop_5(RandomMat(16, 33))
  85. || test_crop_8(RandomMat(20, 20, 48))
  86. || test_crop_8(RandomMat(15, 15, 36))
  87. || test_crop_8(RandomMat(16, 16, 33))
  88. || test_crop_11(RandomMat(20, 20, 20, 48))
  89. || test_crop_11(RandomMat(15, 15, 15, 36))
  90. || test_crop_11(RandomMat(16, 16, 16, 33));
  91. }