runner.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) 2024 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 ...base.utils.subprocess import CompletedProcess
  15. from ..text_rec.runner import TextRecRunner
  16. class TableRecRunner(TextRecRunner):
  17. """Table Recognition Runner"""
  18. def predict(
  19. self, config_path: str, cli_args: list, device: str
  20. ) -> CompletedProcess:
  21. """run predicting using dynamic mode
  22. Args:
  23. config_path (str): the config file path used to predict.
  24. cli_args (list): the additional parameters.
  25. device (str): unused.
  26. Returns:
  27. CompletedProcess: the result of predicting subprocess execution.
  28. """
  29. cmd = [self.python, "tools/infer_table.py", "-c", config_path]
  30. return self.run_cmd(cmd, switch_wdir=True, echo=True, silent=False)
  31. def infer(self, config_path: str, cli_args: list, device: str) -> CompletedProcess:
  32. """run predicting using inference model
  33. Args:
  34. config_path (str): the path of config file used to predict.
  35. cli_args (list): the additional parameters.
  36. device (str): unused.
  37. Returns:
  38. CompletedProcess: the result of infering subprocess execution.
  39. """
  40. cmd = [self.python, "ppstructure/table/predict_structure.py", *cli_args]
  41. return self.run_cmd(cmd, switch_wdir=True, echo=True, silent=False)