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_relu.cpp 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_relu(const ncnn::Mat& a, float slope)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, slope); //slope
  8. std::vector<ncnn::Mat> weights(0);
  9. int ret = test_layer("ReLU", pd, weights, a);
  10. if (ret != 0)
  11. {
  12. fprintf(stderr, "test_relu failed a.dims=%d a=(%d %d %d %d) slope=%f\n", a.dims, a.w, a.h, a.d, a.c, slope);
  13. }
  14. return ret;
  15. }
  16. static int test_relu_0()
  17. {
  18. return 0
  19. || test_relu(RandomMat(5, 6, 7, 24), 0.f)
  20. || test_relu(RandomMat(5, 6, 7, 24), 0.1f)
  21. || test_relu(RandomMat(7, 8, 9, 12), 0.f)
  22. || test_relu(RandomMat(7, 8, 9, 12), 0.1f)
  23. || test_relu(RandomMat(3, 4, 5, 13), 0.f)
  24. || test_relu(RandomMat(3, 4, 5, 13), 0.1f);
  25. }
  26. static int test_relu_1()
  27. {
  28. return 0
  29. || test_relu(RandomMat(5, 7, 24), 0.f)
  30. || test_relu(RandomMat(5, 7, 24), 0.1f)
  31. || test_relu(RandomMat(7, 9, 12), 0.f)
  32. || test_relu(RandomMat(7, 9, 12), 0.1f)
  33. || test_relu(RandomMat(3, 5, 13), 0.f)
  34. || test_relu(RandomMat(3, 5, 13), 0.1f);
  35. }
  36. static int test_relu_2()
  37. {
  38. return 0
  39. || test_relu(RandomMat(15, 24), 0.f)
  40. || test_relu(RandomMat(15, 24), 0.1f)
  41. || test_relu(RandomMat(17, 12), 0.f)
  42. || test_relu(RandomMat(17, 12), 0.1f)
  43. || test_relu(RandomMat(19, 15), 0.f)
  44. || test_relu(RandomMat(19, 15), 0.1f);
  45. }
  46. static int test_relu_3()
  47. {
  48. return 0
  49. || test_relu(RandomMat(128), 0.f)
  50. || test_relu(RandomMat(128), 0.1f)
  51. || test_relu(RandomMat(124), 0.f)
  52. || test_relu(RandomMat(124), 0.1f)
  53. || test_relu(RandomMat(127), 0.f)
  54. || test_relu(RandomMat(127), 0.1f);
  55. }
  56. int main()
  57. {
  58. SRAND(7767517);
  59. return 0
  60. || test_relu_0()
  61. || test_relu_1()
  62. || test_relu_2()
  63. || test_relu_3();
  64. }