pg_postprocess.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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__(
  28. self,
  29. character_dict_path,
  30. valid_set,
  31. score_thresh,
  32. mode,
  33. point_gather_mode=None,
  34. **kwargs,
  35. ):
  36. self.character_dict_path = character_dict_path
  37. self.valid_set = valid_set
  38. self.score_thresh = score_thresh
  39. self.mode = mode
  40. self.point_gather_mode = point_gather_mode
  41. # c++ la-nms is faster, but only support python 3.5
  42. self.is_python35 = False
  43. if sys.version_info.major == 3 and sys.version_info.minor == 5:
  44. self.is_python35 = True
  45. def __call__(self, outs_dict, shape_list):
  46. post = PGNet_PostProcess(
  47. self.character_dict_path,
  48. self.valid_set,
  49. self.score_thresh,
  50. outs_dict,
  51. shape_list,
  52. point_gather_mode=self.point_gather_mode,
  53. )
  54. if self.mode == "fast":
  55. data = post.pg_postprocess_fast()
  56. else:
  57. data = post.pg_postprocess_slow()
  58. return data