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.

roi_pooling.cpp 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * \file dnn/test/cuda/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 "test/cuda/fixture.h"
  12. #include "test/common/checker.h"
  13. #include "test/common/roi_pooling.h"
  14. namespace megdnn {
  15. namespace test {
  16. TEST_F(CUDA, ROI_POOLING_FORWARD) {
  17. size_t N = 10, C = 3, IH = 102, IW = 108, spatial_scale = 100;
  18. size_t OH = 12, OW = 13, M = 7;
  19. ROIPoolingRNG rng(N);
  20. using Param = ROIPooling::Param;
  21. Param param;
  22. param.scale = spatial_scale;
  23. Checker<ROIPoolingForward> checker(handle_cuda());
  24. auto run = [&](DType dtype) {
  25. for (auto mode : {Param::Mode::MAX, Param::Mode::AVERAGE}) {
  26. param.mode = mode;
  27. checker.set_param(param)
  28. .set_rng(1, &rng)
  29. .set_dtype(0, dtype)
  30. .set_dtype(1, dtype)
  31. .set_dtype(2, dtype)
  32. .set_dtype(3, dtype::Int32())
  33. .execs({{N, C, IH, IW}, {M, 5}, {M, C, OH, OW}, {M, C, OH, OW}});
  34. }
  35. };
  36. run(dtype::Float32());
  37. run(dtype::Float16());
  38. }
  39. TEST_F(CUDA, ROI_POOLING_BACKWARD) {
  40. size_t N = 10, C = 3, IH = 102, IW = 108, spatial_scale = 100;
  41. size_t OH = 12, OW = 13, M = 7;
  42. ROIPoolingRNG rng(N);
  43. UniformIntRNG index_rng(0, OH * OW - 1);
  44. using Param = ROIPooling::Param;
  45. Param param;
  46. param.scale = spatial_scale;
  47. Checker<ROIPoolingBackward> checker(handle_cuda());
  48. checker.set_epsilon(1e-2);
  49. auto run = [&](DType dtype) {
  50. for (auto mode : {Param::Mode::MAX, Param::Mode::AVERAGE}) {
  51. param.mode = mode;
  52. checker.set_param(param)
  53. .set_dtype(0, dtype)
  54. .set_dtype(1, dtype)
  55. .set_dtype(2, dtype)
  56. .set_dtype(4, dtype)
  57. .set_dtype(3, dtype::Int32())
  58. .set_rng(2, &rng)
  59. .set_rng(3, &index_rng)
  60. .execs({{M, C, OH, OW},
  61. {N, C, IH, IW},
  62. {M, 5},
  63. {M, C, OH, OW},
  64. {N, C, IH, IW}});
  65. }
  66. };
  67. run(dtype::Float32());
  68. run(dtype::Float16());
  69. }
  70. } // namespace test
  71. } // namespace megdnn
  72. // vim: syntax=cpp.doxygen