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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. void exec(WarpPerspective* opr, const TensorNDArray& tensors);
  23. };
  24. class WarpPerspectiveMatRNG final : public IIDRNG {
  25. public:
  26. WarpPerspectiveMatRNG() : idx(0) {}
  27. dt_float32 gen_single_val() override {
  28. std::normal_distribution<float_t> dist;
  29. switch (idx) {
  30. case 6:
  31. case 7:
  32. dist = std::normal_distribution<float_t>(0.0f, 0.01f);
  33. break;
  34. case 8:
  35. dist = std::normal_distribution<float_t>(1.0f, 0.1f);
  36. break;
  37. default:
  38. dist = std::normal_distribution<float_t>(0.0f, 1.0f);
  39. break;
  40. }
  41. auto res = dist(RandomState::generator());
  42. idx = (idx + 1) % 9;
  43. return res;
  44. }
  45. private:
  46. size_t idx;
  47. };
  48. namespace warp_perspective {
  49. struct TestArg {
  50. param::WarpPerspective param;
  51. TensorShape src;
  52. TensorShape trans;
  53. TensorShape dst;
  54. TestArg(param::WarpPerspective param_, TensorShape src_, TensorShape trans_,
  55. TensorShape dst_)
  56. : param(param_), src(src_), trans(trans_), dst(dst_) {}
  57. };
  58. //! Test args for the WarpPerspective with format NHWC
  59. std::vector<TestArg> get_cv_args();
  60. void run_mat_idx_test(Handle* handle);
  61. void run_int8_test(Handle* handle);
  62. void run_quint8_test(Handle* handle);
  63. } // namespace warp_perspective
  64. } // namespace test
  65. } // namespace megdnn
  66. // vim: syntax=cpp.doxygen

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