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_padding.cpp 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/padding.h"
  15. #include "testutil.h"
  16. static int test_padding(int w, int h, int c, int top, int bottom, int left, int right, int type, float value, int per_channel_pad_data_size, int front, int behind)
  17. {
  18. ncnn::Mat a = RandomMat(w, h, c);
  19. ncnn::ParamDict pd;
  20. pd.set(0, top); // top
  21. pd.set(1, bottom); // bottom
  22. pd.set(2, left); // left
  23. pd.set(3, right); // right
  24. pd.set(4, type); // type
  25. pd.set(5, value); // value
  26. if (per_channel_pad_data_size != 0)
  27. {
  28. per_channel_pad_data_size = c + front + behind;
  29. }
  30. pd.set(6, per_channel_pad_data_size); // per_channel_pad_data_size
  31. pd.set(7, front);
  32. pd.set(8, behind);
  33. std::vector<ncnn::Mat> weights(per_channel_pad_data_size ? 1 : 0);
  34. if (per_channel_pad_data_size)
  35. weights[0] = RandomMat(per_channel_pad_data_size);
  36. int ret = test_layer<ncnn::Padding>("Padding", pd, weights, a);
  37. if (ret != 0)
  38. {
  39. fprintf(stderr, "test_padding failed w=%d h=%d c=%d top=%d bottom=%d left=%d right=%d front=%d behind=%d type=%d value=%f per_channel_pad_data_size=%d\n", w, h, c, top, bottom, left, right, front, behind, type, value, per_channel_pad_data_size);
  40. }
  41. return ret;
  42. }
  43. static int test_padding_0()
  44. {
  45. return 0
  46. || test_padding(5, 7, 24, 1, 1, 1, 1, 0, 1.f, 0, 0, 0)
  47. || test_padding(5, 7, 24, 2, 3, 4, 5, 0, 0.f, 24, 0, 0)
  48. || test_padding(5, 7, 24, 4, 0, 0, 4, 1, 0.f, 0, 0, 0)
  49. || test_padding(5, 7, 24, 0, 3, 0, 3, 2, 0.f, 0, 0, 0)
  50. || test_padding(7, 9, 12, 2, 2, 2, 2, 0, 2.f, 0, 0, 0)
  51. || test_padding(7, 9, 12, 3, 4, 5, 6, 0, 0.f, 12, 0, 0)
  52. || test_padding(7, 9, 12, 1, 5, 5, 1, 1, 0.f, 0, 0, 0)
  53. || test_padding(7, 9, 12, 4, 2, 4, 1, 2, 0.f, 0, 0, 0)
  54. || test_padding(7, 5, 13, 3, 3, 3, 3, 0, 3.f, 0, 0, 0)
  55. || test_padding(7, 5, 13, 0, 1, 2, 0, 0, 0.f, 13, 0, 0)
  56. || test_padding(7, 5, 13, 4, 3, 4, 3, 1, 0.f, 0, 0, 0)
  57. || test_padding(7, 5, 13, 4, 4, 4, 3, 2, 0.f, 0, 0, 0);
  58. }
  59. static int test_padding_1()
  60. {
  61. return 0
  62. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0, 4, 0)
  63. || test_padding(5, 7, 16, 4, 3, 4, 3, 1, 0.f, 0, 4, 0)
  64. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, 4, 0)
  65. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0, 0, 4)
  66. || test_padding(5, 7, 17, 2, 3, 2, 3, 1, 0.f, 0, 4, 9)
  67. || test_padding(5, 7, 12, 4, 3, 4, 3, 0, 1.f, 0, 4, 8)
  68. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, 4, 8)
  69. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16, 4, 2)
  70. || test_padding(5, 7, 8, 2, 3, 2, 3, 1, 0.f, 22, 8, 0)
  71. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0, 2, 4)
  72. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0, 3, 1)
  73. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3, 0, 4)
  74. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3, 4, 4)
  75. || test_padding(5, 7, 16, 2, 1, 2, 1, 0, 0.f, 3, 8, 8)
  76. || test_padding(5, 7, 16, 2, 1, 2, 1, 1, 0.f, 3, 8, 8)
  77. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3, 8, 8);
  78. }
  79. int main()
  80. {
  81. SRAND(7767517);
  82. return test_padding_0() || test_padding_1();
  83. }