nms_cuda.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /******************************************************************************
  2. * Copyright 2020 The Apollo Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *****************************************************************************/
  16. /*
  17. * Copyright 2018-2019 Autoware Foundation. All rights reserved.
  18. *
  19. * Licensed under the Apache License, Version 2.0 (the "License");
  20. * you may not use this file except in compliance with the License.
  21. * You may obtain a copy of the License at
  22. *
  23. * http://www.apache.org/licenses/LICENSE-2.0
  24. *
  25. * Unless required by applicable law or agreed to in writing, software
  26. * distributed under the License is distributed on an "AS IS" BASIS,
  27. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  28. * See the License for the specific language governing permissions and
  29. * limitations under the License.
  30. */
  31. /**
  32. * @file nms_cuda.h
  33. * @brief Non-maximum suppresion for network output
  34. * @author Modified by Kosuke Murakami
  35. * @date 2019/02/26
  36. */
  37. #pragma once
  38. // heders in STL
  39. #include <iostream>
  40. #include <vector>
  41. // headers in local files
  42. #include "common.h"
  43. namespace apollo {
  44. namespace perception {
  45. namespace lidar {
  46. class NmsCuda {
  47. private:
  48. const int num_threads_;
  49. const int num_box_corners_;
  50. const float nms_overlap_threshold_;
  51. public:
  52. /**
  53. * @brief Constructor
  54. * @param[in] num_threads Number of threads when launching cuda kernel
  55. * @param[in] num_box_corners Number of corners for 2D box
  56. * @param[in] nms_overlap_threshold IOU threshold for NMS
  57. * @details Captital variables never change after the compile, Non-captital
  58. * variables could be chaned through rosparam
  59. */
  60. NmsCuda(const int num_threads, const int num_box_corners,
  61. const float nms_overlap_threshold);
  62. /**
  63. * @brief GPU Non-Maximum Suppresion for network output
  64. * @param[in] host_filter_count Number of filtered output
  65. * @param[in] dev_sorted_box_for_nms Bounding box output sorted by score
  66. * @param[out] out_keep_inds Indexes of selected bounding box
  67. * @param[out] out_num_to_keep Number of kept bounding boxes
  68. * @details NMS in GPU and postprocessing for selecting box in CPU
  69. */
  70. void DoNmsCuda(const int host_filter_count, float* dev_sorted_box_for_nms,
  71. int* out_keep_inds, int* out_num_to_keep);
  72. };
  73. } // namespace lidar
  74. } // namespace perception
  75. } // namespace apollo