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 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-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 "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(
  38. {{1, 2, 5, 5},
  39. {2, 1, 1, 3, 3},
  40. {1, 2 * 2 * 3 * 3, 5, 5},
  41. {1, 2 * 3 * 3, 5, 5},
  42. {}});
  43. checker.set_param(param).execs(
  44. {{1, 2, 5, 5},
  45. {2, 1, 1, 3, 3},
  46. {1, 2 * 2 * 3 * 3, 5, 5},
  47. {1, 2 * 3 * 3, 5, 5},
  48. {}});
  49. param.sparse = DeformableConv::Param::Sparse::DENSE;
  50. checker.set_param(param).execs(
  51. {{1, 2, 5, 5},
  52. {2, 2, 3, 3},
  53. {1, 2 * 2 * 3 * 3, 5, 5},
  54. {1, 2 * 3 * 3, 5, 5},
  55. {}});
  56. }
  57. TEST_F(NAIVE, DEFORMABLE_CONV_BWD_FILTER) {
  58. Checker<DeformableConvBackwardFilter> checker(handle());
  59. DeformableConv::Param param;
  60. UniformIntRNG im_rng{0, 4};
  61. UniformIntRNG offset_rng{-2, 2};
  62. UniformIntRNG mask_rng{0, 1};
  63. UniformIntRNG out_grad_rng{0, 1};
  64. checker.set_rng(0, &im_rng)
  65. .set_rng(1, &offset_rng)
  66. .set_rng(2, &mask_rng)
  67. .set_rng(3, &out_grad_rng);
  68. param.pad_h = 1;
  69. param.pad_w = 1;
  70. param.stride_h = 1;
  71. param.stride_w = 1;
  72. param.dilate_h = 1;
  73. param.dilate_w = 1;
  74. param.format = DeformableConv::Param::Format::NCHW;
  75. param.sparse = DeformableConv::Param::Sparse::GROUP;
  76. checker.set_param(param).execs(
  77. {{1, 2, 5, 5},
  78. {1, 2 * 2 * 3 * 3, 5, 5},
  79. {1, 2 * 3 * 3, 5, 5},
  80. {1, 2, 5, 5},
  81. {2, 1, 1, 3, 3}});
  82. }
  83. TEST_F(NAIVE, DEFORMABLE_CONV_BWD_DATA) {
  84. Checker<DeformableConvBackwardData> checker(handle());
  85. DeformableConv::Param param;
  86. ConstValue im_rng{1};
  87. ConstValue filter_rng{0.99};
  88. ConstValue offset_rng{1.1};
  89. ConstValue mask_rng{1};
  90. ConstValue out_grad_rng{1};
  91. checker.set_rng(0, &im_rng)
  92. .set_rng(1, &filter_rng)
  93. .set_rng(2, &offset_rng)
  94. .set_rng(3, &mask_rng)
  95. .set_rng(4, &out_grad_rng);
  96. param.pad_h = 1;
  97. param.pad_w = 1;
  98. param.stride_h = 1;
  99. param.stride_w = 1;
  100. param.dilate_h = 1;
  101. param.dilate_w = 1;
  102. param.format = DeformableConv::Param::Format::NCHW;
  103. param.sparse = DeformableConv::Param::Sparse::GROUP;
  104. checker.set_param(param).execs(
  105. {{1, 2, 5, 5},
  106. {2, 1, 1, 3, 3},
  107. {1, 1 * 2 * 3 * 3, 5, 5},
  108. {1, 1 * 3 * 3, 5, 5},
  109. {1, 2, 5, 5},
  110. {1, 2, 5, 5},
  111. {1, 1 * 2 * 3 * 3, 5, 5},
  112. {1, 1 * 3 * 3, 5, 5}});
  113. }
  114. // vim: syntax=cpp.doxygen

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