rec_postprocessor.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #pragma once
  15. #include "ultra_infer/vision/common/processors/transform.h"
  16. #include "ultra_infer/vision/common/result.h"
  17. #include "ultra_infer/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace ocr {
  21. /*! @brief Postprocessor object for Recognizer serials model.
  22. */
  23. class ULTRAINFER_DECL RecognizerPostprocessor {
  24. public:
  25. RecognizerPostprocessor();
  26. /** \brief Create a postprocessor instance for Recognizer serials model
  27. *
  28. * \param[in] label_path The path of label_dict
  29. */
  30. explicit RecognizerPostprocessor(const std::string &label_path);
  31. /** \brief Process the result of runtime and fill to RecognizerResult
  32. *
  33. * \param[in] tensors The inference result from runtime
  34. * \param[in] texts The output text results of recognizer
  35. * \param[in] rec_scores The output score results of recognizer
  36. * \return true if the postprocess succeeded, otherwise false
  37. */
  38. bool Run(const std::vector<FDTensor> &tensors,
  39. std::vector<std::string> *texts, std::vector<float> *rec_scores);
  40. bool Run(const std::vector<FDTensor> &tensors,
  41. std::vector<std::string> *texts, std::vector<float> *rec_scores,
  42. size_t start_index, size_t total_size,
  43. const std::vector<int> &indices);
  44. private:
  45. bool SingleBatchPostprocessor(const float *out_data,
  46. const std::vector<int64_t> &output_shape,
  47. std::string *text, float *rec_score);
  48. bool initialized_ = false;
  49. std::vector<std::string> label_list_;
  50. };
  51. } // namespace ocr
  52. } // namespace vision
  53. } // namespace ultra_infer