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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/padding.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. per_channel_pad_data_size = c+front+behind;
  28. }
  29. pd.set(6, per_channel_pad_data_size);// per_channel_pad_data_size
  30. pd.set(7,front);
  31. pd.set(8,behind);
  32. std::vector<ncnn::Mat> weights(per_channel_pad_data_size ? 1 : 0);
  33. if (per_channel_pad_data_size)
  34. weights[0] = RandomMat(per_channel_pad_data_size);
  35. ncnn::Option opt;
  36. opt.num_threads = 1;
  37. opt.use_vulkan_compute = true;
  38. opt.use_int8_inference = false;
  39. int ret = test_layer<ncnn::Padding>("Padding", pd, weights, opt, a);
  40. if (ret != 0)
  41. {
  42. 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);
  43. }
  44. return ret;
  45. }
  46. static int test_padding_0()
  47. {
  48. return 0
  49. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0,4,0)
  50. || test_padding(5, 7, 16, 4, 3, 4, 3, 1, 0.f, 0,4,0)
  51. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0,4,0)
  52. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0,0,4)
  53. || test_padding(5, 7, 17, 2, 3, 2, 3, 1, 0.f, 0,4,9)
  54. || test_padding(5, 7, 12, 4, 3, 4, 3, 0, 1.f, 0,4,8)
  55. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0,4,8)
  56. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16,4,2)
  57. || test_padding(5, 7, 8, 2, 3, 2, 3, 1, 0.f, 22,8,0)
  58. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0,2,4)
  59. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0,3,1)
  60. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3,0,4)
  61. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3,4,4)
  62. || test_padding(5, 7, 16, 2, 1, 2, 1, 0, 0.f, 3,8,8)
  63. || test_padding(5, 7, 16, 2, 1, 2, 1, 1, 0.f, 3,8,8)
  64. || test_padding(5, 7, 16, 2, 1, 2, 1, 2, 0.f, 3,8,8)
  65. ;
  66. }
  67. int main()
  68. {
  69. SRAND(7767517);
  70. return test_padding_0();
  71. }