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.cpp 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2020 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 "layer/interp.h"
  15. #include "testutil.h"
  16. static int test_interp(const ncnn::Mat& a, int resize_type, float height_scale, float width_scale, int output_height, int output_width)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, resize_type);
  20. pd.set(1, height_scale);
  21. pd.set(2, width_scale);
  22. pd.set(3, output_height);
  23. pd.set(4, output_width);
  24. std::vector<ncnn::Mat> weights(0);
  25. int ret = test_layer<ncnn::Interp>("Interp", pd, weights, a);
  26. if (ret != 0)
  27. {
  28. fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d height_scale=%f width_scale=%f output_height=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, height_scale, width_scale, output_height, output_width);
  29. }
  30. return ret;
  31. }
  32. static int test_interp_0()
  33. {
  34. ncnn::Mat a = RandomMat(15, 16, 7);
  35. ncnn::Mat b = RandomMat(14, 17, 12);
  36. ncnn::Mat c = RandomMat(13, 14, 24);
  37. return 0
  38. || test_interp(a, 1, 2.f, 2.f, 0, 0)
  39. || test_interp(a, 1, 4.f, 0.5f, 0, 0)
  40. || test_interp(a, 1, 1.2f, 1.2f, 0, 0)
  41. || test_interp(a, 1, 0.8f, 0.8f, 0, 0)
  42. || test_interp(a, 1, 1.f, 1.f, 10, 12)
  43. || test_interp(a, 1, 1.f, 1.f, 2, 2)
  44. || test_interp(a, 1, 1.f, 1.f, 15, 16)
  45. || test_interp(b, 1, 2.f, 2.f, 0, 0)
  46. || test_interp(b, 1, 4.f, 0.5f, 0, 0)
  47. || test_interp(b, 1, 1.2f, 1.2f, 0, 0)
  48. || test_interp(b, 1, 0.8f, 0.8f, 0, 0)
  49. || test_interp(b, 1, 1.f, 1.f, 10, 12)
  50. || test_interp(b, 1, 1.f, 1.f, 2, 2)
  51. || test_interp(b, 1, 1.f, 1.f, 14, 17)
  52. || test_interp(c, 1, 2.f, 2.f, 0, 0)
  53. || test_interp(c, 1, 4.f, 0.5f, 0, 0)
  54. || test_interp(c, 1, 1.2f, 1.2f, 0, 0)
  55. || test_interp(c, 1, 0.8f, 0.8f, 0, 0)
  56. || test_interp(c, 1, 1.f, 1.f, 10, 12)
  57. || test_interp(c, 1, 1.f, 1.f, 2, 2)
  58. || test_interp(c, 1, 1.f, 1.f, 14, 17);
  59. }
  60. static int test_interp_1()
  61. {
  62. ncnn::Mat a = RandomMat(15, 16, 7);
  63. ncnn::Mat b = RandomMat(14, 17, 12);
  64. ncnn::Mat c = RandomMat(13, 14, 24);
  65. return 0
  66. || test_interp(a, 2, 2.f, 2.f, 0, 0)
  67. || test_interp(a, 2, 4.f, 0.5f, 0, 0)
  68. || test_interp(a, 2, 1.2f, 1.2f, 0, 0)
  69. || test_interp(a, 2, 0.8f, 0.8f, 0, 0)
  70. || test_interp(a, 2, 1.f, 1.f, 10, 12)
  71. || test_interp(a, 2, 1.f, 1.f, 2, 2)
  72. || test_interp(a, 2, 1.f, 1.f, 15, 16)
  73. || test_interp(b, 2, 2.f, 2.f, 0, 0)
  74. || test_interp(b, 2, 4.f, 0.5f, 0, 0)
  75. || test_interp(b, 2, 1.2f, 1.2f, 0, 0)
  76. || test_interp(b, 2, 0.8f, 0.8f, 0, 0)
  77. || test_interp(b, 2, 1.f, 1.f, 10, 12)
  78. || test_interp(b, 2, 1.f, 1.f, 2, 2)
  79. || test_interp(b, 2, 1.f, 1.f, 14, 17)
  80. || test_interp(c, 2, 2.f, 2.f, 0, 0)
  81. || test_interp(c, 2, 4.f, 0.5f, 0, 0)
  82. || test_interp(c, 2, 1.2f, 1.2f, 0, 0)
  83. || test_interp(c, 2, 0.8f, 0.8f, 0, 0)
  84. || test_interp(c, 2, 1.f, 1.f, 10, 12)
  85. || test_interp(c, 2, 1.f, 1.f, 2, 2)
  86. || test_interp(c, 2, 1.f, 1.f, 14, 17);
  87. }
  88. static int test_interp_2()
  89. {
  90. ncnn::Mat a = RandomMat(16, 17, 13);
  91. ncnn::Mat b = RandomMat(18, 19, 12);
  92. ncnn::Mat c = RandomMat(13, 14, 24);
  93. return 0
  94. || test_interp(a, 3, 2.f, 2.f, 0, 0)
  95. || test_interp(a, 3, 4.f, 0.5f, 0, 0)
  96. || test_interp(a, 3, 1.2f, 1.2f, 0, 0)
  97. || test_interp(a, 3, 0.8f, 0.8f, 0, 0)
  98. || test_interp(a, 3, 1.f, 1.f, 10, 12)
  99. || test_interp(a, 3, 1.f, 1.f, 2, 2)
  100. || test_interp(a, 3, 1.f, 1.f, 6, 7)
  101. || test_interp(a, 3, 1.f, 1.f, 16, 17)
  102. || test_interp(b, 3, 2.f, 2.f, 0, 0)
  103. || test_interp(b, 3, 4.f, 0.5f, 0, 0)
  104. || test_interp(b, 3, 1.2f, 1.2f, 0, 0)
  105. || test_interp(b, 3, 0.8f, 0.8f, 0, 0)
  106. || test_interp(b, 3, 1.f, 1.f, 10, 12)
  107. || test_interp(b, 3, 1.f, 1.f, 2, 2)
  108. || test_interp(b, 3, 1.f, 1.f, 6, 7)
  109. || test_interp(b, 3, 1.f, 1.f, 18, 19)
  110. || test_interp(c, 3, 2.f, 2.f, 0, 0)
  111. || test_interp(c, 3, 4.f, 0.5f, 0, 0)
  112. || test_interp(c, 3, 1.2f, 1.2f, 0, 0)
  113. || test_interp(c, 3, 0.8f, 0.8f, 0, 0)
  114. || test_interp(c, 3, 1.f, 1.f, 10, 12)
  115. || test_interp(c, 3, 1.f, 1.f, 2, 2)
  116. || test_interp(c, 3, 1.f, 1.f, 6, 7)
  117. || test_interp(c, 3, 1.f, 1.f, 18, 19);
  118. }
  119. int main()
  120. {
  121. SRAND(7767517);
  122. return 0
  123. || test_interp_0()
  124. || test_interp_1()
  125. || test_interp_2();
  126. }