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

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