postprocessor.cc 2.8 KB

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