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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 implied.
  10. */
  11. #pragma once
  12. #include "megdnn/opr_param_defs.h"
  13. #include "megdnn/basic_types.h"
  14. #include <iostream>
  15. #include "./rng.h"
  16. namespace megdnn {
  17. namespace test {
  18. namespace resize {
  19. using IMode = param::Resize::InterpolationMode;
  20. struct TestArg {
  21. param::Resize param;
  22. TensorShape src;
  23. TensorShape dst;
  24. TestArg(param::Resize param_, TensorShape src_, TensorShape dst_)
  25. : param(param_), src(src_), dst(dst_) {}
  26. };
  27. // Get the args for linear test
  28. static void set_linear_args(std::vector<TestArg>& args) {
  29. // test src_rows == dst_rows * 2 && src_cols == dst_cols * 2
  30. param::Resize cur_param;
  31. cur_param.format = param::Resize::Format::NHWC;
  32. cur_param.imode = param::Resize::InterpolationMode::INTER_LINEAR;
  33. args.emplace_back(cur_param, TensorShape{1, 6, 6, 1},
  34. 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},
  38. TensorShape{1, 3, 3, 3});
  39. // test else
  40. args.emplace_back(cur_param, TensorShape{1, 4, 4, 1},
  41. TensorShape{1, 3, 3, 1});
  42. args.emplace_back(cur_param, TensorShape{1, 4, 6, 1},
  43. TensorShape{1, 10, 9, 1});
  44. args.emplace_back(cur_param, TensorShape{1, 4, 6, 3},
  45. TensorShape{1, 10, 9, 3});
  46. }
  47. static void set_nchw_args(std::vector<TestArg>& args) {
  48. param::Resize param;
  49. param.format = param::Resize::Format::NCHW;
  50. param.imode = param::Resize::InterpolationMode::LINEAR;
  51. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 2, 6, 8});
  52. args.emplace_back(param, TensorShape{1, 2, 2, 2}, TensorShape{1, 2, 4, 3});
  53. args.emplace_back(param, TensorShape{1, 2, 6, 8}, TensorShape{1, 2, 3, 4});
  54. }
  55. static inline std::vector<TestArg> get_args(IMode imode = IMode::INTER_LINEAR) {
  56. std::vector<TestArg> args;
  57. set_nchw_args(args);
  58. if(imode == IMode::INTER_LINEAR) {
  59. //! test NHWC with ch != 1 or ch != 3
  60. param::Resize param;
  61. param.format = param::Resize::Format::NHWC;
  62. param.imode = imode;
  63. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 4, 6, 4});
  64. args.emplace_back(param, TensorShape{2, 4, 6, 4}, TensorShape{2, 2, 3, 4});
  65. }
  66. return args;
  67. }
  68. static inline std::vector<TestArg> get_nhwcd4_args() {
  69. std::vector<TestArg> args;
  70. param::Resize param;
  71. param.format = param::Resize::Format::NHWCD4;
  72. param.imode = param::Resize::InterpolationMode::LINEAR;
  73. args.emplace_back(param, TensorShape{2, 2, 1, 3, 4},
  74. TensorShape{2, 4, 1, 6, 4});
  75. args.emplace_back(param, TensorShape{2, 4, 1, 6, 4},
  76. TensorShape{2, 2, 1, 3, 4});
  77. return args;
  78. }
  79. static inline std::vector<TestArg> get_nchw4_args() {
  80. std::vector<TestArg> args;
  81. param::Resize param;
  82. param.format = param::Resize::Format::NCHW4;
  83. param.imode = param::Resize::InterpolationMode::LINEAR;
  84. args.emplace_back(param, TensorShape{1, 1, 2, 3, 4},
  85. TensorShape{1, 1, 2, 6, 4});
  86. args.emplace_back(param, TensorShape{2, 2, 2, 2, 4},
  87. TensorShape{2, 2, 2, 4, 4});
  88. args.emplace_back(param, TensorShape{2, 4, 6, 8, 4},
  89. TensorShape{2, 4, 3, 4, 4});
  90. return args;
  91. }
  92. static inline std::vector<TestArg> get_cv_args() {
  93. std::vector<TestArg> args;
  94. set_linear_args(args);
  95. param::Resize cur_param;
  96. cur_param.format = param::Resize::Format::NHWC;
  97. for (size_t i = 8; i < 129; i *= 4) {
  98. cur_param.imode = param::Resize::InterpolationMode::INTER_NEAREST;
  99. args.emplace_back(cur_param, TensorShape{1, i, i, 3},
  100. TensorShape{1, i / 2, i / 2, 3});
  101. args.emplace_back(cur_param, TensorShape{1, i, i, 1},
  102. TensorShape{1, 8, 8, 1});
  103. cur_param.imode = param::Resize::InterpolationMode::INTER_AREA;
  104. args.emplace_back(cur_param, TensorShape{1, i, i, 3},
  105. TensorShape{1, 8, 8, 3});
  106. cur_param.imode = param::Resize::InterpolationMode::INTER_CUBIC;
  107. args.emplace_back(cur_param, TensorShape{1, i, i, 3},
  108. TensorShape{1, 8, 8, 3});
  109. cur_param.imode = param::Resize::InterpolationMode::INTER_LANCZOS4;
  110. args.emplace_back(cur_param, TensorShape{1, i, i, 3},
  111. TensorShape{1, 8, 8, 3});
  112. }
  113. //! cuda not use vector
  114. //! enlarge==true && dst_area_size > 500 * 500
  115. cur_param.imode = param::Resize::InterpolationMode::INTER_CUBIC;
  116. args.emplace_back(cur_param, TensorShape{1, 3, 3, 1},
  117. TensorShape{1, 500, 600, 1});
  118. cur_param.imode = param::Resize::InterpolationMode::INTER_LANCZOS4;
  119. args.emplace_back(cur_param, TensorShape{1, 3, 3, 1},
  120. TensorShape{1, 500, 600, 1});
  121. return args;
  122. }
  123. } // namespace resize
  124. } // namespace test
  125. } // namespace megdnn
  126. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台