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_deconvolutiondepthwise1d.cpp 7.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // Copyright 2022 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_deconvolutiondepthwise1d(int w, int h, int outh, int kernel, int dilation, int stride, int pad, int bias, int group, int output_pad_right, int output_w)
  5. {
  6. ncnn::Mat a = RandomMat(w, h);
  7. if (output_w > 0 && pad != -233 && pad != -234)
  8. {
  9. pad = -233;
  10. }
  11. ncnn::ParamDict pd;
  12. pd.set(0, outh);
  13. pd.set(1, kernel);
  14. pd.set(2, dilation);
  15. pd.set(3, stride);
  16. pd.set(4, pad);
  17. pd.set(5, bias);
  18. pd.set(6, outh / group * h / group * kernel * group);
  19. pd.set(7, group);
  20. int activation_type = RAND() % 5; // 0 1 2 3 4
  21. ncnn::Mat activation_params(2);
  22. activation_params[0] = RandomFloat(-1, 0); // alpha
  23. activation_params[1] = RandomFloat(0, 1); // beta
  24. pd.set(9, activation_type);
  25. pd.set(10, activation_params);
  26. pd.set(18, output_pad_right);
  27. pd.set(20, output_w);
  28. std::vector<ncnn::Mat> weights(2);
  29. weights[0] = RandomMat(outh / group * h / group * kernel * group);
  30. weights[1] = RandomMat(outh);
  31. int ret = test_layer("DeconvolutionDepthWise1D", pd, weights, a);
  32. if (ret != 0)
  33. {
  34. fprintf(stderr, "test_deconvolutiondepthwise1d failed w=%d h=%d outh=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d group=%d act=%d actparams=[%f,%f] output_pad_right=%d output_w=%d\n", w, h, outh, kernel, dilation, stride, pad, bias, group, activation_type, activation_params[0], activation_params[1], output_pad_right, output_w);
  35. }
  36. return ret;
  37. }
  38. static int test_deconvolutiondepthwise1d_0()
  39. {
  40. static const int kdsp[16][4] = {
  41. {1, 1, 1, 0},
  42. {1, 1, 2, 0},
  43. {2, 1, 1, 1},
  44. {2, 1, 2, -233},
  45. {3, 1, 1, 1},
  46. {3, 1, 2, 1},
  47. {3, 2, 1, 1},
  48. {4, 1, 1, -233},
  49. {4, 1, 2, -234},
  50. {4, 2, 1, -234},
  51. {5, 1, 1, 2},
  52. {5, 1, 2, 2},
  53. {5, 2, 2, 2},
  54. {7, 1, 1, 3},
  55. {7, 1, 2, 3},
  56. {7, 2, 1, -233},
  57. };
  58. for (int i = 0; i < 16; i++)
  59. {
  60. const int k = kdsp[i][0];
  61. const int d = kdsp[i][1];
  62. const int s = kdsp[i][2];
  63. const int p = kdsp[i][3];
  64. int ret = 0
  65. || test_deconvolutiondepthwise1d(15, 1, 1, k, d, s, p, 1, 1, 0, 0)
  66. || test_deconvolutiondepthwise1d(15, 2, 2, k, d, s, p, 0, 1, 1, 7)
  67. || test_deconvolutiondepthwise1d(15, 2, 2, k, d, s, p, 1, 2, 1, 0)
  68. || test_deconvolutiondepthwise1d(15, 3, 3, k, d, s, p, 0, 3, 0, 0)
  69. || test_deconvolutiondepthwise1d(15, 4, 2, k, d, s, p, 1, 2, 0, 7)
  70. || test_deconvolutiondepthwise1d(15, 4, 4, k, d, s, p, 0, 4, 2, 0)
  71. || test_deconvolutiondepthwise1d(15, 7, 7, k, d, s, p, 1, 7, 2, 0)
  72. || test_deconvolutiondepthwise1d(15, 8, 8, k, d, s, p, 0, 2, 0, 7)
  73. || test_deconvolutiondepthwise1d(15, 8, 8, k, d, s, p, 1, 8, 0, 0)
  74. || test_deconvolutiondepthwise1d(15, 12, 12, k, d, s, p, 0, 4, 3, 0)
  75. || test_deconvolutiondepthwise1d(15, 15, 15, k, d, s, p, 1, 15, 3, 7)
  76. || test_deconvolutiondepthwise1d(15, 16, 8, k, d, s, p, 0, 2, 0, 0)
  77. || test_deconvolutiondepthwise1d(15, 16, 16, k, d, s, p, 1, 16, 0, 0);
  78. if (ret != 0)
  79. return -1;
  80. }
  81. return 0;
  82. }
  83. static int test_deconvolutiondepthwise1d_dynamic(int w, int h, int outh, int kernel, int dilation, int stride, int pad, int bias, int group, int output_pad_right, int output_w)
  84. {
  85. ncnn::Mat a = RandomMat(w, h);
  86. if (output_w > 0 && pad != -233 && pad != -234)
  87. {
  88. pad = -233;
  89. }
  90. ncnn::ParamDict pd;
  91. pd.set(0, 0);
  92. pd.set(1, 0);
  93. pd.set(2, dilation);
  94. pd.set(3, stride);
  95. pd.set(4, pad);
  96. pd.set(5, bias);
  97. pd.set(6, 0);
  98. pd.set(7, group);
  99. pd.set(28, 1); // dynamic weight
  100. int activation_type = RAND() % 5; // 0 1 2 3 4
  101. ncnn::Mat activation_params(2);
  102. activation_params[0] = RandomFloat(-1, 0); // alpha
  103. activation_params[1] = RandomFloat(0, 1); // beta
  104. pd.set(9, activation_type);
  105. pd.set(10, activation_params);
  106. pd.set(18, output_pad_right);
  107. pd.set(20, output_w);
  108. std::vector<ncnn::Mat> as(bias ? 3 : 2);
  109. as[0] = a;
  110. as[1] = RandomMat(kernel, outh / group, h);
  111. if (bias)
  112. as[2] = RandomMat(outh);
  113. std::vector<ncnn::Mat> weights(0);
  114. int ret = test_layer("DeconvolutionDepthWise1D", pd, weights, as);
  115. if (ret != 0)
  116. {
  117. fprintf(stderr, "test_deconvolutiondepthwise1d_dynamic failed w=%d h=%d outh=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d group=%d act=%d actparams=[%f,%f] output_pad_right=%d output_w=%d\n", w, h, outh, kernel, dilation, stride, pad, bias, group, activation_type, activation_params[0], activation_params[1], output_pad_right, output_w);
  118. }
  119. return ret;
  120. }
  121. static int test_deconvolutiondepthwise1d_1()
  122. {
  123. static const int kdsp[16][4] = {
  124. {1, 1, 1, 0},
  125. {1, 1, 2, 0},
  126. {2, 1, 1, 1},
  127. {2, 1, 2, -233},
  128. {3, 1, 1, 1},
  129. {3, 1, 2, 1},
  130. {3, 2, 1, 1},
  131. {4, 1, 1, -233},
  132. {4, 1, 2, -234},
  133. {4, 2, 1, -234},
  134. {5, 1, 1, 2},
  135. {5, 1, 2, 2},
  136. {5, 2, 2, 2},
  137. {7, 1, 1, 3},
  138. {7, 1, 2, 3},
  139. {7, 2, 1, -233},
  140. };
  141. for (int i = 0; i < 16; i++)
  142. {
  143. const int k = kdsp[i][0];
  144. const int d = kdsp[i][1];
  145. const int s = kdsp[i][2];
  146. const int p = kdsp[i][3];
  147. int ret = 0
  148. || test_deconvolutiondepthwise1d_dynamic(15, 1, 1, k, d, s, p, 1, 1, 0, 0)
  149. || test_deconvolutiondepthwise1d_dynamic(15, 2, 2, k, d, s, p, 0, 1, 1, 7)
  150. || test_deconvolutiondepthwise1d_dynamic(15, 2, 2, k, d, s, p, 1, 2, 1, 0)
  151. || test_deconvolutiondepthwise1d_dynamic(15, 3, 3, k, d, s, p, 0, 3, 0, 0)
  152. || test_deconvolutiondepthwise1d_dynamic(15, 4, 2, k, d, s, p, 1, 2, 0, 7)
  153. || test_deconvolutiondepthwise1d_dynamic(15, 4, 4, k, d, s, p, 0, 4, 2, 0)
  154. || test_deconvolutiondepthwise1d_dynamic(15, 7, 7, k, d, s, p, 1, 7, 2, 0)
  155. || test_deconvolutiondepthwise1d_dynamic(15, 8, 8, k, d, s, p, 0, 2, 0, 7)
  156. || test_deconvolutiondepthwise1d_dynamic(15, 8, 8, k, d, s, p, 1, 8, 0, 0)
  157. || test_deconvolutiondepthwise1d_dynamic(15, 12, 12, k, d, s, p, 0, 4, 3, 0)
  158. || test_deconvolutiondepthwise1d_dynamic(15, 15, 15, k, d, s, p, 1, 15, 3, 7)
  159. || test_deconvolutiondepthwise1d_dynamic(15, 16, 8, k, d, s, p, 0, 2, 0, 0)
  160. || test_deconvolutiondepthwise1d_dynamic(15, 16, 16, k, d, s, p, 1, 16, 0, 0);
  161. if (ret != 0)
  162. return -1;
  163. }
  164. return 0;
  165. }
  166. int main()
  167. {
  168. SRAND(7767517);
  169. return test_deconvolutiondepthwise1d_0() || test_deconvolutiondepthwise1d_1();
  170. }