postprocess_cuda.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 postprocess_cuda.h
  33. * @brief Postprocess for network output
  34. * @author Kosuke Murakami
  35. * @date 2019/02/26
  36. */
  37. #pragma once
  38. // headers in STL
  39. #include <iostream>
  40. #include <memory>
  41. #include <vector>
  42. // headers in local files
  43. #include "nms_cuda.h"
  44. namespace apollo {
  45. namespace perception {
  46. namespace lidar {
  47. class PostprocessCuda {
  48. private:
  49. const float float_min_;
  50. const float float_max_;
  51. const int num_anchor_;
  52. const int num_class_;
  53. const float score_threshold_;
  54. const int num_threads_;
  55. const float nms_overlap_threshold_;
  56. const int num_box_corners_;
  57. const int num_output_box_feature_;
  58. std::unique_ptr<NmsCuda> nms_cuda_ptr_;
  59. public:
  60. /**
  61. * @brief Constructor
  62. * @param[in] float_min The lowest float value
  63. * @param[in] float_max The maximum float value
  64. * @param[in] num_anchor Number of anchors in total
  65. * @param[in] num_class Number of object's classes
  66. * @param[in] score_threshold Score threshold for filtering output
  67. * @param[in] num_threads Number of threads when launching cuda kernel
  68. * @param[in] nms_overlap_threshold IOU threshold for NMS
  69. * @param[in] num_box_corners Number of box's corner
  70. * @param[in] num_output_box_feature Number of output box's feature
  71. * @details Captital variables never change after the compile, non-capital
  72. * variables could be changed through rosparam
  73. */
  74. PostprocessCuda(const float float_min, const float float_max,
  75. const int num_anchor, const int num_class,
  76. const float score_threshold, const int num_threads,
  77. const float nms_overlap_threshold, const int num_box_corners,
  78. const int num_output_box_feature);
  79. /**
  80. * @brief Postprocessing for the network output
  81. * @param[in] rpn_box_output Box predictions from the network output
  82. * @param[in] rpn_cls_output Class predictions from the network output
  83. * @param[in] rpn_dir_output Direction predictions from the network output
  84. * @param[in] dev_anchor_mask Anchor mask for filtering the network output
  85. * @param[in] dev_anchors_px X-coordinate values for corresponding anchors
  86. * @param[in] dev_anchors_py Y-coordinate values for corresponding anchors
  87. * @param[in] dev_anchors_pz Z-coordinate values for corresponding anchors
  88. * @param[in] dev_anchors_dx X-dimension values for corresponding anchors
  89. * @param[in] dev_anchors_dy Y-dimension values for corresponding anchors
  90. * @param[in] dev_anchors_dz Z-dimension values for corresponding anchors
  91. * @param[in] dev_anchors_ro Rotation values for corresponding anchors
  92. * @param[in] dev_filtered_box Filtered box predictions
  93. * @param[in] dev_filtered_score Filtered score predictions
  94. * @param[in] dev_filtered_label Filtered label predictions
  95. * @param[in] dev_filtered_dir Filtered direction predictions
  96. * @param[in] dev_box_for_nms Decoded boxes in min_x min_y max_x max_y
  97. * represenation from pose and dimension
  98. * @param[in] dev_filter_count The number of filtered output
  99. * @param[out] out_detection Output bounding boxes
  100. * @param[out] out_label Output labels of objects
  101. * @details dev_* represents device memory allocated variables
  102. */
  103. void DoPostprocessCuda(
  104. const float* rpn_box_output, const float* rpn_cls_output,
  105. const float* rpn_dir_output, int* dev_anchor_mask,
  106. const float* dev_anchors_px, const float* dev_anchors_py,
  107. const float* dev_anchors_pz, const float* dev_anchors_dx,
  108. const float* dev_anchors_dy, const float* dev_anchors_dz,
  109. const float* dev_anchors_ro, float* dev_filtered_box,
  110. float* dev_filtered_score, int* dev_filtered_label, int* dev_filtered_dir,
  111. float* dev_box_for_nms, int* dev_filter_count,
  112. std::vector<float>* out_detection, std::vector<int>* out_label);
  113. };
  114. } // namespace lidar
  115. } // namespace perception
  116. } // namespace apollo