__init__.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. import os.path as osp
  16. from ...base import BaseDatasetChecker
  17. from .dataset_src import check_dataset, convert_dataset, split_dataset, anaylse_dataset
  18. from ..model_list import MODELS
  19. class SegDatasetChecker(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(self.check_dataset_config.src_dataset_type,
  31. src_dataset_dir)
  32. def split_dataset(self, src_dataset_dir: str) -> str:
  33. """repartition the train and validation dataset
  34. Args:
  35. src_dataset_dir (str): the root directory of dataset.
  36. Returns:
  37. str: the root directory of splited dataset.
  38. """
  39. return split_dataset(src_dataset_dir,
  40. self.check_dataset_config.split.train_percent,
  41. self.check_dataset_config.split.val_percent)
  42. def check_dataset(self, dataset_dir: str,
  43. sample_num: int=sample_num) -> dict:
  44. """check if the dataset meets the specifications and get dataset summary
  45. Args:
  46. dataset_dir (str): the root directory of dataset.
  47. sample_num (int): the number to be sampled.
  48. Returns:
  49. dict: dataset summary.
  50. """
  51. return check_dataset(dataset_dir, self.output, sample_num)
  52. def analyse(self, dataset_dir: str) -> dict:
  53. """deep analyse dataset
  54. Args:
  55. dataset_dir (str): the root directory of dataset.
  56. Returns:
  57. dict: the deep analysis results.
  58. """
  59. return anaylse_dataset(dataset_dir, self.output)
  60. def get_show_type(self) -> str:
  61. """get the show type of dataset
  62. Returns:
  63. str: show type
  64. """
  65. return "image"
  66. def get_dataset_type(self) -> str:
  67. """return the dataset type
  68. Returns:
  69. str: dataset type
  70. """
  71. return "SegDataset"