cls_postprocessor.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Classifier serials model.
  22. */
  23. class ULTRAINFER_DECL ClassifierPostprocessor {
  24. public:
  25. /** \brief Process the result of runtime and fill to ClassifyResult structure
  26. *
  27. * \param[in] tensors The inference result from runtime
  28. * \param[in] cls_labels The output label results of classification model
  29. * \param[in] cls_scores The output score results of classification model
  30. * \return true if the postprocess succeeded, otherwise false
  31. */
  32. bool Run(const std::vector<FDTensor> &tensors,
  33. std::vector<int32_t> *cls_labels, std::vector<float> *cls_scores);
  34. bool Run(const std::vector<FDTensor> &tensors,
  35. std::vector<int32_t> *cls_labels, std::vector<float> *cls_scores,
  36. size_t start_index, size_t total_size);
  37. /// Set threshold for the classification postprocess, default is 0.9
  38. void SetClsThresh(float cls_thresh) { cls_thresh_ = cls_thresh; }
  39. /// Get threshold value of the classification postprocess.
  40. float GetClsThresh() const { return cls_thresh_; }
  41. private:
  42. float cls_thresh_ = 0.9;
  43. };
  44. } // namespace ocr
  45. } // namespace vision
  46. } // namespace ultra_infer