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 5.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2021 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. static int test_dequantize(const ncnn::Mat& a, int scale_data_size, int bias_data_size)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, scale_data_size);
  19. pd.set(1, bias_data_size);
  20. std::vector<ncnn::Mat> weights(bias_data_size ? 2 : 1);
  21. weights[0] = RandomMat(scale_data_size);
  22. if (bias_data_size)
  23. weights[1] = RandomMat(bias_data_size);
  24. int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING;
  25. int ret = test_layer("Dequantize", pd, weights, a, 0.001, 0, flag);
  26. if (ret != 0)
  27. {
  28. 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);
  29. }
  30. return ret;
  31. }
  32. static int test_dequantize_0()
  33. {
  34. return 0
  35. || test_dequantize(RandomIntMat(11, 13, 48), 1, 48)
  36. || test_dequantize(RandomIntMat(11, 13, 48), 1, 1)
  37. || test_dequantize(RandomIntMat(11, 13, 48), 1, 0)
  38. || test_dequantize(RandomIntMat(11, 13, 48), 48, 48)
  39. || test_dequantize(RandomIntMat(11, 13, 48), 48, 1)
  40. || test_dequantize(RandomIntMat(11, 13, 48), 48, 0)
  41. || test_dequantize(RandomIntMat(5, 7, 24), 1, 24)
  42. || test_dequantize(RandomIntMat(5, 7, 24), 1, 1)
  43. || test_dequantize(RandomIntMat(5, 7, 24), 1, 0)
  44. || test_dequantize(RandomIntMat(5, 7, 24), 24, 24)
  45. || test_dequantize(RandomIntMat(5, 7, 24), 24, 1)
  46. || test_dequantize(RandomIntMat(5, 7, 24), 24, 0)
  47. || test_dequantize(RandomIntMat(7, 9, 12), 1, 12)
  48. || test_dequantize(RandomIntMat(7, 9, 12), 1, 1)
  49. || test_dequantize(RandomIntMat(7, 9, 12), 1, 0)
  50. || test_dequantize(RandomIntMat(7, 9, 12), 12, 12)
  51. || test_dequantize(RandomIntMat(7, 9, 12), 12, 1)
  52. || test_dequantize(RandomIntMat(7, 9, 12), 12, 0)
  53. || test_dequantize(RandomIntMat(3, 5, 13), 1, 13)
  54. || test_dequantize(RandomIntMat(3, 5, 13), 1, 1)
  55. || test_dequantize(RandomIntMat(3, 5, 13), 1, 0)
  56. || test_dequantize(RandomIntMat(3, 5, 13), 13, 13)
  57. || test_dequantize(RandomIntMat(3, 5, 13), 13, 1)
  58. || test_dequantize(RandomIntMat(3, 5, 13), 13, 0);
  59. }
  60. static int test_dequantize_1()
  61. {
  62. return 0
  63. || test_dequantize(RandomIntMat(127, 48), 1, 48)
  64. || test_dequantize(RandomIntMat(127, 48), 1, 1)
  65. || test_dequantize(RandomIntMat(127, 48), 1, 0)
  66. || test_dequantize(RandomIntMat(127, 48), 48, 48)
  67. || test_dequantize(RandomIntMat(127, 48), 48, 1)
  68. || test_dequantize(RandomIntMat(127, 48), 48, 0)
  69. || test_dequantize(RandomIntMat(15, 24), 1, 24)
  70. || test_dequantize(RandomIntMat(15, 24), 1, 1)
  71. || test_dequantize(RandomIntMat(15, 24), 1, 0)
  72. || test_dequantize(RandomIntMat(15, 24), 24, 24)
  73. || test_dequantize(RandomIntMat(15, 24), 24, 1)
  74. || test_dequantize(RandomIntMat(15, 24), 24, 0)
  75. || test_dequantize(RandomIntMat(17, 12), 1, 12)
  76. || test_dequantize(RandomIntMat(17, 12), 1, 1)
  77. || test_dequantize(RandomIntMat(17, 12), 1, 0)
  78. || test_dequantize(RandomIntMat(17, 12), 12, 12)
  79. || test_dequantize(RandomIntMat(17, 12), 12, 1)
  80. || test_dequantize(RandomIntMat(17, 12), 12, 0)
  81. || test_dequantize(RandomIntMat(19, 15), 1, 15)
  82. || test_dequantize(RandomIntMat(19, 15), 1, 1)
  83. || test_dequantize(RandomIntMat(19, 15), 1, 0)
  84. || test_dequantize(RandomIntMat(19, 15), 15, 15)
  85. || test_dequantize(RandomIntMat(19, 15), 15, 1)
  86. || test_dequantize(RandomIntMat(19, 15), 15, 0);
  87. }
  88. static int test_dequantize_2()
  89. {
  90. return 0
  91. || test_dequantize(RandomIntMat(128), 1, 1)
  92. || test_dequantize(RandomIntMat(128), 1, 0)
  93. || test_dequantize(RandomIntMat(120), 1, 1)
  94. || test_dequantize(RandomIntMat(120), 1, 0)
  95. || test_dequantize(RandomIntMat(124), 1, 1)
  96. || test_dequantize(RandomIntMat(124), 1, 0)
  97. || test_dequantize(RandomIntMat(127), 1, 1)
  98. || test_dequantize(RandomIntMat(127), 1, 0);
  99. }
  100. int main()
  101. {
  102. SRAND(7767517);
  103. return 0
  104. || test_dequantize_0()
  105. || test_dequantize_1()
  106. || test_dequantize_2();
  107. }