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.

deformable_ps_roi_pooling.cpp 3.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * \file dnn/test/cuda/deformable_ps_roi_pooling.cpp
  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. #include "megdnn/oprs/nn.h"
  12. #include "src/cuda/utils.h"
  13. #include "test/common/checker.h"
  14. #include "test/common/random_state.h"
  15. #include "test/common/roi_pooling.h"
  16. #include "test/cuda/benchmark.h"
  17. #include "test/cuda/fixture.h"
  18. using namespace megdnn;
  19. using namespace test;
  20. TEST_F(CUDA, DEFORMABLE_PSROI_POOLING_FWD) {
  21. Checker<DeformablePSROIPooling> checker(handle_cuda());
  22. auto run = [&checker](size_t N, size_t C, size_t IH, size_t IW, size_t OH,
  23. size_t OW, bool no_trans, size_t nr_bbox,
  24. size_t nr_cls, size_t part_sz, size_t sample_per_part,
  25. float trans_std, float spatial_scale) {
  26. DeformablePSROIPooling::Param param;
  27. param.no_trans = no_trans;
  28. param.pooled_h = OH;
  29. param.pooled_w = OW;
  30. param.trans_std = trans_std;
  31. param.spatial_scale = spatial_scale;
  32. param.part_size = part_sz;
  33. param.sample_per_part = sample_per_part;
  34. ROIPoolingRNG rois(N);
  35. checker.set_rng(1, &rois);
  36. checker.set_param(param).execs(
  37. {{N, C, IH, IW}, {nr_bbox, 5}, {nr_cls, 2, OH, OW}, {}, {}});
  38. };
  39. run(2, 4, 5, 5, 3, 3, true, 2, 2, 1, 1, 1.f, 1.f);
  40. run(2, 4, 5, 5, 3, 3, false, 2, 2, 1, 1, 1.f, 1.f);
  41. run(2, 4, 5, 5, 3, 3, false, 2, 2, 1, 1, 0.5f, 1.5f);
  42. run(2, 4, 100, 100, 60, 60, false, 2, 2, 1, 1, 0.5f, 1.5f);
  43. run(10, 3, 102, 108, 12, 13, false, 7, 2, 2, 2, 0.5f, 1.5f);
  44. run(2, 32, 100, 100, 50, 50, false, 16, 4, 1, 1, 1.f, 1.f);
  45. }
  46. TEST_F(CUDA, DEFORMABLE_PSROI_POOLING_BWD) {
  47. Checker<DeformablePSROIPoolingBackward> checker(handle_cuda());
  48. auto run = [&checker](size_t N, size_t C, size_t IH, size_t IW, size_t OH,
  49. size_t OW, bool no_trans, size_t nr_bbox,
  50. size_t nr_cls, size_t part_sz, size_t sample_per_part,
  51. float trans_std, float spatial_scale) {
  52. DeformablePSROIPooling::Param param;
  53. param.no_trans = no_trans;
  54. param.pooled_h = OH;
  55. param.pooled_w = OW;
  56. param.trans_std = trans_std;
  57. param.spatial_scale = spatial_scale;
  58. param.part_size = part_sz;
  59. param.sample_per_part = sample_per_part;
  60. ROIPoolingRNG rois(N);
  61. checker.set_rng(1, &rois);
  62. checker.set_param(param).execs({
  63. {N, C, IH, IW}, // data
  64. {nr_bbox, 5}, // rois
  65. {nr_cls, 2, OH, OW}, // trans
  66. {nr_bbox, C, OH, OW}, // out_diff
  67. {nr_bbox, C, OH, OW}, // out_count
  68. {N, C, IH, IW}, // data_diff
  69. {nr_cls, 2, OH, OW} // trans_diff
  70. });
  71. };
  72. run(2, 4, 5, 5, 3, 3, true, 2, 2, 1, 1, 1.f, 1.f);
  73. run(2, 4, 5, 5, 3, 3, false, 2, 2, 2, 2, 1.f, 1.f);
  74. run(2, 4, 5, 5, 3, 3, false, 2, 2, 1, 1, 1.f, 1.f);
  75. run(2, 4, 5, 5, 3, 3, false, 2, 2, 1, 1, 0.5f, 1.5f);
  76. run(2, 4, 100, 100, 60, 60, false, 2, 2, 1, 1, 0.5f, 1.5f);
  77. run(10, 3, 102, 108, 12, 13, false, 7, 2, 2, 2, 0.5f, 1.5f);
  78. run(2, 32, 100, 100, 50, 50, false, 16, 4, 1, 1, 1.f, 1.f);
  79. }
  80. // vim: syntax=cpp.doxygen

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