__init__.py 3.2 KB

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