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.cpp 14 kB

6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 "testutil.h"
  15. static int test_crop(const ncnn::Mat& a, int woffset, int hoffset, int doffset, int coffset, int outw, int outh, int outd, int outc, int woffset2, int hoffset2, int doffset2, int coffset2)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, woffset);
  19. pd.set(1, hoffset);
  20. pd.set(13, doffset);
  21. pd.set(2, coffset);
  22. pd.set(3, outw);
  23. pd.set(4, outh);
  24. pd.set(14, outd);
  25. pd.set(5, outc);
  26. pd.set(6, woffset2);
  27. pd.set(7, hoffset2);
  28. pd.set(15, doffset2);
  29. pd.set(8, coffset2);
  30. std::vector<ncnn::Mat> weights(0);
  31. int ret = test_layer("Crop", pd, weights, a);
  32. if (ret != 0)
  33. {
  34. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d) woffset=%d hoffset=%d doffset=%d coffset=%d outw=%d outh=%d outd=%d outc=%d woffset2=%d hoffset2=%d doffset2=%d coffset2=%d\n", a.dims, a.w, a.h, a.d, a.c, woffset, hoffset, doffset, coffset, outw, outh, outd, outc, woffset2, hoffset2, doffset2, coffset2);
  35. }
  36. return ret;
  37. }
  38. static int test_crop_0(const ncnn::Mat& a)
  39. {
  40. return 0
  41. || test_crop(a, 0, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
  42. || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
  43. || test_crop(a, 11, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0)
  44. || test_crop(a, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0)
  45. || test_crop(a, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0)
  46. || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 12, 0, 0, 0)
  47. || test_crop(a, 12, 0, 0, 0, -233, 0, 0, 0, 16, 0, 0, 0)
  48. || test_crop(a, 16, 0, 0, 0, -233, 0, 0, 0, 7, 0, 0, 0);
  49. }
  50. static int test_crop_3(const ncnn::Mat& a)
  51. {
  52. return 0
  53. || test_crop(a, 0, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  54. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  55. || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  56. || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  57. || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  58. || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  59. || test_crop(a, 5, 0, 0, 0, 5, -233, 0, 0, 0, 0, 0, 0)
  60. || test_crop(a, 6, 0, 0, 0, 6, -233, 0, 0, 0, 0, 0, 0)
  61. || test_crop(a, 4, 0, 0, 0, 4, -233, 0, 0, 0, 0, 0, 0)
  62. || test_crop(a, 0, 11, 0, 0, -233, 12, 0, 0, 0, 0, 0, 0)
  63. || test_crop(a, 0, 12, 0, 0, -233, 16, 0, 0, 0, 0, 0, 0)
  64. || test_crop(a, 0, 8, 0, 0, -233, 7, 0, 0, 0, 0, 0, 0)
  65. || test_crop(a, 5, 11, 0, 0, 4, 16, 0, 0, 0, 0, 0, 0)
  66. || test_crop(a, 6, 12, 0, 0, 5, 7, 0, 0, 0, 0, 0, 0)
  67. || test_crop(a, 4, 8, 0, 0, 6, 12, 0, 0, 0, 0, 0, 0)
  68. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 5, 0, 0, 0)
  69. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, 0, 6, 0, 0, 0)
  70. || test_crop(a, 4, 0, 0, 0, -233, -233, 0, 0, 4, 0, 0, 0)
  71. || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 12, 0, 0)
  72. || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 16, 0, 0)
  73. || test_crop(a, 0, 8, 0, 0, -233, -233, 0, 0, 0, 7, 0, 0)
  74. || test_crop(a, 5, 11, 0, 0, -233, -233, 0, 0, 4, 16, 0, 0)
  75. || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 5, 7, 0, 0)
  76. || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 6, 12, 0, 0);
  77. }
  78. static int test_crop_6(const ncnn::Mat& a)
  79. {
  80. return 0
  81. || test_crop(a, 0, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  82. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  83. || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  84. || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  85. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  86. || test_crop(a, 5, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  87. || test_crop(a, 4, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  88. || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  89. || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 0)
  90. || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 0)
  91. || test_crop(a, 6, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  92. || test_crop(a, 5, 0, 0, 0, 6, -233, 0, -233, 0, 0, 0, 0)
  93. || test_crop(a, 6, 0, 0, 0, 4, -233, 0, -233, 0, 0, 0, 0)
  94. || test_crop(a, 4, 0, 0, 0, 5, -233, 0, -233, 0, 0, 0, 0)
  95. || test_crop(a, 0, 5, 0, 0, -233, 4, 0, -233, 0, 0, 0, 0)
  96. || test_crop(a, 0, 6, 0, 0, -233, 5, 0, -233, 0, 0, 0, 0)
  97. || test_crop(a, 0, 4, 0, 0, -233, 6, 0, -233, 0, 0, 0, 0)
  98. || test_crop(a, 0, 0, 0, 11, -233, -233, 0, 7, 0, 0, 0, 0)
  99. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, 12, 0, 0, 0, 0)
  100. || test_crop(a, 0, 0, 0, 8, -233, -233, 0, 16, 0, 0, 0, 0)
  101. || test_crop(a, 5, 5, 0, 0, 4, 4, 0, -233, 0, 0, 0, 0)
  102. || test_crop(a, 6, 6, 0, 0, 6, 6, 0, -233, 0, 0, 0, 0)
  103. || test_crop(a, 4, 4, 0, 0, 5, 5, 0, -233, 0, 0, 0, 0)
  104. || test_crop(a, 0, 5, 0, 11, -233, 6, 0, 12, 0, 0, 0, 0)
  105. || test_crop(a, 0, 6, 0, 12, -233, 4, 0, 16, 0, 0, 0, 0)
  106. || test_crop(a, 0, 4, 0, 8, -233, 5, 0, 7, 0, 0, 0, 0)
  107. || test_crop(a, 5, 0, 0, 11, 4, -233, 0, 16, 0, 0, 0, 0)
  108. || test_crop(a, 6, 0, 0, 12, 5, -233, 0, 7, 0, 0, 0, 0)
  109. || test_crop(a, 4, 0, 0, 8, 4, -233, 0, 12, 0, 0, 0, 0)
  110. || test_crop(a, 5, 3, 0, 11, 6, 5, 0, 12, 0, 0, 0, 0)
  111. || test_crop(a, 6, 4, 0, 12, 4, 4, 0, 16, 0, 0, 0, 0)
  112. || test_crop(a, 4, 5, 0, 8, 5, 3, 0, 7, 0, 0, 0, 0)
  113. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, -233, 4, 0, 0, 0)
  114. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 5, 0, 0, 0)
  115. || test_crop(a, 4, 0, 0, 0, -233, -233, 0, -233, 6, 0, 0, 0)
  116. || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 5, 0, 0)
  117. || test_crop(a, 0, 6, 0, 0, -233, -233, 0, -233, 0, 6, 0, 0)
  118. || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 4, 0, 0)
  119. || test_crop(a, 0, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 12)
  120. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 16)
  121. || test_crop(a, 0, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 7)
  122. || test_crop(a, 5, 4, 0, 0, -233, -233, 0, -233, 4, 2, 0, 0)
  123. || test_crop(a, 6, 3, 0, 0, -233, -233, 0, -233, 5, 3, 0, 0)
  124. || test_crop(a, 4, 2, 0, 0, -233, -233, 0, -233, 6, 4, 0, 0)
  125. || test_crop(a, 0, 5, 0, 11, -233, -233, 0, -233, 0, 5, 0, 7)
  126. || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 6, 0, 12)
  127. || test_crop(a, 0, 4, 0, 8, -233, -233, 0, -233, 0, 4, 0, 16)
  128. || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 6, 0, 0, 12)
  129. || test_crop(a, 6, 0, 0, 12, -233, -233, 0, -233, 4, 0, 0, 16)
  130. || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 5, 0, 0, 7)
  131. || test_crop(a, 5, 2, 0, 11, -233, -233, 0, -233, 4, 3, 0, 16)
  132. || test_crop(a, 6, 3, 0, 12, -233, -233, 0, -233, 5, 4, 0, 7)
  133. || test_crop(a, 4, 4, 0, 8, -233, -233, 0, -233, 6, 2, 0, 12);
  134. }
  135. static int test_crop_9(const ncnn::Mat& a)
  136. {
  137. return 0
  138. || test_crop(a, 0, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  139. || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  140. || test_crop(a, 0, 5, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  141. || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  142. || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  143. || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  144. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  145. || test_crop(a, 5, 5, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  146. || test_crop(a, 4, 4, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  147. || test_crop(a, 0, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  148. || test_crop(a, 5, 0, 5, 11, -233, -233, -233, -233, 0, 0, 0, 0)
  149. || test_crop(a, 4, 0, 4, 8, -233, -233, -233, -233, 0, 0, 0, 0)
  150. || test_crop(a, 6, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  151. || test_crop(a, 5, 0, 0, 0, 6, -233, -233, -233, 0, 0, 0, 0)
  152. || test_crop(a, 6, 0, 0, 0, 5, -233, -233, -233, 0, 0, 0, 0)
  153. || test_crop(a, 4, 0, 0, 0, 4, -233, -233, -233, 0, 0, 0, 0)
  154. || test_crop(a, 0, 5, 0, 0, -233, 4, -233, -233, 0, 0, 0, 0)
  155. || test_crop(a, 0, 6, 0, 0, -233, 5, -233, -233, 0, 0, 0, 0)
  156. || test_crop(a, 0, 4, 0, 0, -233, 6, -233, -233, 0, 0, 0, 0)
  157. || test_crop(a, 0, 0, 5, 0, -233, -233, 6, -233, 0, 0, 0, 0)
  158. || test_crop(a, 0, 0, 6, 0, -233, -233, 4, -233, 0, 0, 0, 0)
  159. || test_crop(a, 0, 0, 4, 0, -233, -233, 5, -233, 0, 0, 0, 0)
  160. || test_crop(a, 0, 0, 0, 11, -233, -233, -233, 7, 0, 0, 0, 0)
  161. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, 12, 0, 0, 0, 0)
  162. || test_crop(a, 0, 0, 0, 8, -233, -233, -233, 16, 0, 0, 0, 0)
  163. || test_crop(a, 5, 2, 0, 0, 6, 5, -233, -233, 0, 0, 0, 0)
  164. || test_crop(a, 6, 3, 0, 0, 5, 6, -233, -233, 0, 0, 0, 0)
  165. || test_crop(a, 4, 4, 0, 0, 4, 4, -233, -233, 0, 0, 0, 0)
  166. || test_crop(a, 5, 0, 3, 0, 2, -233, 5, -233, 0, 0, 0, 0)
  167. || test_crop(a, 6, 0, 2, 0, 3, -233, 3, -233, 0, 0, 0, 0)
  168. || test_crop(a, 4, 0, 4, 0, 4, -233, 4, -233, 0, 0, 0, 0)
  169. || test_crop(a, 0, 5, 0, 11, -233, 1, -233, 12, 0, 0, 0, 0)
  170. || test_crop(a, 0, 6, 0, 12, -233, 2, -233, 16, 0, 0, 0, 0)
  171. || test_crop(a, 0, 4, 0, 8, -233, 3, -233, 7, 0, 0, 0, 0)
  172. || test_crop(a, 0, 0, 4, 11, -233, -233, 3, 16, 0, 0, 0, 0)
  173. || test_crop(a, 0, 0, 5, 12, -233, -233, 2, 7, 0, 0, 0, 0)
  174. || test_crop(a, 0, 0, 6, 8, -233, -233, 1, 16, 0, 0, 0, 0)
  175. || test_crop(a, 5, 0, 5, 11, 1, -233, 2, 16, 0, 0, 0, 0)
  176. || test_crop(a, 6, 0, 6, 12, 2, -233, 3, 7, 0, 0, 0, 0)
  177. || test_crop(a, 4, 0, 4, 8, 3, -233, 1, 16, 0, 0, 0, 0)
  178. || test_crop(a, 4, 6, 3, 11, 2, 3, 4, 12, 0, 0, 0, 0)
  179. || test_crop(a, 5, 5, 4, 12, 3, 4, 5, 16, 0, 0, 0, 0)
  180. || test_crop(a, 6, 4, 2, 8, 4, 5, 6, 7, 0, 0, 0, 0)
  181. || test_crop(a, 5, 0, 0, 0, -233, -233, -233, -233, 2, 0, 0, 0)
  182. || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 3, 0, 0, 0)
  183. || test_crop(a, 4, 0, 0, 0, -233, -233, -233, -233, 4, 0, 0, 0)
  184. || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 4, 0, 0)
  185. || test_crop(a, 0, 3, 0, 0, -233, -233, -233, -233, 0, 3, 0, 0)
  186. || test_crop(a, 0, 2, 0, 0, -233, -233, -233, -233, 0, 2, 0, 0)
  187. || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 4, 0)
  188. || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 2, 0)
  189. || test_crop(a, 0, 0, 6, 0, -233, -233, -233, -233, 0, 0, 3, 0)
  190. || test_crop(a, 0, 0, 0, 11, -233, -233, -233, -233, 0, 0, 0, 12)
  191. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 16)
  192. || test_crop(a, 0, 0, 0, 8, -233, -233, -233, -233, 0, 0, 0, 7)
  193. || test_crop(a, 5, 3, 0, 0, -233, -233, -233, -233, 5, 2, 0, 0)
  194. || test_crop(a, 6, 4, 0, 0, -233, -233, -233, -233, 3, 3, 0, 0)
  195. || test_crop(a, 4, 4, 0, 0, -233, -233, -233, -233, 2, 5, 0, 0)
  196. || test_crop(a, 0, 4, 0, 11, -233, -233, -233, -233, 0, 3, 0, 7)
  197. || test_crop(a, 0, 3, 0, 12, -233, -233, -233, -233, 0, 4, 0, 12)
  198. || test_crop(a, 0, 2, 0, 8, -233, -233, -233, -233, 0, 5, 0, 16)
  199. || test_crop(a, 0, 4, 4, 0, -233, -233, -233, -233, 0, 4, 1, 0)
  200. || test_crop(a, 0, 5, 5, 0, -233, -233, -233, -233, 0, 2, 2, 0)
  201. || test_crop(a, 0, 2, 6, 0, -233, -233, -233, -233, 0, 1, 3, 0)
  202. || test_crop(a, 3, 0, 0, 11, -233, -233, -233, -233, 3, 0, 0, 12)
  203. || test_crop(a, 4, 0, 0, 12, -233, -233, -233, -233, 4, 0, 0, 16)
  204. || test_crop(a, 5, 0, 0, 8, -233, -233, -233, -233, 2, 0, 0, 7)
  205. || test_crop(a, 0, 4, 4, 11, -233, -233, -233, -233, 0, 4, 4, 12)
  206. || test_crop(a, 0, 5, 5, 12, -233, -233, -233, -233, 0, 4, 4, 16)
  207. || test_crop(a, 0, 6, 6, 8, -233, -233, -233, -233, 0, 3, 3, 7)
  208. || test_crop(a, 1, 1, 1, 11, -233, -233, -233, -233, 1, 1, 1, 16)
  209. || test_crop(a, 2, 2, 2, 12, -233, -233, -233, -233, 2, 2, 2, 7)
  210. || test_crop(a, 3, 3, 3, 8, -233, -233, -233, -233, 3, 3, 3, 12);
  211. }
  212. int main()
  213. {
  214. SRAND(776757);
  215. return 0
  216. || test_crop_0(RandomMat(112))
  217. || test_crop_0(RandomMat(126))
  218. || test_crop_0(RandomMat(127))
  219. || test_crop_3(RandomMat(20, 48))
  220. || test_crop_3(RandomMat(15, 36))
  221. || test_crop_3(RandomMat(16, 33))
  222. || test_crop_6(RandomMat(20, 20, 48))
  223. || test_crop_6(RandomMat(15, 15, 36))
  224. || test_crop_6(RandomMat(16, 16, 33))
  225. || test_crop_9(RandomMat(20, 20, 20, 48))
  226. || test_crop_9(RandomMat(15, 15, 15, 36))
  227. || test_crop_9(RandomMat(16, 16, 16, 33));
  228. }