evaluator.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. """
  23. if self.eval_config.log_interval:
  24. self.pdx_config.update_log_interval(self.eval_config.log_interval)
  25. if self.global_config['model']=='LaTeX_OCR_rec':
  26. self.pdx_config.update_dataset(self.global_config.dataset_dir,
  27. "LaTeXOCRDataSet")
  28. else:
  29. self.pdx_config.update_dataset(self.global_config.dataset_dir,
  30. "MSTextRecDataset")
  31. label_dict_path = None
  32. if self.eval_config.get("label_dict_path"):
  33. label_dict_path = self.eval_config.label_dict_path
  34. else:
  35. label_dict_path = Path(
  36. self.eval_config.weight_path).parent / "label_dict.txt"
  37. if not label_dict_path.exists():
  38. label_dict_path = None
  39. if label_dict_path is not None:
  40. self.pdx_config.update_label_dict_path(label_dict_path)
  41. def get_eval_kwargs(self) -> dict:
  42. """get key-value arguments of model evalution function
  43. Returns:
  44. dict: the arguments of evaluation function.
  45. """
  46. return {
  47. "weight_path": self.eval_config.weight_path,
  48. "device": self.get_device()
  49. }