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_pooling.cpp 7.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include "layer/pooling.h"
  16. static int test_pooling(int w, int h, int c, int pooling_type, int kernel, int stride, int pad, int global_pooling, int pad_mode, int avgpool_count_include_pad, bool use_packing_layout)
  17. {
  18. ncnn::Mat a = RandomMat(w, h, c);
  19. ncnn::ParamDict pd;
  20. pd.set(0, pooling_type);// pooling_type
  21. pd.set(1, kernel);// kernel_w
  22. pd.set(2, stride);// stride_w
  23. pd.set(3, pad);// pad_w
  24. pd.set(4, global_pooling);// global_pooling
  25. pd.set(5, pad_mode);// pad_mode
  26. pd.set(6, avgpool_count_include_pad);// avgpool_count_include_pad
  27. std::vector<ncnn::Mat> weights(0);
  28. ncnn::ModelBinFromMatArray mb(weights.data());
  29. ncnn::Option opt;
  30. opt.num_threads = 1;
  31. opt.use_vulkan_compute = true;
  32. opt.use_fp16_packed = false;
  33. opt.use_fp16_storage = false;
  34. opt.use_fp16_arithmetic = false;
  35. opt.use_int8_storage = false;
  36. opt.use_int8_arithmetic = false;
  37. opt.use_packing_layout = use_packing_layout;
  38. int ret = test_layer<ncnn::Pooling>("Pooling", pd, mb, opt, a);
  39. if (ret != 0)
  40. {
  41. fprintf(stderr, "test_pooling failed w=%d h=%d c=%d pooling_type=%d kernel=%d stride=%d pad=%d global_pooling=%d pad_mode=%d avgpool_count_include_pad=%d use_packing_layout=%d\n", w, h, c, pooling_type, kernel, stride, pad, global_pooling, pad_mode, avgpool_count_include_pad, use_packing_layout);
  42. }
  43. return ret;
  44. }
  45. static int test_pooling_0()
  46. {
  47. static const int ksp[11][3] = {
  48. {2, 1, 0},
  49. {2, 2, 0},
  50. {3, 1, 0},
  51. {3, 2, 1},
  52. {4, 1, 0},
  53. {4, 2, 1},
  54. {5, 1, 0},
  55. {5, 2, 2},
  56. {7, 1, 0},
  57. {7, 2, 1},
  58. {7, 3, 2},
  59. };
  60. for (int i=0; i<11; i++)
  61. {
  62. int ret = 0
  63. || test_pooling(13, 11, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  64. || test_pooling(13, 11, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  65. || test_pooling(13, 11, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  66. || test_pooling(13, 11, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  67. || test_pooling(13, 11, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  68. || test_pooling(13, 11, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  69. || test_pooling(13, 11, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  70. || test_pooling(13, 11, 16, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  71. || test_pooling(13, 11, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  72. || test_pooling(13, 11, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  73. || test_pooling(13, 11, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  74. || test_pooling(13, 11, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  75. || test_pooling(13, 11, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  76. || test_pooling(13, 11, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  77. || test_pooling(13, 11, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  78. || test_pooling(13, 11, 16, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  79. ;
  80. if (ret != 0)
  81. return -1;
  82. }
  83. return 0;
  84. }
  85. static int test_pooling_1()
  86. {
  87. static const int ksp[11][3] = {
  88. {2, 1, 0},
  89. {2, 2, 0},
  90. {3, 1, 0},
  91. {3, 2, 1},
  92. {4, 1, 0},
  93. {4, 2, 1},
  94. {5, 1, 0},
  95. {5, 2, 2},
  96. {7, 1, 0},
  97. {7, 2, 1},
  98. {7, 3, 2},
  99. };
  100. for (int i=0; i<11; i++)
  101. {
  102. int ret = 0
  103. || test_pooling(13, 11, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  104. || test_pooling(13, 11, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  105. || test_pooling(13, 11, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1, false)
  106. || test_pooling(13, 11, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  107. || test_pooling(13, 11, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  108. || test_pooling(13, 11, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1, false)
  109. || test_pooling(13, 11, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, false)
  110. || test_pooling(13, 11, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, false)
  111. || test_pooling(13, 11, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  112. || test_pooling(13, 11, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  113. || test_pooling(13, 11, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1, true)
  114. || test_pooling(13, 11, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  115. || test_pooling(13, 11, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  116. || test_pooling(13, 11, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1, true)
  117. || test_pooling(13, 11, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, true)
  118. || test_pooling(13, 11, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, true)
  119. ;
  120. if (ret != 0)
  121. return -1;
  122. }
  123. return 0;
  124. }
  125. static int test_pooling_2()
  126. {
  127. return 0
  128. || test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, false)
  129. || test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, false)
  130. || test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, false)
  131. || test_pooling(6, 3, 3, 1, 1, 1, 0, 1, 0, 0, false)
  132. || test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, false)
  133. || test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, false)
  134. || test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, false)
  135. || test_pooling(7, 8, 8, 1, 1, 1, 0, 1, 0, 0, false)
  136. || test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 0, false)
  137. || test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 0, false)
  138. || test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, true)
  139. || test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, true)
  140. || test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, true)
  141. || test_pooling(6, 3, 3, 1, 1, 1, 0, 1, 0, 0, true)
  142. || test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, true)
  143. || test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, true)
  144. || test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, true)
  145. || test_pooling(7, 8, 8, 1, 1, 1, 0, 1, 0, 0, true)
  146. || test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 0, true)
  147. || test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 0, true)
  148. ;
  149. }
  150. int main()
  151. {
  152. SRAND(7767517);
  153. return 0
  154. || test_pooling_0()
  155. || test_pooling_1()
  156. || test_pooling_2()
  157. ;
  158. }