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_relu.cpp 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2019 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/relu.h"
  15. #include "testutil.h"
  16. static int test_relu(const ncnn::Mat& a, float slope)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, slope); //slope
  20. std::vector<ncnn::Mat> weights(0);
  21. int ret = test_layer<ncnn::ReLU>("ReLU", pd, weights, a);
  22. if (ret != 0)
  23. {
  24. fprintf(stderr, "test_relu failed a.dims=%d a=(%d %d %d) slope=%f\n", a.dims, a.w, a.h, a.c, slope);
  25. }
  26. return ret;
  27. }
  28. static int test_relu_0()
  29. {
  30. return 0
  31. || test_relu(RandomMat(5, 7, 16), 0.f)
  32. || test_relu(RandomMat(5, 7, 16), 0.1f)
  33. || test_relu(RandomMat(3, 5, 13), 0.f)
  34. || test_relu(RandomMat(3, 5, 13), 0.1f);
  35. }
  36. static int test_relu_1()
  37. {
  38. return 0
  39. || test_relu(RandomMat(6, 16), 0.f)
  40. || test_relu(RandomMat(6, 16), 0.1f)
  41. || test_relu(RandomMat(7, 15), 0.f)
  42. || test_relu(RandomMat(7, 15), 0.1f);
  43. }
  44. static int test_relu_2()
  45. {
  46. return 0
  47. || test_relu(RandomMat(128), 0.f)
  48. || test_relu(RandomMat(128), 0.1f)
  49. || test_relu(RandomMat(127), 0.f)
  50. || test_relu(RandomMat(127), 0.1f);
  51. }
  52. int main()
  53. {
  54. SRAND(7767517);
  55. return 0
  56. || test_relu_0()
  57. || test_relu_1()
  58. || test_relu_2();
  59. }