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.h 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * \file dnn/test/common/warp_perspective.h
  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. #pragma once
  12. #include "test/common/rng.h"
  13. #include "test/common/random_state.h"
  14. #include "test/common/workspace_wrapper.h"
  15. #include "megdnn/oprs/imgproc.h"
  16. #include "megdnn/opr_param_defs.h"
  17. namespace megdnn {
  18. namespace test {
  19. struct WarpPerspectiveMatIdxProxy {
  20. WorkspaceWrapper W;
  21. static void deduce_layout(WarpPerspective*, TensorLayoutArray&);
  22. static void deduce_layout(WarpPerspectiveBackwardData*, TensorLayoutArray&);
  23. static void deduce_layout(WarpPerspectiveBackwardMat*, TensorLayoutArray&);
  24. void exec(WarpPerspective* opr, const TensorNDArray& tensors);
  25. void exec(WarpPerspectiveBackwardData* opr, const TensorNDArray& tensors);
  26. void exec(WarpPerspectiveBackwardMat* opr, const TensorNDArray& tensors);
  27. };
  28. class WarpPerspectiveMatRNG final : public IIDRNG {
  29. public:
  30. WarpPerspectiveMatRNG() : idx(0) {}
  31. dt_float32 gen_single_val() override {
  32. std::normal_distribution<float_t> dist;
  33. switch (idx) {
  34. case 6:
  35. case 7:
  36. dist = std::normal_distribution<float_t>(0.0f, 0.01f);
  37. break;
  38. case 8:
  39. dist = std::normal_distribution<float_t>(1.0f, 0.1f);
  40. break;
  41. default:
  42. dist = std::normal_distribution<float_t>(0.0f, 1.0f);
  43. break;
  44. }
  45. auto res = dist(RandomState::generator());
  46. idx = (idx + 1) % 9;
  47. return res;
  48. }
  49. private:
  50. size_t idx;
  51. };
  52. namespace warp_perspective {
  53. struct TestArg {
  54. param::WarpPerspective param;
  55. TensorShape src;
  56. TensorShape trans;
  57. TensorShape mat_idx;
  58. TensorShape dst;
  59. TestArg(param::WarpPerspective param_, TensorShape src_, TensorShape trans_, TensorShape mat_idx_,
  60. TensorShape dst_)
  61. : param(param_), src(src_), trans(trans_), mat_idx(mat_idx_), dst(dst_) {}
  62. };
  63. //! Test args for the WarpPerspective with format NHWC
  64. std::vector<TestArg> get_cv_args();
  65. void run_mat_idx_test(Handle* handle);
  66. void run_int8_test(Handle* handle);
  67. void run_quint8_test(Handle* handle);
  68. } // namespace warp_perspective
  69. } // namespace test
  70. } // namespace megdnn
  71. // vim: syntax=cpp.doxygen

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