evaluator.py 1.9 KB

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