config.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ..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 = {
  25. "Train.loader.batch_size_per_card": batch_size,
  26. }
  27. self.update(_cfg)
  28. def update_dataset(self, dataset_path: str, dataset_type=None):
  29. """update dataset settings
  30. Args:
  31. dataset_path (str): the root path of dataset.
  32. dataset_type (str, optional): dataset type. Defaults to None.
  33. Raises:
  34. ValueError: the dataset_type error.
  35. """
  36. dataset_path = abspath(dataset_path)
  37. if dataset_type is None:
  38. dataset_type = "TextDetDataset"
  39. if dataset_type == "TextDetDataset":
  40. _cfg = {
  41. "Train.dataset.name": dataset_type,
  42. "Train.dataset.data_dir": dataset_path,
  43. "Train.dataset.label_file_list": [
  44. os.path.join(dataset_path, "train.txt")
  45. ],
  46. "Eval.dataset.name": dataset_type,
  47. "Eval.dataset.data_dir": dataset_path,
  48. "Eval.dataset.label_file_list": [os.path.join(dataset_path, "val.txt")],
  49. }
  50. self.update(_cfg)
  51. else:
  52. raise ValueError(f"{repr(dataset_type)} is not supported.")