__init__.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. import os
  12. import os.path as osp
  13. from collections import defaultdict, Counter
  14. from PIL import Image
  15. import json
  16. from ...base import BaseDatasetChecker
  17. from .dataset_src import check, convert, split_dataset, deep_analyse
  18. from ..model_list import MODELS
  19. class TSADDatasetChecker(BaseDatasetChecker):
  20. """Dataset Checker for TS Anomaly Detection Model
  21. """
  22. entities = MODELS
  23. sample_num = 10
  24. def convert_dataset(self, src_dataset_dir: str) -> str:
  25. """convert the dataset from other type to specified type
  26. Args:
  27. src_dataset_dir (str): the root directory of dataset.
  28. Returns:
  29. str: the root directory of converted dataset.
  30. """
  31. return convert(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_dir, self.output)
  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 deep_analyse(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 "csv"
  66. def get_dataset_type(self) -> str:
  67. """return the dataset type
  68. Returns:
  69. str: dataset type
  70. """
  71. return "TSADDataset"