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_deformableconv2d_4.cpp 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2019 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_deformableconv2d(int w, int h, int c, int outch, int kernel, int dilation, int stride, int pad, int bias)
  5. {
  6. const int kernel_extent_w = dilation * (kernel - 1) + 1;
  7. const int kernel_extent_h = dilation * (kernel - 1) + 1;
  8. const int out_w = (w + pad + pad - kernel_extent_w) / stride + 1;
  9. const int out_h = (h + pad + pad - kernel_extent_h) / stride + 1;
  10. std::vector<ncnn::Mat> a(3);
  11. a[0] = RandomMat(w, h, c);
  12. a[1] = RandomMat(out_w, out_h, kernel * kernel * 2);
  13. a[2] = RandomMat(out_w, out_h, kernel * kernel);
  14. ncnn::ParamDict pd;
  15. pd.set(0, outch);
  16. pd.set(1, kernel);
  17. pd.set(2, dilation);
  18. pd.set(3, stride);
  19. pd.set(4, pad);
  20. pd.set(5, bias);
  21. pd.set(6, outch * c * kernel * kernel);
  22. int activation_type = RAND() % 7; // 0 1 2 3 4 5 6
  23. ncnn::Mat activation_params(2);
  24. activation_params[0] = (activation_type == 6) ? RandomFloat(0, 1) : RandomFloat(-1, 0); // alpha
  25. activation_params[1] = RandomFloat(0, 1); // beta
  26. pd.set(9, activation_type);
  27. pd.set(10, activation_params);
  28. std::vector<ncnn::Mat> weights(bias ? 2 : 1);
  29. weights[0] = RandomMat(outch * c * kernel * kernel);
  30. if (bias)
  31. weights[1] = RandomMat(outch);
  32. float epsilon = 0.001;
  33. int ret = test_layer("DeformableConv2D", pd, weights, a, 1, epsilon);
  34. if (ret != 0)
  35. {
  36. fprintf(stderr, "test_deformableconv2d failed w=%d h=%d c=%d outch=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d act=%d actparams=[%f,%f]\n", w, h, c, outch, kernel, dilation, stride, pad, bias, activation_type, activation_params[0], activation_params[1]);
  37. }
  38. return ret;
  39. }
  40. static int test_deformableconv2d_0()
  41. {
  42. return 0
  43. || test_deformableconv2d(7, 5, 24, 32, 4, 2, 2, 2, 1)
  44. || test_deformableconv2d(7, 5, 32, 24, 4, 2, 2, 2, 1)
  45. || test_deformableconv2d(7, 5, 28, 32, 4, 2, 2, 2, 1)
  46. || test_deformableconv2d(7, 5, 32, 28, 4, 2, 2, 2, 1)
  47. || test_deformableconv2d(7, 5, 26, 32, 4, 2, 2, 2, 1)
  48. || test_deformableconv2d(7, 5, 32, 26, 4, 2, 2, 2, 1);
  49. }
  50. int main()
  51. {
  52. SRAND(7767517);
  53. return test_deformableconv2d_0();
  54. }