postprocessor.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/caddn/postprocessor.h"
  15. #include "ultra_infer/vision/utils/utils.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace perception {
  19. CaddnPostprocessor::CaddnPostprocessor() {}
  20. bool CaddnPostprocessor::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 += 7) {
  32. // item 1 ~ 3 : box3d bottom center x, y, z
  33. // item 4 ~ 6 : box3d w, h, l
  34. // item 7 : box3d yaw angle
  35. std::vector<float> vec(data_0 + i, data_0 + i + 7);
  36. result->boxes.emplace_back(
  37. std::array<float, 7>{0, 0, 0, 0, vec[3], vec[4], vec[5]});
  38. result->center.emplace_back(std::array<float, 3>{vec[0], vec[1], vec[2]});
  39. result->yaw_angle.push_back(vec[6]);
  40. }
  41. const float *data_1 = reinterpret_cast<const float *>(tensors[2].Data());
  42. for (int i = 0; i < tensors[2].shape[0]; i += 1) {
  43. std::vector<float> vec(data_1 + i, data_1 + i + 1);
  44. result->scores.push_back(vec[0]);
  45. }
  46. const float *data_2 = reinterpret_cast<const float *>(tensors[1].Data());
  47. for (int i = 0; i < tensors[1].shape[0]; i++) {
  48. std::vector<float> vec(data_2 + i, data_2 + i + 1);
  49. result->label_ids.push_back(vec[0]);
  50. }
  51. result->valid.push_back(true); // 0 scores
  52. result->valid.push_back(true); // 1 label_ids
  53. result->valid.push_back(true); // 2 boxes
  54. result->valid.push_back(true); // 3 center
  55. result->valid.push_back(false); // 4 observation_angle
  56. result->valid.push_back(true); // 5 yaw_angle
  57. result->valid.push_back(false); // 6 velocity
  58. return true;
  59. }
  60. } // namespace perception
  61. } // namespace vision
  62. } // namespace ultra_infer