evaluator.py 1.7 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 SegEvaluator(BaseEvaluator):
  18. """ Semantic Segmentation Model Evaluator """
  19. entities = MODELS
  20. def update_config(self):
  21. """update evalution config
  22. """
  23. self.pdx_config.update_dataset(self.global_config.dataset_dir,
  24. "SegDataset")
  25. self.pdx_config.update_pretrained_weights(None, is_backbone=True)
  26. def get_config_path(self, weight_path):
  27. """
  28. get config path
  29. Args:
  30. weight_path (str): The path to the weight
  31. Returns:
  32. config_path (str): The path to the config
  33. """
  34. config_path = Path(weight_path).parent.parent / "config.yaml"
  35. return config_path
  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(),
  44. }