config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ....utils.misc import abspath
  16. from ..text_rec.config import TextRecConfig
  17. class TextDetConfig(TextRecConfig):
  18. """ Text Detection Config """
  19. def update_batch_size(self, batch_size: int):
  20. """update batch size setting
  21. Args:
  22. batch_size (int): the batch size number of training loader to set.
  23. """
  24. _cfg = {'Train.loader.batch_size_per_card': batch_size, }
  25. self.update(_cfg)
  26. def update_dataset(self, dataset_path: str, dataset_type=None):
  27. """update dataset settings
  28. Args:
  29. dataset_path (str): the root path of dataset.
  30. dataset_type (str, optional): dataset type. Defaults to None.
  31. Raises:
  32. ValueError: the dataset_type error.
  33. """
  34. dataset_path = abspath(dataset_path)
  35. if dataset_type is None:
  36. dataset_type = 'TextDetDataset'
  37. if dataset_type == 'TextDetDataset':
  38. _cfg = {
  39. 'Train.dataset.name': dataset_type,
  40. 'Train.dataset.data_dir': dataset_path,
  41. 'Train.dataset.label_file_list':
  42. [os.path.join(dataset_path, 'train.txt')],
  43. 'Eval.dataset.name': dataset_type,
  44. 'Eval.dataset.data_dir': dataset_path,
  45. 'Eval.dataset.label_file_list':
  46. [os.path.join(dataset_path, 'val.txt')]
  47. }
  48. self.update(_cfg)
  49. else:
  50. raise ValueError(f"{repr(dataset_type)} is not supported.")