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.9 kB

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