__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # !/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. ################################################################################
  4. #
  5. # Copyright (c) 2024 Baidu.com, Inc. All Rights Reserved
  6. #
  7. ################################################################################
  8. """
  9. Author: PaddlePaddle Authors
  10. """
  11. from pathlib import Path
  12. from ...base import BaseDatasetChecker
  13. from .dataset_src import check, split_dataset, deep_analyse
  14. from ..model_list import MODELS
  15. class ClsDatasetChecker(BaseDatasetChecker):
  16. """Dataset Checker for Image Classification Model
  17. """
  18. entities = MODELS
  19. sample_num = 10
  20. def get_dataset_root(self, dataset_dir: str) -> str:
  21. """find the dataset root dir
  22. Args:
  23. dataset_dir (str): the directory that contain dataset.
  24. Returns:
  25. str: the root directory of dataset.
  26. """
  27. anno_dirs = list(Path(dataset_dir).glob("**/images"))
  28. assert len(anno_dirs) == 1
  29. dataset_dir = anno_dirs[0].parent.as_posix()
  30. return dataset_dir
  31. def convert_dataset(self, src_dataset_dir: str) -> str:
  32. """convert the dataset from other type to specified type
  33. Args:
  34. src_dataset_dir (str): the root directory of dataset.
  35. Returns:
  36. str: the root directory of converted dataset.
  37. """
  38. return src_dataset_dir
  39. def split_dataset(self, src_dataset_dir: str) -> str:
  40. """repartition the train and validation dataset
  41. Args:
  42. src_dataset_dir (str): the root directory of dataset.
  43. Returns:
  44. str: the root directory of splited dataset.
  45. """
  46. return split_dataset(src_dataset_dir,
  47. self.check_dataset_config.split.train_percent,
  48. self.check_dataset_config.split.val_percent)
  49. def check_dataset(self, dataset_dir: str,
  50. sample_num: int=sample_num) -> dict:
  51. """check if the dataset meets the specifications and get dataset summary
  52. Args:
  53. dataset_dir (str): the root directory of dataset.
  54. sample_num (int): the number to be sampled.
  55. Returns:
  56. dict: dataset summary.
  57. """
  58. return check(dataset_dir, self.output)
  59. def analyse(self, dataset_dir: str) -> dict:
  60. """deep analyse dataset
  61. Args:
  62. dataset_dir (str): the root directory of dataset.
  63. Returns:
  64. dict: the deep analysis results.
  65. """
  66. return deep_analyse(dataset_dir, self.output)
  67. def get_show_type(self) -> str:
  68. """get the show type of dataset
  69. Returns:
  70. str: show type
  71. """
  72. return "image"
  73. def get_dataset_type(self) -> str:
  74. """return the dataset type
  75. Returns:
  76. str: dataset type
  77. """
  78. return "ClsDataset"