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.3 kB

6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, bool use_packing_layout)
  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::ModelBinFromMatArray mb(weights.data());
  23. ncnn::Option opt;
  24. opt.num_threads = 1;
  25. opt.use_vulkan_compute = true;
  26. opt.use_int8_inference = false;
  27. opt.use_fp16_packed = false;
  28. opt.use_fp16_storage = false;
  29. opt.use_fp16_arithmetic = false;
  30. opt.use_int8_storage = false;
  31. opt.use_int8_arithmetic = false;
  32. opt.use_packing_layout = use_packing_layout;
  33. int ret = test_layer<ncnn::Softmax>("Softmax", pd, mb, opt, a);
  34. if (ret != 0)
  35. {
  36. fprintf(stderr, "test_softmax failed a.dims=%d a=(%d %d %d) axis=%d use_packing_layout=%d\n", a.dims, a.w, a.h, a.c, axis, use_packing_layout);
  37. }
  38. return ret;
  39. }
  40. static int test_softmax_0()
  41. {
  42. ncnn::Mat a = RandomMat(6, 7, 16);
  43. return 0
  44. || test_softmax(a, 0, false)
  45. || test_softmax(a, 1, false)
  46. || test_softmax(a, 2, false)
  47. || test_softmax(a, 0, true)
  48. || test_softmax(a, 1, true)
  49. || test_softmax(a, 2, true)
  50. ;
  51. }
  52. static int test_softmax_1()
  53. {
  54. ncnn::Mat a = RandomMat(3, 5, 13);
  55. return 0
  56. || test_softmax(a, 0, false)
  57. || test_softmax(a, 1, false)
  58. || test_softmax(a, 2, false)
  59. || test_softmax(a, 0, true)
  60. || test_softmax(a, 1, true)
  61. || test_softmax(a, 2, true)
  62. ;
  63. }
  64. static int test_softmax_2()
  65. {
  66. ncnn::Mat a = RandomMat(6, 16);
  67. return 0
  68. || test_softmax(a, 0, false)
  69. || test_softmax(a, 1, false)
  70. || test_softmax(a, 0, true)
  71. || test_softmax(a, 1, true)
  72. ;
  73. }
  74. static int test_softmax_3()
  75. {
  76. ncnn::Mat a = RandomMat(7, 15);
  77. return 0
  78. || test_softmax(a, 0, false)
  79. || test_softmax(a, 1, false)
  80. || test_softmax(a, 0, true)
  81. || test_softmax(a, 1, true)
  82. ;
  83. }
  84. static int test_softmax_4()
  85. {
  86. ncnn::Mat a = RandomMat(128);
  87. return 0
  88. || test_softmax(a, 0, false)
  89. || test_softmax(a, 0, true)
  90. ;
  91. }
  92. static int test_softmax_5()
  93. {
  94. ncnn::Mat a = RandomMat(127);
  95. return 0
  96. || test_softmax(a, 0, false)
  97. || test_softmax(a, 0, true)
  98. ;
  99. }
  100. int main()
  101. {
  102. SRAND(7767517);
  103. return 0
  104. || test_softmax_0()
  105. || test_softmax_1()
  106. || test_softmax_2()
  107. || test_softmax_3()
  108. || test_softmax_4()
  109. || test_softmax_5()
  110. ;
  111. }