config.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 os
  15. from ....utils.misc import abspath
  16. from ..ts_base.config import BaseTSConfig
  17. class TSClassifyConfig(BaseTSConfig):
  18. """TS Classify Config"""
  19. def update_dataset(self, dataset_dir: str, dataset_type: str = None):
  20. """
  21. update the dataset
  22. Args:
  23. dataset_dir (str): dataset root path
  24. dataset_type (str, optional): type to set for dataset. Default='TSDataset'
  25. """
  26. if dataset_type is None:
  27. dataset_type = "TSCLSDataset"
  28. dataset_dir = abspath(dataset_dir)
  29. ds_cfg = self._make_custom_dataset_config(dataset_dir)
  30. self.update(ds_cfg)
  31. def update_basic_info(self, info_params: dict):
  32. """
  33. update basic info including time_col, freq, target_cols.
  34. Args:
  35. info_params (dict): update basic info
  36. Raises:
  37. TypeError: if info_params is not dict, raising TypeError
  38. """
  39. if isinstance(info_params, dict):
  40. self.update({"info_params": info_params})
  41. else:
  42. raise TypeError("`info_params` must be a dict.")
  43. def _make_custom_dataset_config(self, dataset_root_path: str):
  44. """construct the dataset config that meets the format requirements
  45. Args:
  46. dataset_root_path (str): the root directory of dataset.
  47. Returns:
  48. dict: the dataset config.
  49. """
  50. ds_cfg = {
  51. "dataset": {
  52. "name": "TSCLSDataset",
  53. "dataset_root": dataset_root_path,
  54. "train_path": os.path.join(dataset_root_path, "train.csv"),
  55. "val_path": os.path.join(dataset_root_path, "val.csv"),
  56. },
  57. }
  58. return ds_cfg