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_softmax.cpp 2.3 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_softmax(const ncnn::Mat& a, int axis)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, axis); // axis
  8. pd.set(1, 1); // fixbug0
  9. std::vector<ncnn::Mat> weights(0);
  10. int ret = test_layer("Softmax", pd, weights, a);
  11. if (ret != 0)
  12. {
  13. fprintf(stderr, "test_softmax failed a.dims=%d a=(%d %d %d %d) axis=%d\n", a.dims, a.w, a.h, a.d, a.c, axis);
  14. }
  15. return ret;
  16. }
  17. static int test_softmax_nd(const ncnn::Mat& m)
  18. {
  19. const int dims = m.dims;
  20. for (int i = -dims; i < dims; i++)
  21. {
  22. int ret = test_softmax(m, i);
  23. if (ret != 0)
  24. return ret;
  25. }
  26. return 0;
  27. }
  28. static int test_softmax_0()
  29. {
  30. ncnn::Mat a = RandomMat(23, 25, 27, 32);
  31. ncnn::Mat b = RandomMat(21, 22, 19, 40);
  32. ncnn::Mat c = RandomMat(24, 27, 29, 28);
  33. ncnn::Mat d = RandomMat(25, 23, 25, 31);
  34. return 0
  35. || test_softmax_nd(a)
  36. || test_softmax_nd(b)
  37. || test_softmax_nd(c)
  38. || test_softmax_nd(d);
  39. }
  40. static int test_softmax_1()
  41. {
  42. ncnn::Mat a = RandomMat(25, 27, 32);
  43. ncnn::Mat b = RandomMat(22, 19, 40);
  44. ncnn::Mat c = RandomMat(27, 29, 28);
  45. ncnn::Mat d = RandomMat(23, 25, 31);
  46. return 0
  47. || test_softmax_nd(a)
  48. || test_softmax_nd(b)
  49. || test_softmax_nd(c)
  50. || test_softmax_nd(d);
  51. }
  52. static int test_softmax_2()
  53. {
  54. ncnn::Mat a = RandomMat(125, 32);
  55. ncnn::Mat b = RandomMat(147, 40);
  56. ncnn::Mat c = RandomMat(127, 28);
  57. ncnn::Mat d = RandomMat(129, 31);
  58. return 0
  59. || test_softmax_nd(a)
  60. || test_softmax_nd(b)
  61. || test_softmax_nd(c)
  62. || test_softmax_nd(d);
  63. }
  64. static int test_softmax_3()
  65. {
  66. ncnn::Mat a = RandomMat(128);
  67. ncnn::Mat b = RandomMat(120);
  68. ncnn::Mat c = RandomMat(124);
  69. ncnn::Mat d = RandomMat(127);
  70. return 0
  71. || test_softmax_nd(a)
  72. || test_softmax_nd(b)
  73. || test_softmax_nd(c)
  74. || test_softmax_nd(d);
  75. }
  76. int main()
  77. {
  78. SRAND(7767517);
  79. return 0
  80. || test_softmax_0()
  81. || test_softmax_1()
  82. || test_softmax_2()
  83. || test_softmax_3();
  84. }