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_interp_1.cpp 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2025 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_interp(const ncnn::Mat& a, int resize_type, int align_corner, const char* shape_expr)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, resize_type);
  8. pd.set(5, 1); // dynamic_target_size
  9. pd.set(6, align_corner);
  10. pd.set(9, std::string(shape_expr));
  11. std::vector<ncnn::Mat> weights(0);
  12. int ret = test_layer("Interp", pd, weights, a);
  13. if (ret != 0)
  14. {
  15. fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d %d) resize_type=%d align_corner=%d shape_expr=%s\n", a.dims, a.w, a.h, a.d, a.c, resize_type, align_corner, shape_expr);
  16. }
  17. return ret;
  18. }
  19. static int test_interp(const std::vector<ncnn::Mat>& as, int resize_type, int align_corner, const char* shape_expr)
  20. {
  21. ncnn::ParamDict pd;
  22. pd.set(0, resize_type);
  23. pd.set(5, 1); // dynamic_target_size
  24. pd.set(6, align_corner);
  25. pd.set(9, std::string(shape_expr));
  26. std::vector<ncnn::Mat> weights(0);
  27. int ret = test_layer("Interp", pd, weights, as, 1);
  28. if (ret != 0)
  29. {
  30. fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d %d) resize_type=%d align_corner=%d shape_expr=%s\n", as[0].dims, as[0].w, as[0].h, as[0].d, as[0].c, resize_type, align_corner, shape_expr);
  31. }
  32. return ret;
  33. }
  34. static int test_interp_0()
  35. {
  36. ncnn::Mat a = RandomMat(32, 25, 3);
  37. ncnn::Mat b = RandomMat(20, 14, 32);
  38. return 0
  39. || test_interp(a, 1, 0, "0w,0h")
  40. || test_interp(a, 2, 0, "0w,5")
  41. || test_interp(b, 1, 0, "0w,0h")
  42. || test_interp(b, 2, 0, "0w,5")
  43. || test_interp(a, 3, 0, "square(neg(abs(max(min(//(*(-(+(0w,1),-1),4),4),100),-4)))),0h")
  44. || test_interp(a, 1, 0, "square(neg(abs(max(min(//(*(-(+(0w,1.0),-1.0),2.0),2.0),100.3),-2.2)))),0h")
  45. || test_interp(a, 2, 1, "0w,trunc(*(round(-(floor(+(ceil(*(0w,1.2)),0.7)),-0.4)),1.0001))")
  46. || test_interp(a, 3, 0, "*(0d,4),ceil(sqrt(square(*(asinh(sinh(atanh(tanh(atan(tan(acos(cos(asin(sin(/(0w,2))))))))))),16))))");
  47. }
  48. static int test_interp_1()
  49. {
  50. std::vector<ncnn::Mat> as(2);
  51. as[0] = RandomMat(14, 15, 16);
  52. as[1] = RandomMat(28, 45, 48);
  53. return 0
  54. || test_interp(as, 1, 0, "*(1w,0.5),/(1h,3)")
  55. || test_interp(as, 2, 0, "*(0w,0h),-(-(1c,0c),16)");
  56. }
  57. static int test_interp_2()
  58. {
  59. ncnn::Mat a = RandomMat(14, 15, 16);
  60. ncnn::Mat b = RandomMat(22, 13);
  61. return 0
  62. || test_interp(a, 1, 0, "*(0w,0.5),/(0h,3)")
  63. || test_interp(a, 1, 0, "1,4")
  64. || test_interp(a, 2, 1, "*(0w,0h),0c")
  65. || test_interp(b, 1, 0, "//(0w,3)")
  66. || test_interp(b, 2, 0, "-(0w,5)");
  67. }
  68. int main()
  69. {
  70. SRAND(7767517);
  71. return 0
  72. || test_interp_0()
  73. || test_interp_1()
  74. || test_interp_2();
  75. }