__init__.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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. import os.path as osp
  16. from ...base import BaseDatasetChecker
  17. from ..model_list import MODELS
  18. from .dataset_src import anaylse_dataset, check_dataset, convert_dataset, split_dataset
  19. class UadDatasetChecker(BaseDatasetChecker):
  20. """Dataset Checker for Semantic Segmentation Model"""
  21. entities = MODELS
  22. sample_num = 10
  23. def convert_dataset(self, src_dataset_dir: str) -> str:
  24. """convert the dataset from other type to specified type
  25. Args:
  26. src_dataset_dir (str): the root directory of dataset.
  27. Returns:
  28. str: the root directory of converted dataset.
  29. """
  30. return convert_dataset(
  31. self.check_dataset_config.convert.src_dataset_type, src_dataset_dir
  32. )
  33. def split_dataset(self, src_dataset_dir: str) -> str:
  34. """repartition the train and validation dataset
  35. Args:
  36. src_dataset_dir (str): the root directory of dataset.
  37. Returns:
  38. str: the root directory of splited dataset.
  39. """
  40. return split_dataset(
  41. src_dataset_dir,
  42. self.check_dataset_config.split.train_percent,
  43. self.check_dataset_config.split.val_percent,
  44. )
  45. def check_dataset(self, dataset_dir: str, sample_num: int = sample_num) -> dict:
  46. """check if the dataset meets the specifications and get dataset summary
  47. Args:
  48. dataset_dir (str): the root directory of dataset.
  49. sample_num (int): the number to be sampled.
  50. Returns:
  51. dict: dataset summary.
  52. """
  53. return check_dataset(dataset_dir, self.output, sample_num)
  54. def analyse(self, dataset_dir: str) -> dict:
  55. """deep analyse dataset
  56. Args:
  57. dataset_dir (str): the root directory of dataset.
  58. Returns:
  59. dict: the deep analysis results.
  60. """
  61. return anaylse_dataset(dataset_dir, self.output)
  62. def get_show_type(self) -> str:
  63. """get the show type of dataset
  64. Returns:
  65. str: show type
  66. """
  67. return "image"
  68. def get_dataset_type(self) -> str:
  69. """return the dataset type
  70. Returns:
  71. str: dataset type
  72. """
  73. return "SegDataset"