__init__.py 2.8 KB

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