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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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)
  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::Option opt;
  29. opt.num_threads = 1;
  30. opt.use_vulkan_compute = true;
  31. opt.use_int8_inference = false;
  32. int ret = test_layer<ncnn::Pooling>("Pooling", pd, weights, opt, a);
  33. if (ret != 0)
  34. {
  35. 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\n", w, h, c, pooling_type, kernel, stride, pad, global_pooling, pad_mode, avgpool_count_include_pad);
  36. }
  37. return ret;
  38. }
  39. static int test_pooling_0()
  40. {
  41. static const int ksp[11][3] = {
  42. {2, 1, 0},
  43. {2, 2, 0},
  44. {3, 1, 0},
  45. {3, 2, 1},
  46. {4, 1, 0},
  47. {4, 2, 1},
  48. {5, 1, 0},
  49. {5, 2, 2},
  50. {7, 1, 0},
  51. {7, 2, 1},
  52. {7, 3, 2},
  53. };
  54. for (int i=0; i<11; i++)
  55. {
  56. int ret = 0
  57. || test_pooling(9, 7, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  58. || test_pooling(9, 7, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  59. || test_pooling(9, 7, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  60. || test_pooling(9, 7, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  61. || test_pooling(9, 7, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  62. || test_pooling(9, 7, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  63. || test_pooling(9, 7, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  64. || test_pooling(9, 7, 16, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  65. ;
  66. if (ret != 0)
  67. return -1;
  68. }
  69. return 0;
  70. }
  71. static int test_pooling_1()
  72. {
  73. static const int ksp[11][3] = {
  74. {2, 1, 0},
  75. {2, 2, 0},
  76. {3, 1, 0},
  77. {3, 2, 1},
  78. {4, 1, 0},
  79. {4, 2, 1},
  80. {5, 1, 0},
  81. {5, 2, 2},
  82. {7, 1, 0},
  83. {7, 2, 1},
  84. {7, 3, 2},
  85. };
  86. for (int i=0; i<11; i++)
  87. {
  88. int ret = 0
  89. || test_pooling(9, 7, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  90. || test_pooling(9, 7, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  91. || test_pooling(9, 7, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1)
  92. || test_pooling(9, 7, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  93. || test_pooling(9, 7, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  94. || test_pooling(9, 7, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1)
  95. || test_pooling(9, 7, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0)
  96. || test_pooling(9, 7, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0)
  97. ;
  98. if (ret != 0)
  99. return -1;
  100. }
  101. return 0;
  102. }
  103. static int test_pooling_2()
  104. {
  105. return 0
  106. || test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0)
  107. || test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0)
  108. || test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0)
  109. || test_pooling(6, 3, 3, 1, 1, 1, 0, 1, 0, 0)
  110. || test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0)
  111. || test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0)
  112. || test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0)
  113. || test_pooling(7, 8, 8, 1, 1, 1, 0, 1, 0, 0)
  114. || test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 0)
  115. || test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 0)
  116. ;
  117. }
  118. int main()
  119. {
  120. SRAND(7767517);
  121. return 0
  122. || test_pooling_0()
  123. || test_pooling_1()
  124. || test_pooling_2()
  125. ;
  126. }