image_unwarping.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 .base import BasicPredictor
  18. class WarpPredictor(BasicPredictor):
  19. entities = MODELS
  20. def _build_components(self):
  21. self._add_component(
  22. [
  23. ReadImage(format="RGB"),
  24. Normalize(mean=0.0, std=1.0, scale=1.0 / 255),
  25. ToCHWImage(),
  26. ]
  27. )
  28. predictor = ImagePredictor(
  29. model_dir=self.model_dir,
  30. model_prefix=self.MODEL_FILE_PREFIX,
  31. option=self.pp_option,
  32. )
  33. self._add_component([predictor, DocTrPostProcess()])
  34. def _pack_res(self, single):
  35. keys = ["img_path", "doctr_img"]
  36. return DocTrResult({key: single[key] for key in keys})