__init__.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. from ...base import BaseDatasetChecker
  15. from .dataset_src import check, split_dataset, deep_analyse, convert
  16. from ..model_list import MODELS
  17. class FormulaRecDatasetChecker(BaseDatasetChecker):
  18. """Dataset Checker for Text Recognition Model"""
  19. entities = MODELS
  20. sample_num = 10
  21. def convert_dataset(self, src_dataset_dir: str) -> str:
  22. """convert the dataset from other type to specified type
  23. Args:
  24. src_dataset_dir (str): the root directory of dataset.
  25. Returns:
  26. str: the root directory of converted dataset.
  27. """
  28. return convert(
  29. self.check_dataset_config.convert.src_dataset_type, src_dataset_dir
  30. )
  31. def split_dataset(self, src_dataset_dir: str) -> str:
  32. """repartition the train and validation dataset
  33. Args:
  34. src_dataset_dir (str): the root directory of dataset.
  35. Returns:
  36. str: the root directory of splited dataset.
  37. """
  38. return split_dataset(
  39. src_dataset_dir,
  40. self.check_dataset_config.split.train_percent,
  41. self.check_dataset_config.split.val_percent,
  42. )
  43. def check_dataset(self, dataset_dir: str, sample_num: int = sample_num) -> dict:
  44. """check if the dataset meets the specifications and get dataset summary
  45. Args:
  46. dataset_dir (str): the root directory of dataset.
  47. sample_num (int): the number to be sampled.
  48. Returns:
  49. dict: dataset summary.
  50. """
  51. return check(
  52. dataset_dir,
  53. self.global_config.output,
  54. sample_num=10,
  55. dataset_type=self.get_dataset_type(),
  56. )
  57. def analyse(self, dataset_dir: str) -> dict:
  58. """deep analyse dataset
  59. Args:
  60. dataset_dir (str): the root directory of dataset.
  61. Returns:
  62. dict: the deep analysis results.
  63. """
  64. datatype = "FormulaRecDataset"
  65. return deep_analyse(dataset_dir, self.output, datatype=datatype)
  66. def get_show_type(self) -> str:
  67. """get the show type of dataset
  68. Returns:
  69. str: show type
  70. """
  71. return "image"
  72. def get_dataset_type(self) -> str:
  73. """return the dataset type
  74. Returns:
  75. str: dataset type
  76. """
  77. return "FormulaRecDataset"