postprocess.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <cuda.h>
  15. #include <cuda_runtime_api.h>
  16. #include "paddle/include/experimental/ext_all.h"
  17. std::vector<paddle::Tensor> postprocess_gpu(
  18. const std::vector<paddle::Tensor> &hm,
  19. const std::vector<paddle::Tensor> &reg,
  20. const std::vector<paddle::Tensor> &height,
  21. const std::vector<paddle::Tensor> &dim,
  22. const std::vector<paddle::Tensor> &vel,
  23. const std::vector<paddle::Tensor> &rot,
  24. const std::vector<float> &voxel_size,
  25. const std::vector<float> &point_cloud_range,
  26. const std::vector<float> &post_center_range,
  27. const std::vector<int> &num_classes, const int down_ratio,
  28. const float score_threshold, const float nms_iou_threshold,
  29. const int nms_pre_max_size, const int nms_post_max_size,
  30. const bool with_velocity);
  31. std::vector<paddle::Tensor> centerpoint_postprocess(
  32. const std::vector<paddle::Tensor> &hm,
  33. const std::vector<paddle::Tensor> &reg,
  34. const std::vector<paddle::Tensor> &height,
  35. const std::vector<paddle::Tensor> &dim,
  36. const std::vector<paddle::Tensor> &vel,
  37. const std::vector<paddle::Tensor> &rot,
  38. const std::vector<float> &voxel_size,
  39. const std::vector<float> &point_cloud_range,
  40. const std::vector<float> &post_center_range,
  41. const std::vector<int> &num_classes, const int down_ratio,
  42. const float score_threshold, const float nms_iou_threshold,
  43. const int nms_pre_max_size, const int nms_post_max_size,
  44. const bool with_velocity) {
  45. if (hm[0].is_gpu()) {
  46. return postprocess_gpu(hm, reg, height, dim, vel, rot, voxel_size,
  47. point_cloud_range, post_center_range, num_classes,
  48. down_ratio, score_threshold, nms_iou_threshold,
  49. nms_pre_max_size, nms_post_max_size, with_velocity);
  50. } else {
  51. PD_THROW(
  52. "Unsupported device type for centerpoint postprocess "
  53. "operator.");
  54. }
  55. }
  56. std::vector<std::vector<int64_t>> PostProcessInferShape(
  57. const std::vector<std::vector<int64_t>> &hm_shape,
  58. const std::vector<std::vector<int64_t>> &reg_shape,
  59. const std::vector<std::vector<int64_t>> &height_shape,
  60. const std::vector<std::vector<int64_t>> &dim_shape,
  61. const std::vector<std::vector<int64_t>> &vel_shape,
  62. const std::vector<std::vector<int64_t>> &rot_shape,
  63. const std::vector<float> &voxel_size,
  64. const std::vector<float> &point_cloud_range,
  65. const std::vector<float> &post_center_range,
  66. const std::vector<int> &num_classes, const int down_ratio,
  67. const float score_threshold, const float nms_iou_threshold,
  68. const int nms_pre_max_size, const int nms_post_max_size,
  69. const bool with_velocity) {
  70. if (with_velocity) {
  71. return {{-1, 9}, {-1}, {-1}};
  72. } else {
  73. return {{-1, 7}, {-1}, {-1}};
  74. }
  75. }
  76. std::vector<paddle::DataType> PostProcessInferDtype(
  77. const std::vector<paddle::DataType> &hm_dtype,
  78. const std::vector<paddle::DataType> &reg_dtype,
  79. const std::vector<paddle::DataType> &height_dtype,
  80. const std::vector<paddle::DataType> &dim_dtype,
  81. const std::vector<paddle::DataType> &vel_dtype,
  82. const std::vector<paddle::DataType> &rot_dtype) {
  83. return {reg_dtype[0], hm_dtype[0], paddle::DataType::INT64};
  84. }
  85. PD_BUILD_OP(centerpoint_postprocess)
  86. .Inputs({paddle::Vec("HM"), paddle::Vec("REG"), paddle::Vec("HEIGHT"),
  87. paddle::Vec("DIM"), paddle::Vec("VEL"), paddle::Vec("ROT")})
  88. .Outputs({"BBOXES", "SCORES", "LABELS"})
  89. .SetKernelFn(PD_KERNEL(centerpoint_postprocess))
  90. .Attrs({"voxel_size: std::vector<float>",
  91. "point_cloud_range: std::vector<float>",
  92. "post_center_range: std::vector<float>",
  93. "num_classes: std::vector<int>", "down_ratio: int",
  94. "score_threshold: float", "nms_iou_threshold: float",
  95. "nms_pre_max_size: int", "nms_post_max_size: int",
  96. "with_velocity: bool"})
  97. .SetInferShapeFn(PD_INFER_SHAPE(PostProcessInferShape))
  98. .SetInferDtypeFn(PD_INFER_DTYPE(PostProcessInferDtype));