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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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)
  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::Option opt;
  31. opt.num_threads = 1;
  32. opt.use_vulkan_compute = true;
  33. opt.use_int8_inference = false;
  34. int ret = test_layer<ncnn::Padding>("Padding", pd, weights, opt, a);
  35. if (ret != 0)
  36. {
  37. 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\n", w, h, c, top, bottom, left, right, type, value, per_channel_pad_data_size);
  38. }
  39. return ret;
  40. }
  41. static int test_padding_0()
  42. {
  43. return 0
  44. || test_padding(5, 7, 16, 1, 1, 1, 1, 0, 0.f, 0)
  45. || test_padding(5, 7, 16, 2, 3, 2, 3, 1, 0.f, 0)
  46. || test_padding(5, 7, 16, 4, 3, 4, 3, 2, 0.f, 0)
  47. || test_padding(5, 7, 16, 4, 3, 4, 3, 0, 0.f, 16)
  48. || test_padding(5, 7, 5, 2, 3, 2, 3, 1, 0.f, 0)
  49. || test_padding(5, 7, 6, 4, 3, 4, 3, 2, 0.f, 0)
  50. || test_padding(5, 7, 7, 0, 1, 0, 1, 0, 233.f, 0)
  51. || test_padding(5, 7, 3, 2, 1, 2, 1, 0, 0.f, 3)
  52. ;
  53. }
  54. int main()
  55. {
  56. SRAND(7767517);
  57. return test_padding_0();
  58. }