evaluator.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 ..base import BaseEvaluator
  12. from .model_list import MODELS
  13. class ClsEvaluator(BaseEvaluator):
  14. """ Image Classification Model Evaluator """
  15. entities = MODELS
  16. def update_config(self):
  17. """update evalution config
  18. """
  19. if self.eval_config.log_interval:
  20. self.pdx_config.update_log_interval(self.eval_config.log_interval)
  21. if self.pdx_config["Arch"]["name"] == "DistillationModel":
  22. self.pdx_config.update_teacher_model(pretrained=False)
  23. self.pdx_config.update_student_model(pretrained=False)
  24. self.pdx_config.update_dataset(self.global_config.dataset_dir,
  25. "ClsDataset")
  26. self.pdx_config.update_pretrained_weights(self.eval_config.weight_path)
  27. def get_eval_kwargs(self) -> dict:
  28. """get key-value arguments of model evalution function
  29. Returns:
  30. dict: the arguments of evaluation function.
  31. """
  32. return {
  33. "weight_path": self.eval_config.weight_path,
  34. "device": self.get_device(using_device_number=1)
  35. }