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_deconvolution3d.cpp 3.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2022 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_deconvolution3d(int w, int h, int d, int c, int outch, int kernel, int dilation, int stride, int pad, int bias, int output_pad_right, int output_pad_bottom, int output_pad_behind, int output_w, int output_h, int output_d)
  5. {
  6. ncnn::Mat a = RandomMat(w, h, d, c);
  7. if (output_w > 0 && output_h > 0 && output_d > 0 && pad != -233 && pad != -234)
  8. {
  9. pad = -233;
  10. }
  11. ncnn::ParamDict pd;
  12. pd.set(0, outch);
  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, outch * c * kernel * kernel * kernel);
  19. int activation_type = RAND() % 5; // 0 1 2 3 4
  20. ncnn::Mat activation_params(2);
  21. activation_params[0] = RandomFloat(-1, 0); // alpha
  22. activation_params[1] = RandomFloat(0, 1); // beta
  23. pd.set(9, activation_type);
  24. pd.set(10, activation_params);
  25. pd.set(18, output_pad_right);
  26. pd.set(19, output_pad_bottom);
  27. pd.set(20, output_pad_behind);
  28. pd.set(25, output_w);
  29. pd.set(26, output_h);
  30. pd.set(27, output_d);
  31. std::vector<ncnn::Mat> weights(2);
  32. weights[0] = RandomMat(outch * c * kernel * kernel * kernel);
  33. weights[1] = RandomMat(outch);
  34. int ret = test_layer("Deconvolution3D", pd, weights, a);
  35. if (ret != 0)
  36. {
  37. fprintf(stderr, "test_deconvolution3d failed w=%d h=%d d=%d c=%d outch=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d act=%d actparams=[%f,%f] output_pad_right=%d output_pad_bottom=%d output_pad_behind=%d output_w=%d output_h=%d output_d=%d\n", w, h, d, c, outch, kernel, dilation, stride, pad, bias, activation_type, activation_params[0], activation_params[1], output_pad_right, output_pad_bottom, output_pad_behind, output_w, output_h, output_d);
  38. }
  39. return ret;
  40. }
  41. static int test_deconvolution3d_0()
  42. {
  43. static const int kdsp[7][4] = {
  44. {1, 1, 1, 0},
  45. {1, 1, 2, 0},
  46. {2, 1, 1, 1},
  47. {2, 1, 2, -233},
  48. {3, 1, 1, 1},
  49. {3, 1, 2, 1},
  50. {3, 2, 1, -234},
  51. };
  52. for (int i = 0; i < 7; i++)
  53. {
  54. const int k = kdsp[i][0];
  55. const int d = kdsp[i][1];
  56. const int s = kdsp[i][2];
  57. const int p = kdsp[i][3];
  58. int ret = 0
  59. || test_deconvolution3d(9, 8, 7, 1, 1, k, d, s, p, 1, 0, 0, 0, 0, 0, 0)
  60. || test_deconvolution3d(9, 8, 7, 4, 13, k, d, s, p, 0, 1, 1, 1, 7, 6, 5)
  61. || test_deconvolution3d(9, 8, 7, 13, 4, k, d, s, p, 1, 1, 0, 0, 0, 0, 0)
  62. || test_deconvolution3d(9, 8, 7, 4, 8, k, d, s, p, 0, 0, 1, 0, 0, 0, 0)
  63. || test_deconvolution3d(9, 8, 7, 8, 4, k, d, s, p, 1, 0, 0, 0, 7, 6, 5)
  64. || test_deconvolution3d(9, 8, 7, 8, 13, k, d, s, p, 0, 2, 2, 2, 0, 0, 0)
  65. || test_deconvolution3d(9, 8, 7, 13, 8, k, d, s, p, 1, 2, 0, 2, 0, 0, 0)
  66. || test_deconvolution3d(9, 8, 7, 16, 16, k, d, s, p, 0, 0, 2, 0, 7, 6, 5);
  67. if (ret != 0)
  68. return -1;
  69. }
  70. return 0;
  71. }
  72. int main()
  73. {
  74. SRAND(7767517);
  75. return test_deconvolution3d_0();
  76. }