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.3 kB

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

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