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 3.0 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
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "testutil.h"
  15. static int test_softmax(const ncnn::Mat& a, int axis)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, axis); // axis
  19. pd.set(1, 1); // fixbug0
  20. std::vector<ncnn::Mat> weights(0);
  21. int ret = test_layer("Softmax", pd, weights, a);
  22. if (ret != 0)
  23. {
  24. fprintf(stderr, "test_softmax failed a.dims=%d a=(%d %d %d) axis=%d\n", a.dims, a.w, a.h, a.c, axis);
  25. }
  26. return ret;
  27. }
  28. static int test_softmax_0()
  29. {
  30. ncnn::Mat a = RandomMat(25, 27, 32);
  31. ncnn::Mat b = RandomMat(27, 29, 28);
  32. ncnn::Mat c = RandomMat(23, 25, 27);
  33. return 0
  34. || test_softmax(a, 0)
  35. || test_softmax(a, 1)
  36. || test_softmax(a, 2)
  37. || test_softmax(a, -1)
  38. || test_softmax(a, -2)
  39. || test_softmax(a, -3)
  40. || test_softmax(b, 0)
  41. || test_softmax(b, 1)
  42. || test_softmax(b, 2)
  43. || test_softmax(b, -1)
  44. || test_softmax(b, -2)
  45. || test_softmax(b, -3)
  46. || test_softmax(c, 0)
  47. || test_softmax(c, 1)
  48. || test_softmax(c, 2)
  49. || test_softmax(c, -1)
  50. || test_softmax(c, -2)
  51. || test_softmax(c, -3);
  52. }
  53. static int test_softmax_1()
  54. {
  55. ncnn::Mat a = RandomMat(25, 32);
  56. ncnn::Mat b = RandomMat(27, 28);
  57. ncnn::Mat c = RandomMat(29, 27);
  58. return 0
  59. || test_softmax(a, 0)
  60. || test_softmax(a, 1)
  61. || test_softmax(a, -1)
  62. || test_softmax(a, -2)
  63. || test_softmax(b, 0)
  64. || test_softmax(b, 1)
  65. || test_softmax(b, -1)
  66. || test_softmax(b, -2)
  67. || test_softmax(c, 0)
  68. || test_softmax(c, 1)
  69. || test_softmax(c, -1)
  70. || test_softmax(c, -2);
  71. }
  72. static int test_softmax_2()
  73. {
  74. ncnn::Mat a = RandomMat(128);
  75. ncnn::Mat b = RandomMat(124);
  76. ncnn::Mat c = RandomMat(127);
  77. return 0
  78. || test_softmax(a, 0)
  79. || test_softmax(a, -1)
  80. || test_softmax(b, 0)
  81. || test_softmax(b, -1)
  82. || test_softmax(c, 0)
  83. || test_softmax(c, -1);
  84. }
  85. int main()
  86. {
  87. SRAND(7767517);
  88. return 0
  89. || test_softmax_0()
  90. || test_softmax_1()
  91. || test_softmax_2();
  92. }