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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2025 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_interp(const ncnn::Mat& a, int resize_type, int align_corner, const char* shape_expr)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, resize_type);
  19. pd.set(5, 1); // dynamic_target_size
  20. pd.set(6, align_corner);
  21. pd.set(9, std::string(shape_expr));
  22. std::vector<ncnn::Mat> weights(0);
  23. int ret = test_layer("Interp", pd, weights, a);
  24. if (ret != 0)
  25. {
  26. 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);
  27. }
  28. return ret;
  29. }
  30. static int test_interp(const std::vector<ncnn::Mat>& as, int resize_type, int align_corner, const char* shape_expr)
  31. {
  32. ncnn::ParamDict pd;
  33. pd.set(0, resize_type);
  34. pd.set(5, 1); // dynamic_target_size
  35. pd.set(6, align_corner);
  36. pd.set(9, std::string(shape_expr));
  37. std::vector<ncnn::Mat> weights(0);
  38. int ret = test_layer("Interp", pd, weights, as, 1);
  39. if (ret != 0)
  40. {
  41. 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);
  42. }
  43. return ret;
  44. }
  45. static int test_interp_0()
  46. {
  47. ncnn::Mat a = RandomMat(32, 25, 3);
  48. ncnn::Mat b = RandomMat(20, 14, 32);
  49. return 0
  50. || test_interp(a, 1, 0, "0w,0h")
  51. || test_interp(a, 2, 0, "0w,5")
  52. || test_interp(b, 1, 0, "0w,0h")
  53. || test_interp(b, 2, 0, "0w,5")
  54. || test_interp(a, 3, 0, "square(neg(abs(max(min(//(*(-(+(0w,1),-1),4),4),100),-4)))),0h")
  55. || test_interp(a, 1, 0, "square(neg(abs(max(min(//(*(-(+(0w,1.0),-1.0),2.0),2.0),100.3),-2.2)))),0h")
  56. || test_interp(a, 2, 1, "0w,trunc(*(round(-(floor(+(ceil(*(0w,1.2)),0.7)),-0.4)),1.0001))")
  57. || test_interp(a, 3, 0, "*(0d,4),ceil(sqrt(square(*(asinh(sinh(atanh(tanh(atan(tan(acos(cos(asin(sin(/(0w,2))))))))))),16))))");
  58. }
  59. static int test_interp_1()
  60. {
  61. std::vector<ncnn::Mat> as(2);
  62. as[0] = RandomMat(14, 15, 16);
  63. as[1] = RandomMat(28, 45, 48);
  64. return 0
  65. || test_interp(as, 1, 0, "*(1w,0.5),/(1h,3)")
  66. || test_interp(as, 2, 0, "*(0w,0h),-(-(1c,0c),16)");
  67. }
  68. static int test_interp_2()
  69. {
  70. ncnn::Mat a = RandomMat(14, 15, 16);
  71. ncnn::Mat b = RandomMat(22, 13);
  72. return 0
  73. || test_interp(a, 1, 0, "*(0w,0.5),/(0h,3)")
  74. || test_interp(a, 1, 0, "1,4")
  75. || test_interp(a, 2, 1, "*(0w,0h),0c")
  76. || test_interp(b, 1, 0, "//(0w,3)")
  77. || test_interp(b, 2, 0, "-(0w,5)");
  78. }
  79. int main()
  80. {
  81. SRAND(7767517);
  82. return 0
  83. || test_interp_0()
  84. || test_interp_1()
  85. || test_interp_2();
  86. }