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.

resize.h 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * \file dnn/test/common/resize.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #pragma once
  13. #include <iostream>
  14. #include "megdnn/basic_types.h"
  15. #include "megdnn/opr_param_defs.h"
  16. #include "./rng.h"
  17. namespace megdnn {
  18. namespace test {
  19. namespace resize {
  20. using IMode = param::Resize::InterpolationMode;
  21. struct TestArg {
  22. param::Resize param;
  23. TensorShape src;
  24. TensorShape dst;
  25. TestArg(param::Resize param_, TensorShape src_, TensorShape dst_)
  26. : param(param_), src(src_), dst(dst_) {}
  27. };
  28. // Get the args for linear test
  29. static void set_linear_args(std::vector<TestArg>& args) {
  30. // test src_rows == dst_rows * 2 && src_cols == dst_cols * 2
  31. param::Resize cur_param;
  32. cur_param.format = param::Resize::Format::NHWC;
  33. cur_param.imode = param::Resize::InterpolationMode::INTER_LINEAR;
  34. args.emplace_back(cur_param, TensorShape{1, 6, 6, 1}, TensorShape{1, 3, 3, 1});
  35. // test resize_linear_Restric_kernel
  36. // CH == 3 && dst_rows < src_rows && dst_cols < src_cols
  37. args.emplace_back(cur_param, TensorShape{1, 4, 4, 3}, TensorShape{1, 3, 3, 3});
  38. // test else
  39. args.emplace_back(cur_param, TensorShape{1, 4, 4, 1}, TensorShape{1, 3, 3, 1});
  40. args.emplace_back(cur_param, TensorShape{1, 4, 6, 1}, TensorShape{1, 10, 9, 1});
  41. args.emplace_back(cur_param, TensorShape{1, 4, 6, 3}, TensorShape{1, 10, 9, 3});
  42. }
  43. static void set_nchw_args(std::vector<TestArg>& args) {
  44. param::Resize param;
  45. param.format = param::Resize::Format::NCHW;
  46. param.imode = param::Resize::InterpolationMode::LINEAR;
  47. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 2, 6, 8});
  48. args.emplace_back(param, TensorShape{1, 2, 2, 2}, TensorShape{1, 2, 4, 3});
  49. args.emplace_back(param, TensorShape{1, 2, 6, 8}, TensorShape{1, 2, 3, 4});
  50. }
  51. static inline std::vector<TestArg> get_args(IMode imode = IMode::INTER_LINEAR) {
  52. std::vector<TestArg> args;
  53. set_nchw_args(args);
  54. if (imode == IMode::INTER_LINEAR) {
  55. //! test NHWC with ch != 1 or ch != 3
  56. param::Resize param;
  57. param.format = param::Resize::Format::NHWC;
  58. param.imode = imode;
  59. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 4, 6, 4});
  60. args.emplace_back(param, TensorShape{2, 4, 6, 4}, TensorShape{2, 2, 3, 4});
  61. }
  62. return args;
  63. }
  64. static inline std::vector<TestArg> get_nhwcd4_args() {
  65. std::vector<TestArg> args;
  66. param::Resize param;
  67. param.format = param::Resize::Format::NHWCD4;
  68. param.imode = param::Resize::InterpolationMode::LINEAR;
  69. args.emplace_back(param, TensorShape{2, 2, 1, 3, 4}, TensorShape{2, 4, 1, 6, 4});
  70. args.emplace_back(param, TensorShape{2, 4, 1, 6, 4}, TensorShape{2, 2, 1, 3, 4});
  71. return args;
  72. }
  73. static inline std::vector<TestArg> get_nchw4_args() {
  74. std::vector<TestArg> args;
  75. param::Resize param;
  76. param.format = param::Resize::Format::NCHW4;
  77. param.imode = param::Resize::InterpolationMode::LINEAR;
  78. args.emplace_back(param, TensorShape{1, 1, 2, 3, 4}, TensorShape{1, 1, 2, 6, 4});
  79. args.emplace_back(param, TensorShape{2, 2, 2, 2, 4}, TensorShape{2, 2, 2, 4, 4});
  80. args.emplace_back(param, TensorShape{2, 4, 6, 8, 4}, TensorShape{2, 4, 3, 4, 4});
  81. return args;
  82. }
  83. static inline std::vector<TestArg> get_nchw44_args() {
  84. std::vector<TestArg> args;
  85. param::Resize param;
  86. param.format = param::Resize::Format::NCHW44;
  87. param.imode = param::Resize::InterpolationMode::LINEAR;
  88. rep(n, 4ul) rep(c, 4ul) rep(ih, 4ul) rep(iw, 4ul) rep(oh, 4ul) rep(ow, 4ul)
  89. args.emplace_back(
  90. param, TensorShape{n + 1ul, c + 1ul, ih + 1ul, iw + 1ul, 4ul},
  91. TensorShape{n + 1ul, c + 1ul, oh + 1ul, ow + 1ul, 4ul});
  92. param.imode = param::Resize::InterpolationMode::NEAREST;
  93. rep(n, 4ul) rep(c, 4ul) rep(ih, 4ul) rep(iw, 4ul) rep(oh, 4ul) rep(ow, 4ul)
  94. args.emplace_back(
  95. param, TensorShape{n + 1ul, c + 1ul, ih + 1ul, iw + 1ul, 4ul},
  96. TensorShape{n + 1ul, c + 1ul, oh + 1ul, ow + 1ul, 4ul});
  97. return args;
  98. }
  99. static inline std::vector<TestArg> get_nchw88_args() {
  100. std::vector<TestArg> args;
  101. param::Resize param;
  102. param.format = param::Resize::Format::NCHW88;
  103. param.imode = param::Resize::InterpolationMode::LINEAR;
  104. rep(n, 4ul) rep(c, 4ul) rep(ih, 4ul) rep(iw, 4ul) rep(oh, 4ul) rep(ow, 4ul)
  105. args.emplace_back(
  106. param, TensorShape{n + 1ul, c + 1ul, ih + 1ul, iw + 1ul, 8ul},
  107. TensorShape{n + 1ul, c + 1ul, oh + 1ul, ow + 1ul, 8ul});
  108. param.imode = param::Resize::InterpolationMode::NEAREST;
  109. rep(n, 4ul) rep(c, 4ul) rep(ih, 4ul) rep(iw, 4ul) rep(oh, 4ul) rep(ow, 4ul)
  110. args.emplace_back(
  111. param, TensorShape{n + 1ul, c + 1ul, ih + 1ul, iw + 1ul, 8ul},
  112. TensorShape{n + 1ul, c + 1ul, oh + 1ul, ow + 1ul, 8ul});
  113. return args;
  114. }
  115. static inline std::vector<TestArg> get_cv_args() {
  116. std::vector<TestArg> args;
  117. set_linear_args(args);
  118. param::Resize cur_param;
  119. cur_param.format = param::Resize::Format::NHWC;
  120. for (size_t i = 8; i < 129; i *= 4) {
  121. cur_param.imode = param::Resize::InterpolationMode::INTER_NEAREST;
  122. args.emplace_back(
  123. cur_param, TensorShape{1, i, i, 3}, TensorShape{1, i / 2, i / 2, 3});
  124. args.emplace_back(cur_param, TensorShape{1, i, i, 1}, TensorShape{1, 8, 8, 1});
  125. cur_param.imode = param::Resize::InterpolationMode::INTER_AREA;
  126. args.emplace_back(cur_param, TensorShape{1, i, i, 3}, TensorShape{1, 8, 8, 3});
  127. cur_param.imode = param::Resize::InterpolationMode::INTER_CUBIC;
  128. args.emplace_back(cur_param, TensorShape{1, i, i, 3}, TensorShape{1, 8, 8, 3});
  129. cur_param.imode = param::Resize::InterpolationMode::INTER_LANCZOS4;
  130. args.emplace_back(cur_param, TensorShape{1, i, i, 3}, TensorShape{1, 8, 8, 3});
  131. }
  132. //! cuda not use vector
  133. //! enlarge==true && dst_area_size > 500 * 500
  134. cur_param.imode = param::Resize::InterpolationMode::INTER_CUBIC;
  135. args.emplace_back(cur_param, TensorShape{1, 3, 3, 1}, TensorShape{1, 500, 600, 1});
  136. cur_param.imode = param::Resize::InterpolationMode::INTER_LANCZOS4;
  137. args.emplace_back(cur_param, TensorShape{1, 3, 3, 1}, TensorShape{1, 500, 600, 1});
  138. return args;
  139. }
  140. } // namespace resize
  141. } // namespace test
  142. } // namespace megdnn
  143. // vim: syntax=cpp.doxygen