pg_postprocess.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2021 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. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. import os
  18. import sys
  19. __dir__ = os.path.dirname(__file__)
  20. sys.path.append(__dir__)
  21. sys.path.append(os.path.join(__dir__, '..'))
  22. from ppocr.utils.e2e_utils.pgnet_pp_utils import PGNet_PostProcess
  23. class PGPostProcess(object):
  24. """
  25. The post process for PGNet.
  26. """
  27. def __init__(self,
  28. character_dict_path,
  29. valid_set,
  30. score_thresh,
  31. mode,
  32. point_gather_mode=None,
  33. **kwargs):
  34. self.character_dict_path = character_dict_path
  35. self.valid_set = valid_set
  36. self.score_thresh = score_thresh
  37. self.mode = mode
  38. self.point_gather_mode = point_gather_mode
  39. # c++ la-nms is faster, but only support python 3.5
  40. self.is_python35 = False
  41. if sys.version_info.major == 3 and sys.version_info.minor == 5:
  42. self.is_python35 = True
  43. def __call__(self, outs_dict, shape_list):
  44. post = PGNet_PostProcess(
  45. self.character_dict_path,
  46. self.valid_set,
  47. self.score_thresh,
  48. outs_dict,
  49. shape_list,
  50. point_gather_mode=self.point_gather_mode)
  51. if self.mode == 'fast':
  52. data = post.pg_postprocess_fast()
  53. else:
  54. data = post.pg_postprocess_slow()
  55. return data