evaluator.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # !/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. ################################################################################
  4. #
  5. # Copyright (c) 2024 Baidu.com, Inc. All Rights Reserved
  6. #
  7. ################################################################################
  8. """
  9. Author: PaddlePaddle Authors
  10. """
  11. from pathlib import Path
  12. from ..base.evaluator import BaseEvaluator
  13. from .support_models import SUPPORT_MODELS
  14. class TextRecEvaluator(BaseEvaluator):
  15. """ Text Recognition Model Evaluator """
  16. support_models = SUPPORT_MODELS
  17. def update_config(self):
  18. """update evalution config
  19. """
  20. if self.eval_config.log_interval:
  21. self.pdx_config.update_log_interval(self.eval_config.log_interval)
  22. self.pdx_config.update_dataset(self.global_config.dataset_dir,
  23. "MSTextRecDataset")
  24. label_dict_path = None
  25. if self.eval_config.get("label_dict_path"):
  26. label_dict_path = self.eval_config.label_dict_path
  27. else:
  28. label_dict_path = Path(
  29. self.eval_config.weight_path).parent / "label_dict.txt"
  30. if not label_dict_path.exists():
  31. label_dict_path = None
  32. if label_dict_path is not None:
  33. self.pdx_config.update_label_dict_path(label_dict_path)
  34. def get_eval_kwargs(self) -> dict:
  35. """get key-value arguments of model evalution function
  36. Returns:
  37. dict: the arguments of evaluation function.
  38. """
  39. return {
  40. "weight_path": self.eval_config.weight_path,
  41. "device": self.get_device()
  42. }