evaluator.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. import os
  15. from ...utils.misc import abspath
  16. from ..base import BaseEvaluator
  17. from .model_list import MODELS
  18. class FaceRecEvaluator(BaseEvaluator):
  19. """Face Recognition Model Evaluator"""
  20. entities = MODELS
  21. def update_config(self):
  22. """update evalution config"""
  23. if self.eval_config.log_interval:
  24. self.pdx_config.update_log_interval(self.eval_config.log_interval)
  25. self.update_dataset_cfg()
  26. self.pdx_config.update_pretrained_weights(self.eval_config.weight_path)
  27. def update_dataset_cfg(self):
  28. val_dataset_dir = abspath(os.path.join(self.global_config.dataset_dir, "val"))
  29. val_list_path = abspath(os.path.join(val_dataset_dir, "pair_label.txt"))
  30. ds_cfg = [
  31. f"DataLoader.Eval.dataset.name=FaceEvalDataset",
  32. f"DataLoader.Eval.dataset.dataset_root={val_dataset_dir}",
  33. f"DataLoader.Eval.dataset.pair_label_path={val_list_path}",
  34. ]
  35. self.pdx_config.update(ds_cfg)
  36. def get_eval_kwargs(self) -> dict:
  37. """get key-value arguments of model evalution function
  38. Returns:
  39. dict: the arguments of evaluation function.
  40. """
  41. return {
  42. "weight_path": self.eval_config.weight_path,
  43. "device": self.get_device(using_device_number=1),
  44. }