config.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 TableRecConfig(TextRecConfig):
  18. """Table Recognition Config"""
  19. def update_dataset(self, dataset_path: str, dataset_type: str = None):
  20. """update dataset settings
  21. Args:
  22. dataset_path (str): the root path of dataset.
  23. dataset_type (str, optional): dataset type. Defaults to None.
  24. Raises:
  25. ValueError: the dataset_type error.
  26. """
  27. dataset_path = abspath(dataset_path)
  28. if dataset_type is None:
  29. dataset_type = "PubTabTableRecDataset"
  30. if dataset_type == "PubTabTableRecDataset":
  31. _cfg = {
  32. "Train.dataset.name": dataset_type,
  33. "Train.dataset.data_dir": dataset_path,
  34. "Train.dataset.label_file_list": [
  35. os.path.join(dataset_path, "train.txt")
  36. ],
  37. "Eval.dataset.name": dataset_type,
  38. "Eval.dataset.data_dir": dataset_path,
  39. "Eval.dataset.label_file_list": [os.path.join(dataset_path, "val.txt")],
  40. }
  41. self.update(_cfg)
  42. else:
  43. raise ValueError(f"{repr(dataset_type)} is not supported.")
  44. def _get_infer_shape(self):
  45. """get resize scale of ResizeImg operation in the evaluation
  46. Returns:
  47. str: resize scale, i.e. `Eval.dataset.transforms.ResizeTableImage.max_len`
  48. """
  49. size = None
  50. transforms = self.dict["Eval"]["dataset"]["transforms"]
  51. for op in transforms:
  52. if list(op)[0] == "ResizeTableImage":
  53. size = op["ResizeTableImage"]["max_len"]
  54. return size