postprocessor.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "ultra_infer/vision/perception/paddle3d/centerpoint/postprocessor.h"
  15. #include "ultra_infer/vision/utils/utils.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace perception {
  19. CenterpointPostprocessor::CenterpointPostprocessor() {}
  20. bool CenterpointPostprocessor::Run(const std::vector<FDTensor> &tensors,
  21. PerceptionResult *result) {
  22. if (tensors[0].dtype != FDDataType::FP32) {
  23. FDERROR << "Only support post process with float32 data." << std::endl;
  24. return false;
  25. }
  26. const float *data_0 = reinterpret_cast<const float *>(tensors[0].Data());
  27. for (int i = 0; i < tensors[0].shape[0] * tensors[0].shape[1]; i += 9) {
  28. // item 1 ~ 3 : box3d bottom center x, y, z
  29. // item 4 ~ 6 : box3d w, l, h
  30. // item 7 ~ 8 : speed x,y
  31. // item 9 : box3d yaw angle
  32. std::vector<float> vec(data_0 + i, data_0 + i + 9);
  33. result->boxes.emplace_back(
  34. std::array<float, 7>{0, 0, 0, 0, vec[3], vec[4], vec[5]});
  35. result->center.emplace_back(std::array<float, 3>{vec[0], vec[1], vec[2]});
  36. result->yaw_angle.push_back(vec[8]);
  37. result->velocity.push_back(std::array<float, 3>{vec[6], vec[7]});
  38. }
  39. const float *data_1 = reinterpret_cast<const float *>(tensors[2].Data());
  40. for (int i = 0; i < tensors[1].shape[0]; i += 1) {
  41. std::vector<float> vec(data_1 + i, data_1 + i + 1);
  42. result->scores.push_back(vec[0]);
  43. }
  44. const long long *data_2 =
  45. reinterpret_cast<const long long *>(tensors[1].Data());
  46. for (int i = 0; i < tensors[2].shape[0]; i++) {
  47. std::vector<long long> vec(data_2 + i, data_2 + i + 1);
  48. result->label_ids.push_back(vec[0]);
  49. }
  50. result->valid.push_back(true); // 0 scores
  51. result->valid.push_back(true); // 1 label_ids
  52. result->valid.push_back(true); // 2 boxes
  53. result->valid.push_back(true); // 3 center
  54. result->valid.push_back(false); // 4 observation_angle
  55. result->valid.push_back(true); // 5 yaw_angle
  56. result->valid.push_back(true); // 6 velocity
  57. return true;
  58. }
  59. } // namespace perception
  60. } // namespace vision
  61. } // namespace ultra_infer