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_quantize_oom.cpp 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2021 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_quantize_oom(const ncnn::Mat& a, float scale_low, float scale_high)
  5. {
  6. ncnn::Mat scale_data;
  7. if (scale_low == scale_high)
  8. {
  9. scale_data.create(1);
  10. scale_data[0] = scale_low;
  11. }
  12. else
  13. {
  14. if (a.dims == 1) scale_data.create(1);
  15. if (a.dims == 2) scale_data.create(a.h);
  16. if (a.dims == 3) scale_data.create(a.c);
  17. Randomize(scale_data, scale_low, scale_high);
  18. }
  19. ncnn::ParamDict pd;
  20. pd.set(0, scale_data.w);
  21. std::vector<ncnn::Mat> weights(1);
  22. weights[0] = scale_data;
  23. int ret = test_layer_oom("Quantize", pd, weights, a);
  24. if (ret != 0)
  25. {
  26. fprintf(stderr, "test_quantize_oom failed a.dims=%d a=(%d %d %d) scale_low=%f scale_high=%f\n", a.dims, a.w, a.h, a.c, scale_low, scale_high);
  27. }
  28. return ret;
  29. }
  30. static int test_quantize_0()
  31. {
  32. return 0
  33. || test_quantize_oom(RandomMat(5, 7, 24), 100.f, 100.f)
  34. || test_quantize_oom(RandomMat(7, 9, 12), 100.f, 100.f)
  35. || test_quantize_oom(RandomMat(3, 5, 13), 100.f, 100.f);
  36. }
  37. static int test_quantize_1()
  38. {
  39. return 0
  40. || test_quantize_oom(RandomMat(15, 24), 100.f, 100.f)
  41. || test_quantize_oom(RandomMat(17, 12), 100.f, 100.f)
  42. || test_quantize_oom(RandomMat(19, 15), 100.f, 100.f);
  43. }
  44. static int test_quantize_2()
  45. {
  46. return 0
  47. || test_quantize_oom(RandomMat(128), 120.f, 140.f)
  48. || test_quantize_oom(RandomMat(124), 120.f, 140.f)
  49. || test_quantize_oom(RandomMat(127), 120.f, 140.f);
  50. }
  51. int main()
  52. {
  53. SRAND(7767517);
  54. return 0
  55. || test_quantize_0()
  56. || test_quantize_1()
  57. || test_quantize_2();
  58. }