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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, 16, 1, 1, 1, 1, 0, 0.f, 0, 4, 0)
  47. || test_padding(5, 7, 16, 4, 3, 4, 3, 1, 0.f, 0, 4, 0)
  48. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, 4, 0)
  49. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0, 0, 4)
  50. || test_padding(5, 7, 17, 2, 3, 2, 3, 1, 0.f, 0, 4, 9)
  51. || test_padding(5, 7, 12, 4, 3, 4, 3, 0, 1.f, 0, 4, 8)
  52. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, 4, 8)
  53. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16, 4, 2)
  54. || test_padding(5, 7, 8, 2, 3, 2, 3, 1, 0.f, 22, 8, 0)
  55. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0, 2, 4)
  56. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0, 3, 1)
  57. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3, 0, 4)
  58. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3, 4, 4)
  59. || test_padding(5, 7, 16, 2, 1, 2, 1, 0, 0.f, 3, 8, 8)
  60. || test_padding(5, 7, 16, 2, 1, 2, 1, 1, 0.f, 3, 8, 8)
  61. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3, 8, 8);
  62. }
  63. int main()
  64. {
  65. SRAND(7767517);
  66. return test_padding_0();
  67. }