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_normalize.cpp 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/normalize.h"
  16. static int test_normalize(const ncnn::Mat& a, int across_spatial, int across_channel, int channel_shared, float eps, int eps_mode)
  17. {
  18. int scale_data_size = channel_shared ? 1 : a.c;
  19. ncnn::ParamDict pd;
  20. pd.set(0, across_spatial);
  21. pd.set(4, across_channel);
  22. pd.set(1, channel_shared);
  23. pd.set(2, eps);
  24. pd.set(3, scale_data_size);
  25. pd.set(9, eps_mode);
  26. std::vector<ncnn::Mat> weights(1);
  27. weights[0] = RandomMat(scale_data_size);
  28. ncnn::Option opt;
  29. opt.num_threads = 1;
  30. opt.use_vulkan_compute = true;
  31. opt.use_int8_inference = false;
  32. int ret = test_layer<ncnn::Normalize>("Normalize", pd, weights, opt, a);
  33. if (ret != 0)
  34. {
  35. fprintf(stderr, "test_normalize failed a.dims=%d a=(%d %d %d) across_spatial=%d across_channel=%d channel_shared=%d eps=%f eps_mode=%d\n", a.dims, a.w, a.h, a.c, across_spatial, across_channel, channel_shared, eps, eps_mode);
  36. }
  37. return ret;
  38. }
  39. static int test_normalize_0()
  40. {
  41. ncnn::Mat a = RandomMat(6, 4, 2);
  42. ncnn::Mat b = RandomMat(5, 7, 8);
  43. return 0
  44. || test_normalize(a, 1, 0, 0, 0.01f, 0)
  45. || test_normalize(a, 1, 0, 0, 0.001f, 1)
  46. || test_normalize(a, 1, 0, 0, 0.002f, 2)
  47. || test_normalize(a, 1, 0, 1, 0.01f, 0)
  48. || test_normalize(a, 1, 0, 1, 0.001f, 1)
  49. || test_normalize(a, 1, 0, 1, 0.002f, 2)
  50. || test_normalize(b, 1, 0, 0, 0.01f, 0)
  51. || test_normalize(b, 1, 0, 0, 0.001f, 1)
  52. || test_normalize(b, 1, 0, 0, 0.002f, 2)
  53. || test_normalize(b, 1, 0, 1, 0.01f, 0)
  54. || test_normalize(b, 1, 0, 1, 0.001f, 1)
  55. || test_normalize(b, 1, 0, 1, 0.002f, 2)
  56. ;
  57. }
  58. static int test_normalize_1()
  59. {
  60. ncnn::Mat a = RandomMat(5, 6, 3);
  61. ncnn::Mat b = RandomMat(3, 4, 8);
  62. return 0
  63. || test_normalize(a, 0, 1, 0, 0.01f, 0)
  64. || test_normalize(a, 0, 1, 0, 0.001f, 1)
  65. || test_normalize(a, 0, 1, 0, 0.002f, 2)
  66. || test_normalize(a, 0, 1, 1, 0.01f, 0)
  67. || test_normalize(a, 0, 1, 1, 0.001f, 1)
  68. || test_normalize(a, 0, 1, 1, 0.002f, 2)
  69. || test_normalize(b, 0, 1, 0, 0.01f, 0)
  70. || test_normalize(b, 0, 1, 0, 0.001f, 1)
  71. || test_normalize(b, 0, 1, 0, 0.002f, 2)
  72. || test_normalize(b, 0, 1, 1, 0.01f, 0)
  73. || test_normalize(b, 0, 1, 1, 0.001f, 1)
  74. || test_normalize(b, 0, 1, 1, 0.002f, 2)
  75. ;
  76. }
  77. static int test_normalize_2()
  78. {
  79. ncnn::Mat a = RandomMat(2, 3, 5);
  80. ncnn::Mat b = RandomMat(4, 6, 8);
  81. return 0
  82. || test_normalize(a, 1, 1, 0, 0.01f, 0)
  83. || test_normalize(a, 1, 1, 0, 0.001f, 1)
  84. || test_normalize(a, 1, 1, 0, 0.002f, 2)
  85. || test_normalize(a, 1, 1, 1, 0.01f, 0)
  86. || test_normalize(a, 1, 1, 1, 0.001f, 1)
  87. || test_normalize(a, 1, 1, 1, 0.002f, 2)
  88. || test_normalize(b, 1, 1, 0, 0.01f, 0)
  89. || test_normalize(b, 1, 1, 0, 0.001f, 1)
  90. || test_normalize(b, 1, 1, 0, 0.002f, 2)
  91. || test_normalize(b, 1, 1, 1, 0.01f, 0)
  92. || test_normalize(b, 1, 1, 1, 0.001f, 1)
  93. || test_normalize(b, 1, 1, 1, 0.002f, 2)
  94. ;
  95. }
  96. int main()
  97. {
  98. SRAND(7767517);
  99. return 0
  100. || test_normalize_0()
  101. || test_normalize_1()
  102. || test_normalize_2()
  103. ;
  104. }