jinho8345 commited on
Commit
9078e85
·
1 Parent(s): 8d22c51

format script, rename classes

Browse files
Files changed (1) hide show
  1. cdip-annotations-formnet.py +31 -31
cdip-annotations-formnet.py CHANGED
@@ -1,36 +1,33 @@
1
  import json
2
  import os
3
  from pathlib import Path
4
-
5
  from PIL import Image
6
-
7
  import datasets
8
 
9
  logger = datasets.logging.get_logger(__name__)
 
 
 
 
 
 
 
10
  def load_json(json_path):
11
  with open(json_path, "r") as f:
12
  data = json.load(f)
13
  return data
14
 
15
 
16
-
17
- _CITATION = """\
18
- @article{Jaume2019FUNSDAD,
19
- title={FUNSD: A Dataset for Form Understanding in Noisy Scanned Documents},
20
- author={Guillaume Jaume and H. K. Ekenel and J. Thiran},
21
- journal={2019 International Conference on Document Analysis and Recognition Workshops (ICDARW)},
22
- year={2019},
23
- volume={2},
24
- pages={1-6}
25
  }
26
  """
27
 
28
  _DESCRIPTION = """\
29
- https://guillaumejaume.github.io/FUNSD/
30
  """
31
 
32
 
33
- class CDIPOcrConfig(datasets.BuilderConfig):
34
  """BuilderConfig for FUNSD"""
35
 
36
  def __init__(self, **kwargs):
@@ -38,14 +35,18 @@ class CDIPOcrConfig(datasets.BuilderConfig):
38
  Args:
39
  **kwargs: keyword arguments forwarded to super.
40
  """
41
- super(CDIPOcrConfig, self).__init__(**kwargs)
42
 
43
 
44
- class CDIPOcr(datasets.GeneratorBasedBuilder):
45
  """Conll2003 dataset."""
46
 
47
  BUILDER_CONFIGS = [
48
- CDIPOcrConfig(name="CDIP_OCR", version=datasets.Version("1.0.0"), description="CDIP OCR"),
 
 
 
 
49
  ]
50
 
51
  def _info(self):
@@ -55,7 +56,9 @@ class CDIPOcr(datasets.GeneratorBasedBuilder):
55
  {
56
  "id": datasets.Value("string"),
57
  "words": datasets.Sequence(datasets.Value("string")),
58
- "bboxes": datasets.Sequence(datasets.Sequence(datasets.Value("int64"))),
 
 
59
  }
60
  ),
61
  )
@@ -65,7 +68,10 @@ class CDIPOcr(datasets.GeneratorBasedBuilder):
65
  # downloaded_file = dl_manager.download_and_extract("https://guillaumejaume.github.io/FUNSD/dataset.zip")
66
  return [
67
  datasets.SplitGenerator(
68
- name=datasets.Split.TRAIN, gen_kwargs={"annot_root": f"/home/jinho/datasets/IIT-CDIP-annotations"}
 
 
 
69
  ),
70
  ]
71
 
@@ -73,22 +79,12 @@ class CDIPOcr(datasets.GeneratorBasedBuilder):
73
  logger.info("⏳ Generating examples from = %s", annot_root)
74
 
75
  cnt = 0
76
- start_from = 'o.a.f'
77
- start_flag = False
78
- for subfolder in sorted(list(os.listdir(annot_root))): # b.a, b.b
79
  subfolder_path = os.path.join(annot_root, subfolder)
80
  logger.info(f"{subfolder = }")
81
 
82
- for json_folder in os.listdir(subfolder_path): # b.a.p, b.a.c
83
  json_folder_path = os.path.join(subfolder_path, json_folder)
84
-
85
-
86
- if not start_flag:
87
- if start_from != json_folder:
88
- continue
89
- else:
90
- start_flag = True
91
-
92
  json_paths = list(Path(json_folder_path).glob("**/*.json"))
93
  logger.info(f"{json_folder, len(json_paths) = }")
94
 
@@ -106,4 +102,8 @@ class CDIPOcr(datasets.GeneratorBasedBuilder):
106
  bboxes.extend(line_bboxes)
107
  cnt += 1
108
 
109
- yield cnt, {"id": str(json_path.name), "words": words, "bboxes": bboxes }
 
 
 
 
 
1
  import json
2
  import os
3
  from pathlib import Path
 
4
  from PIL import Image
 
5
  import datasets
6
 
7
  logger = datasets.logging.get_logger(__name__)
8
+
9
+
10
+ """
11
+ - o.a/o.a.f/0011656044-53.layout.json file has been deleted because it was empty
12
+
13
+ """
14
+
15
  def load_json(json_path):
16
  with open(json_path, "r") as f:
17
  data = json.load(f)
18
  return data
19
 
20
 
21
+ _CITATION = """
 
 
 
 
 
 
 
 
22
  }
23
  """
24
 
25
  _DESCRIPTION = """\
26
+ https://zenodo.org/record/6540454
27
  """
28
 
29
 
30
+ class CDIPAnnotationsConfig(datasets.BuilderConfig):
31
  """BuilderConfig for FUNSD"""
32
 
33
  def __init__(self, **kwargs):
 
35
  Args:
36
  **kwargs: keyword arguments forwarded to super.
37
  """
38
+ super(CDIPAnnotationsConfig, self).__init__(**kwargs)
39
 
40
 
41
+ class CDIPAnnotations(datasets.GeneratorBasedBuilder):
42
  """Conll2003 dataset."""
43
 
44
  BUILDER_CONFIGS = [
45
+ CDIPAnnotationsConfig(
46
+ name="cdip-annotations",
47
+ version=datasets.Version("1.0.0"),
48
+ description="CDIP Annotations",
49
+ ),
50
  ]
51
 
52
  def _info(self):
 
56
  {
57
  "id": datasets.Value("string"),
58
  "words": datasets.Sequence(datasets.Value("string")),
59
+ "bboxes": datasets.Sequence(
60
+ datasets.Sequence(datasets.Value("int64"))
61
+ ),
62
  }
63
  ),
64
  )
 
68
  # downloaded_file = dl_manager.download_and_extract("https://guillaumejaume.github.io/FUNSD/dataset.zip")
69
  return [
70
  datasets.SplitGenerator(
71
+ name=datasets.Split.TRAIN,
72
+ gen_kwargs={
73
+ "annot_root": f"/home/jinho/datasets/IIT-CDIP-annotations"
74
+ },
75
  ),
76
  ]
77
 
 
79
  logger.info("⏳ Generating examples from = %s", annot_root)
80
 
81
  cnt = 0
82
+ for subfolder in sorted(list(os.listdir(annot_root)))[:1]: # b.a, b.b
 
 
83
  subfolder_path = os.path.join(annot_root, subfolder)
84
  logger.info(f"{subfolder = }")
85
 
86
+ for json_folder in os.listdir(subfolder_path)[:2]: # b.a.p, b.a.c
87
  json_folder_path = os.path.join(subfolder_path, json_folder)
 
 
 
 
 
 
 
 
88
  json_paths = list(Path(json_folder_path).glob("**/*.json"))
89
  logger.info(f"{json_folder, len(json_paths) = }")
90
 
 
102
  bboxes.extend(line_bboxes)
103
  cnt += 1
104
 
105
+ yield cnt, {
106
+ "id": str(json_path.name),
107
+ "words": words,
108
+ "bboxes": bboxes,
109
+ }