runner.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TextDetRunner(TextRecRunner):
  17. """Text Detection 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. # `cli_args` and `device` unused
  30. cmd = [self.python, "tools/infer_det.py", "-c", config_path]
  31. return self.run_cmd(cmd, switch_wdir=True, echo=True, silent=False)
  32. def infer(self, config_path: str, cli_args: list, device: str) -> CompletedProcess:
  33. """run predicting using inference model
  34. Args:
  35. config_path (str): the path of config file used to predict.
  36. cli_args (list): the additional parameters.
  37. device (str): unused.
  38. Returns:
  39. CompletedProcess: the result of infering subprocess execution.
  40. """
  41. # `config_path` and `device` unused
  42. cmd = [self.python, "tools/infer/predict_det.py", *cli_args]
  43. return self.run_cmd(cmd, switch_wdir=True, echo=True, silent=False)