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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_normalize(const ncnn::Mat& a, int across_spatial, int across_channel, int channel_shared, float eps, int eps_mode)
  5. {
  6. int scale_data_size = channel_shared ? 1 : a.c;
  7. ncnn::ParamDict pd;
  8. pd.set(0, across_spatial);
  9. pd.set(4, across_channel);
  10. pd.set(1, channel_shared);
  11. pd.set(2, eps);
  12. pd.set(3, scale_data_size);
  13. pd.set(9, eps_mode);
  14. std::vector<ncnn::Mat> weights(1);
  15. weights[0] = RandomMat(scale_data_size);
  16. int ret = test_layer("Normalize", pd, weights, a);
  17. if (ret != 0)
  18. {
  19. 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);
  20. }
  21. return ret;
  22. }
  23. static int test_normalize_0()
  24. {
  25. ncnn::Mat a = RandomMat(6, 4, 2);
  26. ncnn::Mat b = RandomMat(5, 7, 8);
  27. return 0
  28. || test_normalize(a, 1, 0, 0, 0.01f, 0)
  29. || test_normalize(a, 1, 0, 0, 0.001f, 1)
  30. || test_normalize(a, 1, 0, 0, 0.002f, 2)
  31. || test_normalize(a, 1, 0, 1, 0.01f, 0)
  32. || test_normalize(a, 1, 0, 1, 0.001f, 1)
  33. || test_normalize(a, 1, 0, 1, 0.002f, 2)
  34. || test_normalize(b, 1, 0, 0, 0.01f, 0)
  35. || test_normalize(b, 1, 0, 0, 0.001f, 1)
  36. || test_normalize(b, 1, 0, 0, 0.002f, 2)
  37. || test_normalize(b, 1, 0, 1, 0.01f, 0)
  38. || test_normalize(b, 1, 0, 1, 0.001f, 1)
  39. || test_normalize(b, 1, 0, 1, 0.002f, 2);
  40. }
  41. static int test_normalize_1()
  42. {
  43. ncnn::Mat a = RandomMat(5, 6, 3);
  44. ncnn::Mat b = RandomMat(3, 4, 8);
  45. return 0
  46. || test_normalize(a, 0, 1, 0, 0.01f, 0)
  47. || test_normalize(a, 0, 1, 0, 0.001f, 1)
  48. || test_normalize(a, 0, 1, 0, 0.002f, 2)
  49. || test_normalize(a, 0, 1, 1, 0.01f, 0)
  50. || test_normalize(a, 0, 1, 1, 0.001f, 1)
  51. || test_normalize(a, 0, 1, 1, 0.002f, 2)
  52. || test_normalize(b, 0, 1, 0, 0.01f, 0)
  53. || test_normalize(b, 0, 1, 0, 0.001f, 1)
  54. || test_normalize(b, 0, 1, 0, 0.002f, 2)
  55. || test_normalize(b, 0, 1, 1, 0.01f, 0)
  56. || test_normalize(b, 0, 1, 1, 0.001f, 1)
  57. || test_normalize(b, 0, 1, 1, 0.002f, 2);
  58. }
  59. static int test_normalize_2()
  60. {
  61. ncnn::Mat a = RandomMat(2, 3, 5);
  62. ncnn::Mat b = RandomMat(4, 6, 8);
  63. return 0
  64. || test_normalize(a, 1, 1, 0, 0.01f, 0)
  65. || test_normalize(a, 1, 1, 0, 0.001f, 1)
  66. || test_normalize(a, 1, 1, 0, 0.002f, 2)
  67. || test_normalize(a, 1, 1, 1, 0.01f, 0)
  68. || test_normalize(a, 1, 1, 1, 0.001f, 1)
  69. || test_normalize(a, 1, 1, 1, 0.002f, 2)
  70. || test_normalize(b, 1, 1, 0, 0.01f, 0)
  71. || test_normalize(b, 1, 1, 0, 0.001f, 1)
  72. || test_normalize(b, 1, 1, 0, 0.002f, 2)
  73. || test_normalize(b, 1, 1, 1, 0.01f, 0)
  74. || test_normalize(b, 1, 1, 1, 0.001f, 1)
  75. || test_normalize(b, 1, 1, 1, 0.002f, 2);
  76. }
  77. int main()
  78. {
  79. SRAND(7767517);
  80. return 0
  81. || test_normalize_0()
  82. || test_normalize_1()
  83. || test_normalize_2();
  84. }