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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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, bool use_packing_layout)
  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. pd.set(6, per_channel_pad_data_size);// per_channel_pad_data_size
  27. std::vector<ncnn::Mat> weights(per_channel_pad_data_size ? 1 : 0);
  28. if (per_channel_pad_data_size)
  29. weights[0] = RandomMat(per_channel_pad_data_size);
  30. ncnn::ModelBinFromMatArray mb(weights.data());
  31. ncnn::Option opt;
  32. opt.num_threads = 1;
  33. opt.use_vulkan_compute = true;
  34. opt.use_int8_inference = false;
  35. opt.use_fp16_packed = false;
  36. opt.use_fp16_storage = false;
  37. opt.use_fp16_arithmetic = false;
  38. opt.use_int8_storage = false;
  39. opt.use_int8_arithmetic = false;
  40. opt.use_packing_layout = use_packing_layout;
  41. int ret = test_layer<ncnn::Padding>("Padding", pd, mb, opt, a);
  42. if (ret != 0)
  43. {
  44. fprintf(stderr, "test_padding failed w=%d h=%d c=%d top=%d bottom=%d left=%d right=%d type=%d value=%f per_channel_pad_data_size=%d use_packing_layout=%d\n", w, h, c, top, bottom, left, right, type, value, per_channel_pad_data_size, use_packing_layout);
  45. }
  46. return ret;
  47. }
  48. static int test_padding_0()
  49. {
  50. return 0
  51. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0, false)
  52. || test_padding(5, 7, 16, 2, 3, 2, 3, 1, 0.f, 0, false)
  53. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, false)
  54. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16, false)
  55. || test_padding(5, 7, 5, 2, 3, 2, 3, 1, 0.f, 0, false)
  56. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0, false)
  57. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0, false)
  58. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3, false)
  59. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0, true)
  60. || test_padding(5, 7, 16, 2, 3, 2, 3, 1, 0.f, 0, true)
  61. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0, true)
  62. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16, true)
  63. || test_padding(5, 7, 5, 2, 3, 2, 3, 1, 0.f, 0, true)
  64. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0, true)
  65. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0, true)
  66. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3, true)
  67. ;
  68. }
  69. int main()
  70. {
  71. SRAND(7767517);
  72. return test_padding_0();
  73. }