__init__.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 json
  15. import os
  16. import os.path as osp
  17. from collections import Counter, defaultdict
  18. from pathlib import Path
  19. from PIL import Image
  20. from ...base import BaseDatasetChecker
  21. from ..model_list import MODELS
  22. from .dataset_src import check, deep_analyse, split_dataset
  23. class TableRecDatasetChecker(BaseDatasetChecker):
  24. """Dataset Checker for Table Recognition Model"""
  25. entities = MODELS
  26. def get_dataset_root(self, dataset_dir: str) -> str:
  27. """find the dataset root dir
  28. Args:
  29. dataset_dir (str): the directory that contain dataset.
  30. Returns:
  31. str: the root directory of dataset.
  32. """
  33. anno_dirs = list(Path(dataset_dir).glob("**/train.txt"))
  34. assert len(anno_dirs) == 1
  35. dataset_dir = anno_dirs[0].parent.as_posix()
  36. return dataset_dir
  37. def convert_dataset(self, src_dataset_dir: str) -> str:
  38. """convert the dataset from other type to specified type
  39. Args:
  40. src_dataset_dir (str): the root directory of dataset.
  41. Returns:
  42. str: the root directory of converted dataset.
  43. """
  44. return src_dataset_dir
  45. def split_dataset(self, src_dataset_dir: str) -> str:
  46. """repartition the train and validation dataset
  47. Args:
  48. src_dataset_dir (str): the root directory of dataset.
  49. Returns:
  50. str: the root directory of splited dataset.
  51. """
  52. return split_dataset(
  53. src_dataset_dir,
  54. self.check_dataset_config.split.train_percent,
  55. self.check_dataset_config.split.val_percent,
  56. )
  57. def check_dataset(self, dataset_dir: str) -> dict:
  58. """check if the dataset meets the specifications and get dataset summary
  59. Args:
  60. dataset_dir (str): the root directory of dataset.
  61. Returns:
  62. dict: dataset summary.
  63. """
  64. return check(dataset_dir, self.output, sample_num=10)
  65. def get_show_type(self) -> str:
  66. """get the show type of dataset
  67. Returns:
  68. str: show type
  69. """
  70. return "image"
  71. def get_dataset_type(self) -> str:
  72. """return the dataset type
  73. Returns:
  74. str: dataset type
  75. """
  76. return "PubTabTableRecDataset"