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_pooling1d.cpp 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Copyright 2021 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_pooling1d(int w, int h, int pooling_type, int kernel, int stride, int pad, int global_pooling, int pad_mode, int avgpool_count_include_pad, int adaptive_pooling, int out_w)
  5. {
  6. ncnn::Mat a = RandomMat(w, h);
  7. ncnn::ParamDict pd;
  8. pd.set(0, pooling_type); // pooling_type
  9. pd.set(1, kernel); // kernel_w
  10. pd.set(2, stride); // stride_w
  11. pd.set(3, pad); // pad_w
  12. pd.set(4, global_pooling); // global_pooling
  13. pd.set(5, pad_mode); // pad_mode
  14. pd.set(6, avgpool_count_include_pad); // avgpool_count_include_pad
  15. pd.set(7, adaptive_pooling); // adaptive_pooling
  16. pd.set(8, out_w); // out_w
  17. std::vector<ncnn::Mat> weights(0);
  18. int ret = test_layer("Pooling1D", pd, weights, a);
  19. if (ret != 0)
  20. {
  21. fprintf(stderr, "test_pooling1d failed w=%d h=%d pooling_type=%d kernel=%d stride=%d pad=%d global_pooling=%d pad_mode=%d avgpool_count_include_pad=%d adaptive_pooling=%d out_w=%d\n", w, h, pooling_type, kernel, stride, pad, global_pooling, pad_mode, avgpool_count_include_pad, adaptive_pooling, out_w);
  22. }
  23. return ret;
  24. }
  25. static int test_pooling1d_0()
  26. {
  27. static const int ksp[11][3] = {
  28. {2, 1, 0},
  29. {2, 2, 0},
  30. {3, 1, 0},
  31. {3, 2, 1},
  32. {4, 1, 0},
  33. {4, 2, 1},
  34. {5, 1, 0},
  35. {5, 2, 2},
  36. {7, 1, 0},
  37. {7, 2, 1},
  38. {7, 3, 2},
  39. };
  40. for (int i = 0; i < 11; i++)
  41. {
  42. int ret = 0
  43. || test_pooling1d(9, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
  44. || test_pooling1d(9, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
  45. || test_pooling1d(9, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
  46. || test_pooling1d(9, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 0, 0, 0)
  47. || test_pooling1d(9, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
  48. || test_pooling1d(9, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
  49. || test_pooling1d(9, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
  50. || test_pooling1d(9, 16, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 0, 0, 0);
  51. if (ret != 0)
  52. return -1;
  53. }
  54. return 0;
  55. }
  56. static int test_pooling1d_1()
  57. {
  58. static const int ksp[11][3] = {
  59. {2, 1, 0},
  60. {2, 2, 0},
  61. {3, 1, 0},
  62. {3, 2, 1},
  63. {4, 1, 0},
  64. {4, 2, 1},
  65. {5, 1, 0},
  66. {5, 2, 2},
  67. {7, 1, 0},
  68. {7, 2, 1},
  69. {7, 3, 2},
  70. };
  71. for (int i = 0; i < 11; i++)
  72. {
  73. int ret = 0
  74. || test_pooling1d(9, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
  75. || test_pooling1d(9, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
  76. || test_pooling1d(9, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1, 0, 0)
  77. || test_pooling1d(9, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
  78. || test_pooling1d(9, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
  79. || test_pooling1d(9, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1, 0, 0)
  80. || test_pooling1d(9, 12, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 1, 0, 0)
  81. || test_pooling1d(9, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
  82. || test_pooling1d(9, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
  83. || test_pooling1d(9, 64, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 1, 0, 0);
  84. if (ret != 0)
  85. return -1;
  86. }
  87. return 0;
  88. }
  89. static int test_pooling1d_2()
  90. {
  91. return 0
  92. || test_pooling1d(2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0)
  93. || test_pooling1d(5, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0)
  94. || test_pooling1d(3, 3, 0, 1, 1, 0, 1, 0, 0, 0, 0)
  95. || test_pooling1d(6, 3, 1, 1, 1, 0, 1, 0, 0, 0, 0)
  96. || test_pooling1d(4, 4, 0, 1, 1, 0, 1, 0, 0, 0, 0)
  97. || test_pooling1d(6, 4, 1, 1, 1, 0, 1, 0, 0, 0, 0)
  98. || test_pooling1d(8, 8, 0, 1, 1, 0, 1, 0, 0, 0, 0)
  99. || test_pooling1d(7, 8, 1, 1, 1, 0, 1, 0, 0, 0, 0)
  100. || test_pooling1d(11, 16, 0, 1, 1, 0, 1, 0, 0, 0, 0)
  101. || test_pooling1d(13, 16, 1, 1, 1, 0, 1, 0, 0, 0, 0)
  102. || test_pooling1d(48, 4, 0, 2, 2, 0, 0, 0, 0, 0, 0)
  103. || test_pooling1d(48, 15, 0, 2, 2, 1, 0, 0, 0, 0, 0);
  104. }
  105. // adaptive avg pool
  106. static int test_pooling1d_3()
  107. {
  108. return 0
  109. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  110. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  111. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  112. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  113. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  114. || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  115. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  116. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  117. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  118. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  119. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  120. || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  121. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  122. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  123. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  124. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  125. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  126. || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  127. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  128. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  129. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  130. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  131. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  132. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  133. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 7)
  134. || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 8)
  135. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  136. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  137. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  138. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  139. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  140. || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  141. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 1)
  142. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 2)
  143. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 3)
  144. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 4)
  145. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 5)
  146. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 6)
  147. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 7)
  148. || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 8)
  149. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 1)
  150. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 3)
  151. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 5)
  152. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 7)
  153. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 9)
  154. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 11)
  155. || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 13)
  156. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 2)
  157. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 4)
  158. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 6)
  159. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 8)
  160. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 10)
  161. || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 12);
  162. }
  163. // adaptive max pool
  164. static int test_pooling1d_4()
  165. {
  166. return 0
  167. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  168. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  169. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  170. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  171. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  172. || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  173. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  174. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  175. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  176. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  177. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  178. || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  179. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  180. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  181. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  182. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  183. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  184. || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  185. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  186. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  187. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  188. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  189. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  190. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  191. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 7)
  192. || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 8)
  193. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  194. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  195. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  196. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  197. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  198. || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  199. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 1)
  200. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 2)
  201. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 3)
  202. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 4)
  203. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 5)
  204. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 6)
  205. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 7)
  206. || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 8)
  207. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 1)
  208. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 3)
  209. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 5)
  210. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 7)
  211. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 9)
  212. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 11)
  213. || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 13)
  214. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 2)
  215. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 4)
  216. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 6)
  217. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 8)
  218. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 10)
  219. || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 12);
  220. }
  221. int main()
  222. {
  223. SRAND(7767517);
  224. return 0
  225. || test_pooling1d_0()
  226. || test_pooling1d_1()
  227. || test_pooling1d_2()
  228. || test_pooling1d_3()
  229. || test_pooling1d_4();
  230. }