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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "layer/normalize.h"
  15. #include "testutil.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. int ret = test_layer<ncnn::Normalize>("Normalize", pd, weights, a);
  29. if (ret != 0)
  30. {
  31. 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);
  32. }
  33. return ret;
  34. }
  35. static int test_normalize_0()
  36. {
  37. ncnn::Mat a = RandomMat(6, 4, 2);
  38. ncnn::Mat b = RandomMat(5, 7, 8);
  39. return 0
  40. || test_normalize(a, 1, 0, 0, 0.01f, 0)
  41. || test_normalize(a, 1, 0, 0, 0.001f, 1)
  42. || test_normalize(a, 1, 0, 0, 0.002f, 2)
  43. || test_normalize(a, 1, 0, 1, 0.01f, 0)
  44. || test_normalize(a, 1, 0, 1, 0.001f, 1)
  45. || test_normalize(a, 1, 0, 1, 0.002f, 2)
  46. || test_normalize(b, 1, 0, 0, 0.01f, 0)
  47. || test_normalize(b, 1, 0, 0, 0.001f, 1)
  48. || test_normalize(b, 1, 0, 0, 0.002f, 2)
  49. || test_normalize(b, 1, 0, 1, 0.01f, 0)
  50. || test_normalize(b, 1, 0, 1, 0.001f, 1)
  51. || test_normalize(b, 1, 0, 1, 0.002f, 2);
  52. }
  53. static int test_normalize_1()
  54. {
  55. ncnn::Mat a = RandomMat(5, 6, 3);
  56. ncnn::Mat b = RandomMat(3, 4, 8);
  57. return 0
  58. || test_normalize(a, 0, 1, 0, 0.01f, 0)
  59. || test_normalize(a, 0, 1, 0, 0.001f, 1)
  60. || test_normalize(a, 0, 1, 0, 0.002f, 2)
  61. || test_normalize(a, 0, 1, 1, 0.01f, 0)
  62. || test_normalize(a, 0, 1, 1, 0.001f, 1)
  63. || test_normalize(a, 0, 1, 1, 0.002f, 2)
  64. || test_normalize(b, 0, 1, 0, 0.01f, 0)
  65. || test_normalize(b, 0, 1, 0, 0.001f, 1)
  66. || test_normalize(b, 0, 1, 0, 0.002f, 2)
  67. || test_normalize(b, 0, 1, 1, 0.01f, 0)
  68. || test_normalize(b, 0, 1, 1, 0.001f, 1)
  69. || test_normalize(b, 0, 1, 1, 0.002f, 2);
  70. }
  71. static int test_normalize_2()
  72. {
  73. ncnn::Mat a = RandomMat(2, 3, 5);
  74. ncnn::Mat b = RandomMat(4, 6, 8);
  75. return 0
  76. || test_normalize(a, 1, 1, 0, 0.01f, 0)
  77. || test_normalize(a, 1, 1, 0, 0.001f, 1)
  78. || test_normalize(a, 1, 1, 0, 0.002f, 2)
  79. || test_normalize(a, 1, 1, 1, 0.01f, 0)
  80. || test_normalize(a, 1, 1, 1, 0.001f, 1)
  81. || test_normalize(a, 1, 1, 1, 0.002f, 2)
  82. || test_normalize(b, 1, 1, 0, 0.01f, 0)
  83. || test_normalize(b, 1, 1, 0, 0.001f, 1)
  84. || test_normalize(b, 1, 1, 0, 0.002f, 2)
  85. || test_normalize(b, 1, 1, 1, 0.01f, 0)
  86. || test_normalize(b, 1, 1, 1, 0.001f, 1)
  87. || test_normalize(b, 1, 1, 1, 0.002f, 2);
  88. }
  89. int main()
  90. {
  91. SRAND(7767517);
  92. return 0
  93. || test_normalize_0()
  94. || test_normalize_1()
  95. || test_normalize_2();
  96. }