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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 coffset, int outw, int outh, int outc, int woffset2, int hoffset2, int coffset2)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, woffset); // woffset
  20. pd.set(1, hoffset); // hoffset
  21. pd.set(2, coffset); // coffset
  22. pd.set(3, outw); // outw
  23. pd.set(4, outh); // outh
  24. pd.set(5, outc); // outc
  25. pd.set(6, woffset2); // woffset2
  26. pd.set(7, hoffset2); // hoffset2
  27. pd.set(8, coffset2); // coffset2
  28. std::vector<ncnn::Mat> weights(0);
  29. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, a);
  30. if (ret != 0)
  31. {
  32. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d) woffset=%d hoffset=%d coffset=%d outw=%d outh=%d outc=%d woffset2=%d hoffset2=%d coffset2=%d\n", a.dims, a.w, a.h, a.c, woffset, hoffset, coffset, outw, outh, outc, woffset2, hoffset2, coffset2);
  33. }
  34. return ret;
  35. }
  36. static ncnn::Mat IntArrayMat(int a0)
  37. {
  38. ncnn::Mat m(1);
  39. int* p = m;
  40. p[0] = a0;
  41. return m;
  42. }
  43. static ncnn::Mat IntArrayMat(int a0, int a1)
  44. {
  45. ncnn::Mat m(2);
  46. int* p = m;
  47. p[0] = a0;
  48. p[1] = a1;
  49. return m;
  50. }
  51. static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
  52. {
  53. ncnn::Mat m(3);
  54. int* p = m;
  55. p[0] = a0;
  56. p[1] = a1;
  57. p[2] = a2;
  58. return m;
  59. }
  60. static void print_int_array(const ncnn::Mat& a)
  61. {
  62. const int* pa = a;
  63. fprintf(stderr, "[");
  64. for (int i = 0; i < a.w; i++)
  65. {
  66. fprintf(stderr, " %d", pa[i]);
  67. }
  68. fprintf(stderr, " ]");
  69. }
  70. static int test_crop(const ncnn::Mat& a, const ncnn::Mat& starts, const ncnn::Mat& ends, const ncnn::Mat& axes)
  71. {
  72. ncnn::ParamDict pd;
  73. pd.set(9, starts); // starts
  74. pd.set(10, ends); // ends
  75. pd.set(11, axes); // axes
  76. std::vector<ncnn::Mat> weights(0);
  77. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, a);
  78. if (ret != 0)
  79. {
  80. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d)", a.dims, a.w, a.h, a.c);
  81. fprintf(stderr, " starts=");
  82. print_int_array(starts);
  83. fprintf(stderr, " ends=");
  84. print_int_array(ends);
  85. fprintf(stderr, " axes=");
  86. print_int_array(axes);
  87. fprintf(stderr, "\n");
  88. }
  89. return ret;
  90. }
  91. static int test_crop(const ncnn::Mat& a, int woffset, int hoffset, int coffset, const ncnn::Mat& ref)
  92. {
  93. ncnn::ParamDict pd;
  94. pd.set(0, woffset);
  95. pd.set(1, hoffset);
  96. pd.set(2, coffset);
  97. pd.set(3, 0); // outw
  98. pd.set(4, 0); // outh
  99. pd.set(5, 0); // outc
  100. pd.set(6, 0); // woffset2
  101. pd.set(7, 0); // hoffset2
  102. pd.set(8, 0); // coffset2
  103. std::vector<ncnn::Mat> weights(0);
  104. std::vector<ncnn::Mat> ab(2);
  105. ab[0] = a;
  106. ab[1] = ref;
  107. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, ab);
  108. if (ret != 0)
  109. {
  110. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d) woffset=%d hoffset=%d coffset=%d ref.dims=%d ref=(%d %d %d)\n", a.dims, a.w, a.h, a.c, woffset, hoffset, coffset, ref.dims, ref.w, ref.h, ref.c);
  111. }
  112. return ret;
  113. }
  114. static int test_crop_0(const ncnn::Mat& a)
  115. {
  116. return 0
  117. || test_crop(a, 0, 0, 0, -233, 0, 0, 0, 0, 0)
  118. || test_crop(a, 11, 0, 0, -233, 0, 0, 0, 0, 0)
  119. || test_crop(a, 11, 0, 0, 17, 0, 0, 0, 0, 0)
  120. || test_crop(a, 12, 0, 0, 28, 0, 0, 0, 0, 0)
  121. || test_crop(a, 24, 0, 0, 24, 0, 0, 0, 0, 0)
  122. || test_crop(a, 11, 0, 0, -233, 0, 0, 28, 0, 0)
  123. || test_crop(a, 12, 0, 0, -233, 0, 0, 24, 0, 0)
  124. || test_crop(a, 24, 0, 0, -233, 0, 0, 17, 0, 0);
  125. }
  126. static int test_crop_1(const ncnn::Mat& a)
  127. {
  128. return 0
  129. || test_crop(a, IntArrayMat(12), IntArrayMat(-233), IntArrayMat(0))
  130. || test_crop(a, IntArrayMat(24), IntArrayMat(-233), IntArrayMat(0))
  131. || test_crop(a, IntArrayMat(11), IntArrayMat(11 + 24), IntArrayMat(0))
  132. || test_crop(a, IntArrayMat(12), IntArrayMat(12 + 17), IntArrayMat(0))
  133. || test_crop(a, IntArrayMat(24), IntArrayMat(24 + 28), IntArrayMat(0))
  134. || test_crop(a, IntArrayMat(11), IntArrayMat(-17 + 1), IntArrayMat(0))
  135. || test_crop(a, IntArrayMat(12), IntArrayMat(-28 + 1), IntArrayMat(0))
  136. || test_crop(a, IntArrayMat(24), IntArrayMat(-24 + 1), IntArrayMat(0));
  137. }
  138. static int test_crop_2(const ncnn::Mat& a)
  139. {
  140. return 0
  141. || test_crop(a, 0, 0, 0, ncnn::Mat(27))
  142. || test_crop(a, 11, 0, 0, ncnn::Mat(17))
  143. || test_crop(a, 12, 0, 0, ncnn::Mat(28))
  144. || test_crop(a, 24, 0, 0, ncnn::Mat(24));
  145. }
  146. static int test_crop_3(const ncnn::Mat& a)
  147. {
  148. return 0
  149. || test_crop(a, 0, 0, 0, -233, -233, 0, 0, 0, 0)
  150. || test_crop(a, 11, 0, 0, -233, -233, 0, 0, 0, 0)
  151. || test_crop(a, 0, 11, 0, -233, -233, 0, 0, 0, 0)
  152. || test_crop(a, 0, 12, 0, -233, -233, 0, 0, 0, 0)
  153. || test_crop(a, 12, 12, 0, -233, -233, 0, 0, 0, 0)
  154. || test_crop(a, 16, 16, 0, -233, -233, 0, 0, 0, 0)
  155. || test_crop(a, 11, 0, 0, 17, -233, 0, 0, 0, 0)
  156. || test_crop(a, 12, 0, 0, 28, -233, 0, 0, 0, 0)
  157. || test_crop(a, 16, 0, 0, 24, -233, 0, 0, 0, 0)
  158. || test_crop(a, 0, 11, 0, -233, 28, 0, 0, 0, 0)
  159. || test_crop(a, 0, 12, 0, -233, 24, 0, 0, 0, 0)
  160. || test_crop(a, 0, 16, 0, -233, 17, 0, 0, 0, 0)
  161. || test_crop(a, 11, 11, 0, 24, 24, 0, 0, 0, 0)
  162. || test_crop(a, 12, 12, 0, 17, 17, 0, 0, 0, 0)
  163. || test_crop(a, 16, 16, 0, 28, 28, 0, 0, 0, 0)
  164. || test_crop(a, 11, 0, 0, -233, -233, 0, 17, 0, 0)
  165. || test_crop(a, 12, 0, 0, -233, -233, 0, 28, 0, 0)
  166. || test_crop(a, 16, 0, 0, -233, -233, 0, 24, 0, 0)
  167. || test_crop(a, 0, 11, 0, -233, -233, 0, 0, 28, 0)
  168. || test_crop(a, 0, 12, 0, -233, -233, 0, 0, 24, 0)
  169. || test_crop(a, 0, 16, 0, -233, -233, 0, 0, 17, 0)
  170. || test_crop(a, 11, 11, 0, -233, -233, 0, 24, 24, 0)
  171. || test_crop(a, 12, 12, 0, -233, -233, 0, 17, 17, 0)
  172. || test_crop(a, 16, 16, 0, -233, -233, 0, 28, 28, 0);
  173. }
  174. static int test_crop_4(const ncnn::Mat& a)
  175. {
  176. return 0
  177. || test_crop(a, IntArrayMat(12), IntArrayMat(-233), IntArrayMat(0))
  178. || test_crop(a, IntArrayMat(16), IntArrayMat(-233), IntArrayMat(0))
  179. || test_crop(a, IntArrayMat(16), IntArrayMat(-233), IntArrayMat(1))
  180. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-233, -233), IntArrayMat(0, 1))
  181. || test_crop(a, IntArrayMat(11), IntArrayMat(28), IntArrayMat(0))
  182. || test_crop(a, IntArrayMat(12), IntArrayMat(24), IntArrayMat(0))
  183. || test_crop(a, IntArrayMat(16), IntArrayMat(17), IntArrayMat(0))
  184. || test_crop(a, IntArrayMat(11), IntArrayMat(24), IntArrayMat(1))
  185. || test_crop(a, IntArrayMat(12), IntArrayMat(17), IntArrayMat(1))
  186. || test_crop(a, IntArrayMat(16), IntArrayMat(28), IntArrayMat(1))
  187. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(17, 17), IntArrayMat(0, 1))
  188. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(28, 28), IntArrayMat(0, 1))
  189. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(24, 24), IntArrayMat(0, 1))
  190. || test_crop(a, IntArrayMat(11), IntArrayMat(-24 + 1), IntArrayMat(0))
  191. || test_crop(a, IntArrayMat(12), IntArrayMat(-17 + 1), IntArrayMat(0))
  192. || test_crop(a, IntArrayMat(16), IntArrayMat(-28 + 1), IntArrayMat(0))
  193. || test_crop(a, IntArrayMat(11), IntArrayMat(-17 + 1), IntArrayMat(1))
  194. || test_crop(a, IntArrayMat(12), IntArrayMat(-28 + 1), IntArrayMat(1))
  195. || test_crop(a, IntArrayMat(16), IntArrayMat(-24 + 1), IntArrayMat(1))
  196. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-28 + 1, -28 + 1), IntArrayMat(0, 1))
  197. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-24 + 1, -24 + 1), IntArrayMat(0, 1))
  198. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(-17 + 1, -17 + 1), IntArrayMat(0, 1));
  199. }
  200. static int test_crop_5(const ncnn::Mat& a)
  201. {
  202. return 0
  203. || test_crop(a, 0, 12, 0, ncnn::Mat(24, 17))
  204. || test_crop(a, 11, 0, 0, ncnn::Mat(17, 27))
  205. || test_crop(a, 11, 11, 0, ncnn::Mat(28, 28))
  206. || test_crop(a, 12, 12, 0, ncnn::Mat(24, 24))
  207. || test_crop(a, 16, 16, 0, ncnn::Mat(17, 17));
  208. }
  209. static int test_crop_6(const ncnn::Mat& a)
  210. {
  211. return 0
  212. || test_crop(a, 0, 0, 0, -233, -233, -233, 0, 0, 0)
  213. || test_crop(a, 12, 0, 0, -233, -233, -233, 0, 0, 0)
  214. || test_crop(a, 0, 11, 0, -233, -233, -233, 0, 0, 0)
  215. || test_crop(a, 0, 16, 0, -233, -233, -233, 0, 0, 0)
  216. || test_crop(a, 0, 0, 12, -233, -233, -233, 0, 0, 0)
  217. || test_crop(a, 11, 11, 0, -233, -233, -233, 0, 0, 0)
  218. || test_crop(a, 16, 16, 0, -233, -233, -233, 0, 0, 0)
  219. || test_crop(a, 0, 12, 12, -233, -233, -233, 0, 0, 0)
  220. || test_crop(a, 11, 0, 11, -233, -233, -233, 0, 0, 0)
  221. || test_crop(a, 16, 0, 16, -233, -233, -233, 0, 0, 0)
  222. || test_crop(a, 12, 12, 12, -233, -233, -233, 0, 0, 0)
  223. || test_crop(a, 11, 0, 0, 28, -233, -233, 0, 0, 0)
  224. || test_crop(a, 12, 0, 0, 24, -233, -233, 0, 0, 0)
  225. || test_crop(a, 16, 0, 0, 17, -233, -233, 0, 0, 0)
  226. || test_crop(a, 0, 11, 0, -233, 24, -233, 0, 0, 0)
  227. || test_crop(a, 0, 12, 0, -233, 17, -233, 0, 0, 0)
  228. || test_crop(a, 0, 16, 0, -233, 28, -233, 0, 0, 0)
  229. || test_crop(a, 0, 0, 11, -233, -233, 17, 0, 0, 0)
  230. || test_crop(a, 0, 0, 12, -233, -233, 28, 0, 0, 0)
  231. || test_crop(a, 0, 0, 16, -233, -233, 24, 0, 0, 0)
  232. || test_crop(a, 11, 11, 0, 17, 17, -233, 0, 0, 0)
  233. || test_crop(a, 12, 12, 0, 28, 28, -233, 0, 0, 0)
  234. || test_crop(a, 16, 16, 0, 24, 24, -233, 0, 0, 0)
  235. || test_crop(a, 0, 11, 11, -233, 28, 28, 0, 0, 0)
  236. || test_crop(a, 0, 12, 12, -233, 24, 24, 0, 0, 0)
  237. || test_crop(a, 0, 16, 16, -233, 17, 17, 0, 0, 0)
  238. || test_crop(a, 11, 0, 11, 24, -233, 24, 0, 0, 0)
  239. || test_crop(a, 12, 0, 12, 17, -233, 17, 0, 0, 0)
  240. || test_crop(a, 16, 0, 16, 24, -233, 24, 0, 0, 0)
  241. || test_crop(a, 11, 11, 11, 28, 28, 28, 0, 0, 0)
  242. || test_crop(a, 12, 12, 12, 24, 24, 24, 0, 0, 0)
  243. || test_crop(a, 16, 16, 16, 17, 17, 17, 0, 0, 0)
  244. || test_crop(a, 11, 0, 0, -233, -233, -233, 24, 0, 0)
  245. || test_crop(a, 12, 0, 0, -233, -233, -233, 17, 0, 0)
  246. || test_crop(a, 16, 0, 0, -233, -233, -233, 28, 0, 0)
  247. || test_crop(a, 0, 11, 0, -233, -233, -233, 0, 17, 0)
  248. || test_crop(a, 0, 12, 0, -233, -233, -233, 0, 28, 0)
  249. || test_crop(a, 0, 16, 0, -233, -233, -233, 0, 24, 0)
  250. || test_crop(a, 0, 0, 11, -233, -233, -233, 0, 0, 28)
  251. || test_crop(a, 0, 0, 12, -233, -233, -233, 0, 0, 24)
  252. || test_crop(a, 0, 0, 16, -233, -233, -233, 0, 0, 17)
  253. || test_crop(a, 11, 11, 0, -233, -233, -233, 24, 24, 0)
  254. || test_crop(a, 12, 12, 0, -233, -233, -233, 17, 17, 0)
  255. || test_crop(a, 16, 16, 0, -233, -233, -233, 28, 28, 0)
  256. || test_crop(a, 0, 11, 11, -233, -233, -233, 0, 17, 17)
  257. || test_crop(a, 0, 12, 12, -233, -233, -233, 0, 28, 28)
  258. || test_crop(a, 0, 16, 16, -233, -233, -233, 0, 24, 24)
  259. || test_crop(a, 11, 0, 11, -233, -233, -233, 28, 0, 28)
  260. || test_crop(a, 12, 0, 12, -233, -233, -233, 24, 0, 24)
  261. || test_crop(a, 16, 0, 16, -233, -233, -233, 17, 0, 17)
  262. || test_crop(a, 11, 11, 11, -233, -233, -233, 24, 24, 24)
  263. || test_crop(a, 12, 12, 12, -233, -233, -233, 17, 17, 17)
  264. || test_crop(a, 16, 16, 16, -233, -233, -233, 28, 28, 28);
  265. }
  266. static int test_crop_7(const ncnn::Mat& a)
  267. {
  268. return 0
  269. || test_crop(a, IntArrayMat(11), IntArrayMat(-233), IntArrayMat(0))
  270. || test_crop(a, IntArrayMat(16), IntArrayMat(-233), IntArrayMat(0))
  271. || test_crop(a, IntArrayMat(12), IntArrayMat(-233), IntArrayMat(1))
  272. || test_crop(a, IntArrayMat(11), IntArrayMat(-233), IntArrayMat(2))
  273. || test_crop(a, IntArrayMat(16), IntArrayMat(-233), IntArrayMat(2))
  274. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-233, -233), IntArrayMat(0, 1))
  275. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-233, -233), IntArrayMat(0, 2))
  276. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(-233, -233), IntArrayMat(0, 2))
  277. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-233, -233), IntArrayMat(1, 2))
  278. || test_crop(a, IntArrayMat(11, 11, 11), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 2))
  279. || test_crop(a, IntArrayMat(16, 16, 16), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 2))
  280. || test_crop(a, IntArrayMat(11), IntArrayMat(24), IntArrayMat(0))
  281. || test_crop(a, IntArrayMat(12), IntArrayMat(17), IntArrayMat(0))
  282. || test_crop(a, IntArrayMat(16), IntArrayMat(28), IntArrayMat(0))
  283. || test_crop(a, IntArrayMat(11), IntArrayMat(17), IntArrayMat(1))
  284. || test_crop(a, IntArrayMat(12), IntArrayMat(28), IntArrayMat(1))
  285. || test_crop(a, IntArrayMat(16), IntArrayMat(24), IntArrayMat(1))
  286. || test_crop(a, IntArrayMat(11), IntArrayMat(28), IntArrayMat(2))
  287. || test_crop(a, IntArrayMat(12), IntArrayMat(24), IntArrayMat(2))
  288. || test_crop(a, IntArrayMat(16), IntArrayMat(17), IntArrayMat(2))
  289. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(24, 24), IntArrayMat(0, 1))
  290. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(17, 17), IntArrayMat(0, 1))
  291. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(28, 28), IntArrayMat(0, 1))
  292. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(17, 17), IntArrayMat(0, 2))
  293. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(28, 28), IntArrayMat(0, 2))
  294. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(24, 24), IntArrayMat(0, 2))
  295. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(28, 28), IntArrayMat(1, 2))
  296. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(24, 24), IntArrayMat(1, 2))
  297. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(17, 17), IntArrayMat(1, 2))
  298. || test_crop(a, IntArrayMat(11, 11, 11), IntArrayMat(24, 24, 24), IntArrayMat(0, 1, 2))
  299. || test_crop(a, IntArrayMat(12, 12, 12), IntArrayMat(17, 17, 17), IntArrayMat(0, 1, 2))
  300. || test_crop(a, IntArrayMat(16, 16, 16), IntArrayMat(28, 28, 28), IntArrayMat(0, 1, 2))
  301. || test_crop(a, IntArrayMat(11), IntArrayMat(-17 + 1), IntArrayMat(0))
  302. || test_crop(a, IntArrayMat(12), IntArrayMat(-28 + 1), IntArrayMat(0))
  303. || test_crop(a, IntArrayMat(16), IntArrayMat(-24 + 1), IntArrayMat(0))
  304. || test_crop(a, IntArrayMat(11), IntArrayMat(-28 + 1), IntArrayMat(1))
  305. || test_crop(a, IntArrayMat(12), IntArrayMat(-24 + 1), IntArrayMat(1))
  306. || test_crop(a, IntArrayMat(16), IntArrayMat(-17 + 1), IntArrayMat(1))
  307. || test_crop(a, IntArrayMat(11), IntArrayMat(-24 + 1), IntArrayMat(2))
  308. || test_crop(a, IntArrayMat(12), IntArrayMat(-17 + 1), IntArrayMat(2))
  309. || test_crop(a, IntArrayMat(16), IntArrayMat(-28 + 1), IntArrayMat(2))
  310. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-17 + 1, -17 + 1), IntArrayMat(0, 1))
  311. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-28 + 1, -28 + 1), IntArrayMat(0, 1))
  312. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(-24 + 1, -24 + 1), IntArrayMat(0, 1))
  313. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-28 + 1, -28 + 1), IntArrayMat(0, 2))
  314. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-24 + 1, -24 + 1), IntArrayMat(0, 2))
  315. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(-17 + 1, -17 + 1), IntArrayMat(0, 2))
  316. || test_crop(a, IntArrayMat(11, 11), IntArrayMat(-24 + 1, -24 + 1), IntArrayMat(1, 2))
  317. || test_crop(a, IntArrayMat(12, 12), IntArrayMat(-17 + 1, -17 + 1), IntArrayMat(1, 2))
  318. || test_crop(a, IntArrayMat(16, 16), IntArrayMat(-28 + 1, -28 + 1), IntArrayMat(1, 2))
  319. || test_crop(a, IntArrayMat(11, 11, 11), IntArrayMat(-17 + 1, -17 + 1, -17 + 1), IntArrayMat(0, 1, 2))
  320. || test_crop(a, IntArrayMat(12, 12, 12), IntArrayMat(-28 + 1, -28 + 1, -28 + 1), IntArrayMat(0, 1, 2))
  321. || test_crop(a, IntArrayMat(16, 16, 16), IntArrayMat(-24 + 1, -24 + 1, -24 + 1), IntArrayMat(0, 1, 2));
  322. }
  323. static int test_crop_8(const ncnn::Mat& a)
  324. {
  325. return 0
  326. || test_crop(a, 0, 11, 0, ncnn::Mat(28, 28))
  327. || test_crop(a, 12, 0, 0, ncnn::Mat(24, 24))
  328. || test_crop(a, 11, 11, 0, ncnn::Mat(28, 28))
  329. || test_crop(a, 12, 12, 0, ncnn::Mat(24, 24))
  330. || test_crop(a, 16, 16, 0, ncnn::Mat(17, 17))
  331. || test_crop(a, 11, 11, 11, ncnn::Mat(17, 17, 17))
  332. || test_crop(a, 12, 12, 12, ncnn::Mat(28, 28, 28))
  333. || test_crop(a, 16, 16, 16, ncnn::Mat(24, 24, 24));
  334. }
  335. int main()
  336. {
  337. SRAND(7767517);
  338. return 0
  339. || test_crop_0(RandomMat(128))
  340. || test_crop_0(RandomMat(124))
  341. || test_crop_0(RandomMat(127))
  342. || test_crop_1(RandomMat(128))
  343. || test_crop_1(RandomMat(124))
  344. || test_crop_1(RandomMat(127))
  345. || test_crop_2(RandomMat(128))
  346. || test_crop_2(RandomMat(124))
  347. || test_crop_2(RandomMat(127))
  348. || test_crop_3(RandomMat(64, 64))
  349. || test_crop_3(RandomMat(60, 60))
  350. || test_crop_3(RandomMat(63, 63))
  351. || test_crop_4(RandomMat(64, 64))
  352. || test_crop_4(RandomMat(60, 60))
  353. || test_crop_4(RandomMat(63, 63))
  354. || test_crop_5(RandomMat(64, 64))
  355. || test_crop_5(RandomMat(60, 60))
  356. || test_crop_5(RandomMat(63, 63))
  357. || test_crop_6(RandomMat(64, 64, 64))
  358. || test_crop_6(RandomMat(60, 60, 60))
  359. || test_crop_6(RandomMat(63, 63, 63))
  360. || test_crop_7(RandomMat(64, 64, 64))
  361. || test_crop_7(RandomMat(60, 60, 60))
  362. || test_crop_7(RandomMat(63, 63, 63))
  363. || test_crop_8(RandomMat(64, 64, 64))
  364. || test_crop_8(RandomMat(60, 60, 60))
  365. || test_crop_8(RandomMat(63, 63, 63));
  366. }