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_lrn.cpp 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_lrn(const ncnn::Mat& a, int region_type, int local_size, float alpha, float beta, float bias)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, region_type);
  8. pd.set(1, local_size);
  9. pd.set(2, alpha);
  10. pd.set(3, beta);
  11. pd.set(4, bias);
  12. std::vector<ncnn::Mat> weights(0);
  13. int ret = test_layer("LRN", pd, weights, a);
  14. if (ret != 0)
  15. {
  16. fprintf(stderr, "test_lrn failed a.dims=%d a=(%d %d %d) region_type=%d local_size=%d alpha=%f beta=%f bias=%f\n", a.dims, a.w, a.h, a.c, region_type, local_size, alpha, beta, bias);
  17. }
  18. return ret;
  19. }
  20. static int test_lrn_0()
  21. {
  22. ncnn::Mat a = RandomMat(11, 7, 12);
  23. return 0
  24. || test_lrn(a, 0, 1, 1.f, 0.75f, 1.f)
  25. || test_lrn(a, 0, 5, 2.f, 0.12f, 1.33f)
  26. || test_lrn(a, 1, 1, 0.6f, 0.4f, 2.4f)
  27. || test_lrn(a, 1, 3, 1.f, 0.75f, 0.5f);
  28. }
  29. static int test_lrn_1()
  30. {
  31. ncnn::Mat a = RandomMat(10, 8, 16);
  32. return 0
  33. || test_lrn(a, 0, 1, 1.f, 0.75f, 1.f)
  34. || test_lrn(a, 0, 5, 2.f, 0.12f, 1.33f)
  35. || test_lrn(a, 1, 1, 0.6f, 0.4f, 2.4f)
  36. || test_lrn(a, 1, 3, 1.f, 0.75f, 0.5f);
  37. }
  38. static int test_lrn_2()
  39. {
  40. ncnn::Mat a = RandomMat(12, 10, 9);
  41. return 0
  42. || test_lrn(a, 0, 1, 1.f, 0.75f, 1.f)
  43. || test_lrn(a, 0, 5, 2.f, 0.12f, 1.33f)
  44. || test_lrn(a, 1, 1, 0.6f, 0.4f, 2.4f)
  45. || test_lrn(a, 1, 3, 1.f, 0.75f, 0.5f);
  46. }
  47. int main()
  48. {
  49. SRAND(7767517);
  50. return 0
  51. || test_lrn_0()
  52. || test_lrn_1()
  53. || test_lrn_2();
  54. }