Datasets:

Modalities:
Image
Text
Formats:
parquet
Libraries:
Datasets
Dask
License:
Thibault Clérice commited on
Commit
f3b4c2e
0 Parent(s):

First loading attempt

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. .gitignore +2 -0
  3. LADaS.py +115 -0
  4. README.md +11 -0
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ data.tar.gz filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ env
2
+ .idea
LADaS.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import os
3
+ import yaml
4
+ import datasets
5
+ from PIL import Image
6
+
7
+
8
+ _VERSION = "2024-06-04"
9
+ _URL = f"https://github.com/DEFI-COLaF/LADaS/archive/refs/tags/{_VERSION}.tar.gz"
10
+ _HOMEPAGE = "https://github.com/DEFI-COLaF/LADaS"
11
+ _LICENSE = "CC BY 4.0"
12
+ _CITATION = """\
13
+ @misc{Clerice_Layout_Analysis_Dataset,
14
+ author = {Clérice, Thibault and Janès, Juliette and Scheithauer, Hugo and Bénière, Sarah and Langlais, Pierre-Carl and Romary, Laurent and Sagot, Benoit and Bougrelle, Roxane},
15
+ title = {{Layout Analysis Dataset with SegmOnto (LADaS)}},
16
+ url = {https://github.com/DEFI-COLaF/LADaS}
17
+ }
18
+ """
19
+
20
+ _CATEGORIES = ['AdvertisementZone', 'DigitizationArtefactZone', 'DropCapitalZone', 'FigureZone', 'FigureZone-FigDesc', 'FigureZone-Head', 'GraphicZone', 'GraphicZone-Decoration', 'GraphicZone-FigDesc', 'GraphicZone-Head', 'GraphicZone-Maths', 'GraphicZone-Part', 'GraphicZone-TextualContent', 'MainZone-Date', 'MainZone-Entry', 'MainZone-Entry-Continued', 'MainZone-Form', 'MainZone-Head', 'MainZone-Lg', 'MainZone-Lg-Continued', 'MainZone-List', 'MainZone-List-Continued', 'MainZone-Other', 'MainZone-P', 'MainZone-P-Continued', 'MainZone-Signature', 'MainZone-Sp', 'MainZone-Sp-Continued', 'MarginTextZone-ManuscriptAddendum', 'MarginTextZone-Notes', 'MarginTextZone-Notes-Continued', 'NumberingZone', 'PageTitleZone', 'PageTitleZone-Index', 'QuireMarkZone', 'RunningTitleZone', 'StampZone', 'StampZone-Sticker', 'TableZone', 'TableZone-Continued', 'TableZone-Head']
21
+
22
+
23
+ class LadasConfig(datasets.BuilderConfig):
24
+ """Builder Config for LADaS"""
25
+ def __init__(self, *args, **kwargs):
26
+ super().__init__(*args, **kwargs)
27
+
28
+
29
+ class LadasDataset(datasets.GeneratorBasedBuilder):
30
+ VERSION = datasets.Version(_VERSION.replace("-", "."))
31
+ BUILDER_CONFIGS = [
32
+ LadasConfig(
33
+ name="full",
34
+ description="Full version of the dataset"
35
+ )
36
+ ]
37
+
38
+ def _info(self) -> datasets.DatasetInfo:
39
+ features = datasets.Features({
40
+ "image_path": datasets.Value("string"),
41
+ "image": datasets.Image(),
42
+ # "width": datasets.Value("int32"),
43
+ # "height": datasets.Value("int32"),
44
+ "objects": datasets.Sequence(
45
+ {
46
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
47
+ "category": datasets.ClassLabel(names=_CATEGORIES),
48
+ }
49
+ )
50
+ })
51
+ return datasets.DatasetInfo(
52
+ features=features,
53
+ homepage=_HOMEPAGE,
54
+ citation=_CITATION,
55
+ license=_LICENSE
56
+ )
57
+
58
+ def _split_generators(self, dl_manager):
59
+ urls_to_download = _URL
60
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
61
+ return [
62
+ datasets.SplitGenerator(
63
+ name=datasets.Split.TRAIN,
64
+ gen_kwargs={
65
+ "local_dir": downloaded_files,
66
+ "split": "train"
67
+ },
68
+ ),
69
+ datasets.SplitGenerator(
70
+ name=datasets.Split.VALIDATION,
71
+ gen_kwargs={
72
+ "local_dir": downloaded_files,
73
+ "split": "valid"
74
+ },
75
+ ),
76
+ datasets.SplitGenerator(
77
+ name=datasets.Split.TEST,
78
+ gen_kwargs={
79
+ "local_dir": downloaded_files,
80
+ "split": "test"
81
+ },
82
+ ),
83
+ ]
84
+
85
+ def _generate_examples(self, local_dir: str, split: str):
86
+
87
+ idx = 0
88
+
89
+ for file in glob.glob(os.path.join(local_dir, "*", "data", "*", split, "labels", "*.txt")):
90
+ objects = []
91
+ with open(file) as f:
92
+ for line in f:
93
+ cls, *bbox = line.strip().split()
94
+ objects.append({"category": _CATEGORIES[int(cls)], "bbox": list(map(float, bbox))})
95
+
96
+ image_path = os.path.normpath(file).split(os.sep)
97
+ image_path = os.path.join(*image_path[:-2], "images", image_path[-1].replace(".txt", ".jpg"))
98
+ if file.startswith("/") and not image_path.startswith("/"):
99
+ image_path = "/" + image_path
100
+
101
+ with open(image_path, "rb") as f:
102
+ image_bytes = f.read()
103
+ f.seek(0)
104
+
105
+ with Image.open(image_path) as im:
106
+ width, height = im.size
107
+
108
+ yield idx, {
109
+ "image_id": f"{image_path[-4]}/{image_path[-1]}",
110
+ "image": {"path": image_path, "bytes": image_bytes},
111
+ "width": width,
112
+ "height": height,
113
+ "objects": objects,
114
+ }
115
+ idx += 1
README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ task_categories:
3
+ - object-detection
4
+ license: cc-by-4.0
5
+ pretty_name: LADaS
6
+ size_categories:
7
+ - 1K<n<10K
8
+ ---
9
+
10
+ # LADaS: Layout Analysis Dataset with Segmonto
11
+