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_dequantize.cpp 6.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright 2021 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_dequantize(const ncnn::Mat& a, int scale_data_size, int bias_data_size)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, scale_data_size);
  8. pd.set(1, bias_data_size);
  9. std::vector<ncnn::Mat> weights(bias_data_size ? 2 : 1);
  10. weights[0] = RandomMat(scale_data_size);
  11. if (bias_data_size)
  12. weights[1] = RandomMat(bias_data_size);
  13. int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING;
  14. int ret = test_layer("Dequantize", pd, weights, a, 0.001, 0, flag);
  15. if (ret != 0)
  16. {
  17. fprintf(stderr, "test_dequantize failed a.dims=%d a=(%d %d %d) scale_data_size=%d bias_data_size=%d\n", a.dims, a.w, a.h, a.c, scale_data_size, bias_data_size);
  18. }
  19. return ret;
  20. }
  21. static int test_dequantize_pack8(const ncnn::Mat& a, int scale_data_size, int bias_data_size)
  22. {
  23. ncnn::ParamDict pd;
  24. pd.set(0, scale_data_size);
  25. pd.set(1, bias_data_size);
  26. std::vector<ncnn::Mat> weights(bias_data_size ? 2 : 1);
  27. weights[0] = RandomMat(scale_data_size);
  28. if (bias_data_size)
  29. weights[1] = RandomMat(bias_data_size);
  30. int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING | TEST_LAYER_ENABLE_FORCE_INPUT_PACK8;
  31. int ret = test_layer("Dequantize", pd, weights, a, 0.001, 0, flag);
  32. if (ret != 0)
  33. {
  34. fprintf(stderr, "test_dequantize_pack8 failed a.dims=%d a=(%d %d %d) scale_data_size=%d bias_data_size=%d\n", a.dims, a.w, a.h, a.c, scale_data_size, bias_data_size);
  35. }
  36. return ret;
  37. }
  38. static int test_dequantize_0()
  39. {
  40. return 0
  41. || test_dequantize(RandomIntMat(11, 13, 48), 1, 48)
  42. || test_dequantize(RandomIntMat(11, 13, 48), 1, 1)
  43. || test_dequantize(RandomIntMat(11, 13, 48), 1, 0)
  44. || test_dequantize(RandomIntMat(11, 13, 48), 48, 48)
  45. || test_dequantize(RandomIntMat(11, 13, 48), 48, 1)
  46. || test_dequantize(RandomIntMat(11, 13, 48), 48, 0)
  47. || test_dequantize(RandomIntMat(5, 7, 24), 1, 24)
  48. || test_dequantize(RandomIntMat(5, 7, 24), 1, 1)
  49. || test_dequantize(RandomIntMat(5, 7, 24), 1, 0)
  50. || test_dequantize(RandomIntMat(5, 7, 24), 24, 24)
  51. || test_dequantize(RandomIntMat(5, 7, 24), 24, 1)
  52. || test_dequantize(RandomIntMat(5, 7, 24), 24, 0)
  53. || test_dequantize(RandomIntMat(7, 9, 12), 1, 12)
  54. || test_dequantize(RandomIntMat(7, 9, 12), 1, 1)
  55. || test_dequantize(RandomIntMat(7, 9, 12), 1, 0)
  56. || test_dequantize(RandomIntMat(7, 9, 12), 12, 12)
  57. || test_dequantize(RandomIntMat(7, 9, 12), 12, 1)
  58. || test_dequantize(RandomIntMat(7, 9, 12), 12, 0)
  59. || test_dequantize(RandomIntMat(3, 5, 13), 1, 13)
  60. || test_dequantize(RandomIntMat(3, 5, 13), 1, 1)
  61. || test_dequantize(RandomIntMat(3, 5, 13), 1, 0)
  62. || test_dequantize(RandomIntMat(3, 5, 13), 13, 13)
  63. || test_dequantize(RandomIntMat(3, 5, 13), 13, 1)
  64. || test_dequantize(RandomIntMat(3, 5, 13), 13, 0);
  65. }
  66. static int test_dequantize_1()
  67. {
  68. return 0
  69. || test_dequantize(RandomIntMat(127, 48), 1, 48)
  70. || test_dequantize(RandomIntMat(127, 48), 1, 1)
  71. || test_dequantize(RandomIntMat(127, 48), 1, 0)
  72. || test_dequantize(RandomIntMat(127, 48), 48, 48)
  73. || test_dequantize(RandomIntMat(127, 48), 48, 1)
  74. || test_dequantize(RandomIntMat(127, 48), 48, 0)
  75. || test_dequantize(RandomIntMat(15, 24), 1, 24)
  76. || test_dequantize(RandomIntMat(15, 24), 1, 1)
  77. || test_dequantize(RandomIntMat(15, 24), 1, 0)
  78. || test_dequantize(RandomIntMat(15, 24), 24, 24)
  79. || test_dequantize(RandomIntMat(15, 24), 24, 1)
  80. || test_dequantize(RandomIntMat(15, 24), 24, 0)
  81. || test_dequantize(RandomIntMat(17, 12), 1, 12)
  82. || test_dequantize(RandomIntMat(17, 12), 1, 1)
  83. || test_dequantize(RandomIntMat(17, 12), 1, 0)
  84. || test_dequantize(RandomIntMat(17, 12), 12, 12)
  85. || test_dequantize(RandomIntMat(17, 12), 12, 1)
  86. || test_dequantize(RandomIntMat(17, 12), 12, 0)
  87. || test_dequantize(RandomIntMat(19, 15), 1, 15)
  88. || test_dequantize(RandomIntMat(19, 15), 1, 1)
  89. || test_dequantize(RandomIntMat(19, 15), 1, 0)
  90. || test_dequantize(RandomIntMat(19, 15), 15, 15)
  91. || test_dequantize(RandomIntMat(19, 15), 15, 1)
  92. || test_dequantize(RandomIntMat(19, 15), 15, 0);
  93. }
  94. static int test_dequantize_2()
  95. {
  96. return 0
  97. || test_dequantize(RandomIntMat(128), 1, 1)
  98. || test_dequantize(RandomIntMat(128), 1, 0)
  99. || test_dequantize(RandomIntMat(120), 1, 1)
  100. || test_dequantize(RandomIntMat(120), 1, 0)
  101. || test_dequantize(RandomIntMat(124), 1, 1)
  102. || test_dequantize(RandomIntMat(124), 1, 0)
  103. || test_dequantize(RandomIntMat(127), 1, 1)
  104. || test_dequantize(RandomIntMat(127), 1, 0);
  105. }
  106. static int test_dequantize_3()
  107. {
  108. return 0
  109. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 1, 24)
  110. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 1, 1)
  111. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 1, 0)
  112. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 24, 24)
  113. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 24, 1)
  114. || test_dequantize_pack8(RandomIntMat(5, 7, 24), 24, 0)
  115. || test_dequantize_pack8(RandomIntMat(15, 24), 1, 24)
  116. || test_dequantize_pack8(RandomIntMat(15, 24), 1, 1)
  117. || test_dequantize_pack8(RandomIntMat(15, 24), 1, 0)
  118. || test_dequantize_pack8(RandomIntMat(15, 24), 24, 24)
  119. || test_dequantize_pack8(RandomIntMat(15, 24), 24, 1)
  120. || test_dequantize_pack8(RandomIntMat(15, 24), 24, 0)
  121. || test_dequantize_pack8(RandomIntMat(128), 1, 1)
  122. || test_dequantize_pack8(RandomIntMat(128), 1, 0);
  123. }
  124. int main()
  125. {
  126. SRAND(7767517);
  127. return 0
  128. || test_dequantize_0()
  129. || test_dequantize_1()
  130. || test_dequantize_2()
  131. || test_dequantize_3();
  132. }