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_scale.cpp 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/scale.h"
  16. static int test_scale(const ncnn::Mat& a, int scale_data_size, int bias)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, scale_data_size);
  20. pd.set(1, bias);
  21. std::vector<ncnn::Mat> weights(bias ? 2 : 1);
  22. weights[0] = RandomMat(scale_data_size);
  23. if (bias)
  24. weights[1] = RandomMat(scale_data_size);
  25. ncnn::Option opt;
  26. opt.num_threads = 1;
  27. opt.use_vulkan_compute = true;
  28. opt.use_int8_inference = false;
  29. int ret = test_layer<ncnn::Scale>("Scale", pd, weights, opt, a);
  30. if (ret != 0)
  31. {
  32. fprintf(stderr, "test_scale failed a.dims=%d a=(%d %d %d) scale_data_size=%d bias=%d\n", a.dims, a.w, a.h, a.c, scale_data_size, bias);
  33. }
  34. return ret;
  35. }
  36. static int test_scale_attention(const ncnn::Mat& a, int scale_data_size)
  37. {
  38. ncnn::ParamDict pd;
  39. pd.set(0, -233);
  40. std::vector<ncnn::Mat> weights(0);
  41. ncnn::Option opt;
  42. opt.num_threads = 1;
  43. opt.use_int8_inference = false;
  44. std::vector<ncnn::Mat> ab(2);
  45. ab[0] = a;
  46. ab[1] = RandomMat(scale_data_size);
  47. int ret = test_layer<ncnn::Scale>("Scale", pd, weights, opt, ab, 2);
  48. if (ret != 0)
  49. {
  50. fprintf(stderr, "test_scale_attention failed a.dims=%d a=(%d %d %d) scale_data_size=%d\n", a.dims, a.w, a.h, a.c, scale_data_size);
  51. }
  52. return ret;
  53. }
  54. static int test_scale_0()
  55. {
  56. return 0
  57. || test_scale(RandomMat(6, 7, 16), 16, 0)
  58. || test_scale(RandomMat(6, 7, 16), 16, 1)
  59. || test_scale(RandomMat(3, 5, 13), 13, 0)
  60. || test_scale(RandomMat(3, 5, 13), 13, 1)
  61. ;
  62. }
  63. static int test_scale_1()
  64. {
  65. return 0
  66. || test_scale(RandomMat(6, 16), 16, 0)
  67. || test_scale(RandomMat(6, 16), 16, 1)
  68. || test_scale(RandomMat(7, 15), 15, 0)
  69. || test_scale(RandomMat(7, 15), 15, 1)
  70. ;
  71. }
  72. static int test_scale_2()
  73. {
  74. return 0
  75. || test_scale(RandomMat(128), 128, 0)
  76. || test_scale(RandomMat(128), 128, 1)
  77. || test_scale(RandomMat(127), 127, 0)
  78. || test_scale(RandomMat(127), 127, 1)
  79. ;
  80. }
  81. static int test_scale_3()
  82. {
  83. return 0
  84. || test_scale_attention(RandomMat(6, 7, 16), 16)
  85. || test_scale_attention(RandomMat(3, 5, 13), 13)
  86. ;
  87. }
  88. static int test_scale_4()
  89. {
  90. return 0
  91. || test_scale_attention(RandomMat(6, 16), 16)
  92. || test_scale_attention(RandomMat(7, 15), 15)
  93. ;
  94. }
  95. static int test_scale_5()
  96. {
  97. return 0
  98. || test_scale_attention(RandomMat(128), 128)
  99. || test_scale_attention(RandomMat(127), 127)
  100. ;
  101. }
  102. int main()
  103. {
  104. SRAND(7767517);
  105. return 0
  106. || test_scale_0()
  107. || test_scale_1()
  108. || test_scale_2()
  109. || test_scale_3()
  110. || test_scale_4()
  111. || test_scale_5()
  112. ;
  113. }