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.4 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "layer/softmax.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. ncnn::Option opt;
  23. opt.num_threads = 1;
  24. opt.use_vulkan_compute = true;
  25. opt.use_int8_inference = false;
  26. int ret = test_layer<ncnn::Softmax>("Softmax", pd, weights, opt, a);
  27. if (ret != 0)
  28. {
  29. fprintf(stderr, "test_softmax failed a.dims=%d a=(%d %d %d) axis=%d\n", a.dims, a.w, a.h, a.c, axis);
  30. }
  31. return ret;
  32. }
  33. static int test_softmax_0()
  34. {
  35. ncnn::Mat a = RandomMat(6, 7, 16);
  36. return 0
  37. || test_softmax(a, 0)
  38. || test_softmax(a, 1)
  39. || test_softmax(a, 2)
  40. ;
  41. }
  42. static int test_softmax_1()
  43. {
  44. ncnn::Mat a = RandomMat(3, 5, 13);
  45. return 0
  46. || test_softmax(a, 0)
  47. || test_softmax(a, 1)
  48. || test_softmax(a, 2)
  49. ;
  50. }
  51. static int test_softmax_2()
  52. {
  53. ncnn::Mat a = RandomMat(6, 16);
  54. return 0
  55. || test_softmax(a, 0)
  56. || test_softmax(a, 1)
  57. ;
  58. }
  59. static int test_softmax_3()
  60. {
  61. ncnn::Mat a = RandomMat(7, 15);
  62. return 0
  63. || test_softmax(a, 0)
  64. || test_softmax(a, 1)
  65. ;
  66. }
  67. static int test_softmax_4()
  68. {
  69. ncnn::Mat a = RandomMat(128);
  70. return test_softmax(a, 0);
  71. }
  72. static int test_softmax_5()
  73. {
  74. ncnn::Mat a = RandomMat(127);
  75. return test_softmax(a, 0);
  76. }
  77. int main()
  78. {
  79. SRAND(7767517);
  80. return 0
  81. || test_softmax_0()
  82. || test_softmax_1()
  83. || test_softmax_2()
  84. || test_softmax_3()
  85. || test_softmax_4()
  86. || test_softmax_5()
  87. ;
  88. }