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