evaluator.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 pathlib import Path
  15. from ..base import BaseEvaluator
  16. from .model_list import MODELS
  17. class TextRecEvaluator(BaseEvaluator):
  18. """Text Recognition Model Evaluator"""
  19. entities = MODELS
  20. def update_config(self):
  21. """update evalution config"""
  22. if self.eval_config.log_interval:
  23. self.pdx_config.update_log_interval(self.eval_config.log_interval)
  24. if self.global_config["model"] == "LaTeX_OCR_rec":
  25. self.pdx_config.update_dataset(
  26. self.global_config.dataset_dir, "LaTeXOCRDataSet"
  27. )
  28. elif "PP-OCRv3" in self.global_config["model"]:
  29. self.pdx_config.update_dataset(
  30. self.global_config.dataset_dir, "SimpleDataSet"
  31. )
  32. else:
  33. self.pdx_config.update_dataset(
  34. self.global_config.dataset_dir, "MSTextRecDataset"
  35. )
  36. label_dict_path = None
  37. if self.eval_config.get("label_dict_path"):
  38. label_dict_path = self.eval_config.label_dict_path
  39. else:
  40. label_dict_path = (
  41. Path(self.eval_config.weight_path).parent / "label_dict.txt"
  42. )
  43. if not label_dict_path.exists():
  44. label_dict_path = None
  45. if label_dict_path is not None:
  46. self.pdx_config.update_label_dict_path(label_dict_path)
  47. def get_eval_kwargs(self) -> dict:
  48. """get key-value arguments of model evalution function
  49. Returns:
  50. dict: the arguments of evaluation function.
  51. """
  52. return {
  53. "weight_path": self.eval_config.weight_path,
  54. "device": self.get_device(),
  55. }