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_conv.cpp 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * \file dnn/test/naive/deformable_conv.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/naive/fixture.h"
  12. #include "megdnn/oprs/nn.h"
  13. #include "test/common/benchmarker.h"
  14. #include "test/common/checker.h"
  15. #include "test/common/random_state.h"
  16. using namespace megdnn;
  17. using namespace test;
  18. TEST_F(NAIVE, DEFORMABLE_CONV_FWD) {
  19. Checker<DeformableConv> checker(handle());
  20. DeformableConv::Param param;
  21. UniformIntRNG im_rng{0, 4};
  22. UniformIntRNG filter_rng{0, 4};
  23. UniformIntRNG offset_rng{-2, 2};
  24. UniformIntRNG mask_rng{0, 1};
  25. checker.set_rng(0, &im_rng)
  26. .set_rng(1, &filter_rng)
  27. .set_rng(2, &offset_rng)
  28. .set_rng(3, &mask_rng);
  29. param.pad_h = 1;
  30. param.pad_w = 1;
  31. param.stride_h = 1;
  32. param.stride_w = 1;
  33. param.dilate_h = 1;
  34. param.dilate_w = 1;
  35. param.format = DeformableConv::Param::Format::NCHW;
  36. param.sparse = DeformableConv::Param::Sparse::GROUP;
  37. checker.set_param(param).execs({{1, 2, 5, 5},
  38. {2, 1, 1, 3, 3},
  39. {1, 2 * 2 * 3 * 3, 5, 5},
  40. {1, 2 * 3 * 3, 5, 5},
  41. {}});
  42. checker.set_param(param).execs({{1, 2, 5, 5},
  43. {2, 1, 1, 3, 3},
  44. {1, 2 * 2 * 3 * 3, 5, 5},
  45. {1, 2 * 3 * 3, 5, 5},
  46. {}});
  47. param.sparse = DeformableConv::Param::Sparse::DENSE;
  48. checker.set_param(param).execs({{1, 2, 5, 5},
  49. {2, 2, 3, 3},
  50. {1, 2 * 2 * 3 * 3, 5, 5},
  51. {1, 2 * 3 * 3, 5, 5},
  52. {}});
  53. }
  54. TEST_F(NAIVE, DEFORMABLE_CONV_BWD_FILTER) {
  55. Checker<DeformableConvBackwardFilter> checker(handle());
  56. DeformableConv::Param param;
  57. UniformIntRNG im_rng{0, 4};
  58. UniformIntRNG offset_rng{-2, 2};
  59. UniformIntRNG mask_rng{0, 1};
  60. UniformIntRNG out_grad_rng{0, 1};
  61. checker.set_rng(0, &im_rng)
  62. .set_rng(1, &offset_rng)
  63. .set_rng(2, &mask_rng)
  64. .set_rng(3, &out_grad_rng);
  65. param.pad_h = 1;
  66. param.pad_w = 1;
  67. param.stride_h = 1;
  68. param.stride_w = 1;
  69. param.dilate_h = 1;
  70. param.dilate_w = 1;
  71. param.format = DeformableConv::Param::Format::NCHW;
  72. param.sparse = DeformableConv::Param::Sparse::GROUP;
  73. checker.set_param(param).execs({{1, 2, 5, 5},
  74. {1, 2 * 2 * 3 * 3, 5, 5},
  75. {1, 2 * 3 * 3, 5, 5},
  76. {1, 2, 5, 5},
  77. {2, 1, 1, 3, 3}});
  78. }
  79. TEST_F(NAIVE, DEFORMABLE_CONV_BWD_DATA) {
  80. Checker<DeformableConvBackwardData> checker(handle());
  81. DeformableConv::Param param;
  82. ConstValue im_rng{1};
  83. ConstValue filter_rng{0.99};
  84. ConstValue offset_rng{1.1};
  85. ConstValue mask_rng{1};
  86. ConstValue out_grad_rng{1};
  87. checker.set_rng(0, &im_rng)
  88. .set_rng(1, &filter_rng)
  89. .set_rng(2, &offset_rng)
  90. .set_rng(3, &mask_rng)
  91. .set_rng(4, &out_grad_rng);
  92. param.pad_h = 1;
  93. param.pad_w = 1;
  94. param.stride_h = 1;
  95. param.stride_w = 1;
  96. param.dilate_h = 1;
  97. param.dilate_w = 1;
  98. param.format = DeformableConv::Param::Format::NCHW;
  99. param.sparse = DeformableConv::Param::Sparse::GROUP;
  100. checker.set_param(param).execs({{1, 2, 5, 5},
  101. {2, 1, 1, 3, 3},
  102. {1, 1 * 2 * 3 * 3, 5, 5},
  103. {1, 1 * 3 * 3, 5, 5},
  104. {1, 2, 5, 5},
  105. {1, 2, 5, 5},
  106. {1, 1 * 2 * 3 * 3, 5, 5},
  107. {1, 1 * 3 * 3, 5, 5}});
  108. }
  109. // vim: syntax=cpp.doxygen

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

Contributors (1)