postprocessor.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/smoke/postprocessor.h"
  15. #include "ultra_infer/vision/utils/utils.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace perception {
  19. SmokePostprocessor::SmokePostprocessor() {}
  20. bool SmokePostprocessor::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 = 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 += 14) {
  32. // item 1 : class
  33. // item 2 : observation angle α
  34. // item 3 ~ 6 : box2d x1, y1, x2, y2
  35. // item 7 ~ 9 : box3d h, w, l
  36. // item 10 ~ 12 : box3d bottom center x, y, z
  37. // item 13 : box3d yaw angle
  38. // item 14 : score
  39. std::vector<float> vec(data + i, data + i + 14);
  40. result->scores.push_back(vec[13]);
  41. result->label_ids.push_back(vec[0]);
  42. result->boxes.emplace_back(std::array<float, 7>{
  43. vec[2], vec[3], vec[4], vec[5], vec[6], vec[7], vec[8]});
  44. result->center.emplace_back(std::array<float, 3>{vec[9], vec[10], vec[11]});
  45. result->observation_angle.push_back(vec[1]);
  46. result->yaw_angle.push_back(vec[12]);
  47. }
  48. result->valid.push_back(true); // 0 scores
  49. result->valid.push_back(true); // 1 label_ids
  50. result->valid.push_back(true); // 2 boxes
  51. result->valid.push_back(true); // 3 center
  52. result->valid.push_back(true); // 4 observation_angle
  53. result->valid.push_back(true); // 5 yaw_angle
  54. result->valid.push_back(false); // 6 velocity
  55. return true;
  56. }
  57. } // namespace perception
  58. } // namespace vision
  59. } // namespace ultra_infer