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.

warp_perspective.cpp 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * \file dnn/test/fallback/warp_perspective.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 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. #include "test/fallback/fixture.h"
  12. #include "test/common/checker.h"
  13. #include "test/common/random_state.h"
  14. #include "test/common/rng.h"
  15. #include "test/common/warp_perspective.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(FALLBACK, WARP_PERSPECTIVE) {
  19. Checker<WarpPerspective> checker(handle());
  20. param::WarpPerspective param;
  21. class ResizeMatRNG : public RNG {
  22. void gen(const TensorND& tensor_) override {
  23. auto& gen = RandomState::generator();
  24. std::uniform_real_distribution<dt_float32> pdist3(1.9f, 3.1f);
  25. std::uniform_real_distribution<dt_float32> pdist(0.9f, 1.1f);
  26. std::uniform_real_distribution<dt_float32> pdisth(0.4f, 0.6f);
  27. std::uniform_real_distribution<dt_float32> ndist(-1.1f, -0.9f);
  28. std::uniform_real_distribution<dt_float32> ndist3(-3.1f, -1.9f);
  29. std::uniform_real_distribution<dt_float32> ndisth(-0.6f, -0.4f);
  30. std::uniform_int_distribution<int> dice(0, 5);
  31. float* ptr = tensor_.ptr<dt_float32>();
  32. auto N = tensor_.layout.shape[0];
  33. for (size_t n = 0; n < N; ++n) {
  34. for (size_t i = 0; i < 9; ++i) {
  35. switch (dice(gen)) {
  36. case 0:
  37. ptr[i] = pdist3(gen);
  38. break;
  39. case 1:
  40. ptr[i] = pdist(gen);
  41. break;
  42. case 2:
  43. ptr[i] = pdisth(gen);
  44. break;
  45. case 3:
  46. ptr[i] = ndist(gen);
  47. break;
  48. case 4:
  49. ptr[i] = ndist3(gen);
  50. break;
  51. case 5:
  52. ptr[i] = ndisth(gen);
  53. break;
  54. }
  55. }
  56. // is resize?
  57. if (n & 1) {
  58. ptr[1] = 0;
  59. ptr[3] = 0;
  60. ptr[6] = ptr[7] = 0;
  61. }
  62. ptr += 9;
  63. }
  64. }
  65. } rng;
  66. checker.set_rng(1, &rng);
  67. using BMode = param::WarpPerspective::BorderMode;
  68. param.imode = param::WarpPerspective::InterpolationMode::LINEAR;
  69. for (auto mode : {BMode::REFLECT_101, BMode::REPLICATE, BMode::REFLECT,
  70. BMode::WRAP, BMode::CONSTANT}) {
  71. param.bmode = mode;
  72. param.border_val = 1.737;
  73. checker.set_param(param);
  74. checker.exec({{1000, 2, 10, 11}, {1000, 3, 3}, {1000, 2, 12, 13}});
  75. }
  76. #if MEGDNN_TEST_ASAN
  77. //! asan detect nan will make test failed
  78. #else
  79. // resize nan case
  80. UniformFloatRNG rng_zero(0, 0);
  81. checker.set_rng(1, &rng_zero);
  82. {
  83. param.bmode = BMode::CONSTANT;
  84. param.border_val = 1.737;
  85. checker.set_param(param);
  86. checker.exec({{1000, 2, 10, 11}, {1000, 3, 3}, {1000, 2, 12, 13}});
  87. }
  88. #endif
  89. }
  90. TEST_F(FALLBACK, WARP_PERSPECTIVE_MAT_IDX) {
  91. warp_perspective::run_mat_idx_test(handle());
  92. }
  93. TEST_F(FALLBACK, WARP_PERSPECTIFVE_NCHW_INT8) {
  94. warp_perspective::run_int8_test(handle());
  95. }
  96. TEST_F(FALLBACK, WARP_PERSPECTIFVE_NCHW_QUINT8) {
  97. warp_perspective::run_quint8_test(handle());
  98. }
  99. } // namespace test
  100. } // namespace megdnn
  101. // vim: syntax=cpp.doxygen

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