image_unwarping.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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 ...modules.image_unwarping.model_list import MODELS
  15. from ..components import *
  16. from ..results import DocTrResult
  17. from ..utils.process_hook import batchable_method
  18. from .base import CVPredictor
  19. class WarpPredictor(CVPredictor):
  20. entities = MODELS
  21. def _build_components(self):
  22. self._add_component(
  23. [
  24. ReadImage(format="RGB"),
  25. Normalize(mean=0.0, std=1.0, scale=1.0 / 255),
  26. ToCHWImage(),
  27. ]
  28. )
  29. predictor = ImagePredictor(
  30. model_dir=self.model_dir,
  31. model_prefix=self.MODEL_FILE_PREFIX,
  32. option=self.pp_option,
  33. )
  34. self._add_component([("Predictor", predictor), DocTrPostProcess()])
  35. @batchable_method
  36. def _pack_res(self, single):
  37. keys = ["img_path", "doctr_img"]
  38. return DocTrResult({key: single[key] for key in keys})