__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 pathlib import Path
  16. from .dataset_src import check, convert, split_dataset, deep_analyse
  17. from ...base import BaseDatasetChecker
  18. from ..model_list import MODELS
  19. class COCOInstSegDatasetChecker(BaseDatasetChecker):
  20. """Dataset Checker for Instance Segmentation Model"""
  21. entities = MODELS
  22. sample_num = 10
  23. def get_dataset_root(self, dataset_dir: str) -> str:
  24. """find the dataset root dir
  25. Args:
  26. dataset_dir (str): the directory that contain dataset.
  27. Returns:
  28. str: the root directory of dataset.
  29. """
  30. anno_dirs = list(Path(dataset_dir).glob("**/images"))
  31. assert len(anno_dirs) == 1
  32. dataset_dir = anno_dirs[0].parent.as_posix()
  33. return dataset_dir
  34. def convert_dataset(self, src_dataset_dir: str) -> str:
  35. """convert the dataset from other type to specified type
  36. Args:
  37. src_dataset_dir (str): the root directory of dataset.
  38. Returns:
  39. str: the root directory of converted dataset.
  40. """
  41. return convert(
  42. self.check_dataset_config.convert.src_dataset_type, src_dataset_dir
  43. )
  44. def split_dataset(self, src_dataset_dir: str) -> str:
  45. """repartition the train and validation dataset
  46. Args:
  47. src_dataset_dir (str): the root directory of dataset.
  48. Returns:
  49. str: the root directory of splited dataset.
  50. """
  51. return split_dataset(
  52. src_dataset_dir,
  53. self.check_dataset_config.split.train_percent,
  54. self.check_dataset_config.split.val_percent,
  55. )
  56. def check_dataset(self, dataset_dir: str, sample_num: int = sample_num) -> dict:
  57. """check if the dataset meets the specifications and get dataset summary
  58. Args:
  59. dataset_dir (str): the root directory of dataset.
  60. sample_num (int): the number to be sampled.
  61. Returns:
  62. dict: dataset summary.
  63. """
  64. return check(dataset_dir, self.output)
  65. def analyse(self, dataset_dir: str) -> dict:
  66. """deep analyse dataset
  67. Args:
  68. dataset_dir (str): the root directory of dataset.
  69. Returns:
  70. dict: the deep analysis results.
  71. """
  72. return deep_analyse(dataset_dir, self.output)
  73. def get_show_type(self) -> str:
  74. """get the show type of dataset
  75. Returns:
  76. str: show type
  77. """
  78. return "image"
  79. def get_dataset_type(self) -> str:
  80. """return the dataset type
  81. Returns:
  82. str: dataset type
  83. """
  84. return "COCOInstSegDataset"