Datasets:

ArXiv:
License:
davanstrien HF staff commited on
Commit
52fe1d5
1 Parent(s): 86f7abc

draft dataset

Browse files
Files changed (2) hide show
  1. README.md +240 -0
  2. european_art.py +341 -0
README.md ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ - config_name: raw
4
+ features:
5
+ - name: image
6
+ dtype: image
7
+ - name: source
8
+ dtype: string
9
+ - name: width
10
+ dtype: int16
11
+ - name: height
12
+ dtype: int16
13
+ - name: dept
14
+ dtype: int8
15
+ - name: segmented
16
+ dtype: int8
17
+ - name: objects
18
+ list:
19
+ - name: name
20
+ dtype:
21
+ class_label:
22
+ names:
23
+ '0': zebra
24
+ '1': tree
25
+ '2': nude
26
+ '3': crucifixion
27
+ '4': scroll
28
+ '5': head
29
+ '6': swan
30
+ '7': shield
31
+ '8': lily
32
+ '9': mouse
33
+ '10': knight
34
+ '11': dragon
35
+ '12': horn
36
+ '13': dog
37
+ '14': palm
38
+ '15': tiara
39
+ '16': helmet
40
+ '17': sheep
41
+ '18': deer
42
+ '19': person
43
+ '20': sword
44
+ '21': rooster
45
+ '22': bear
46
+ '23': halo
47
+ '24': lion
48
+ '25': monkey
49
+ '26': prayer
50
+ '27': crown of thorns
51
+ '28': elephant
52
+ '29': zucchetto
53
+ '30': unicorn
54
+ '31': holy shroud
55
+ '32': cat
56
+ '33': apple
57
+ '34': banana
58
+ '35': chalice
59
+ '36': bird
60
+ '37': eagle
61
+ '38': pegasus
62
+ '39': crown
63
+ '40': camauro
64
+ '41': saturno
65
+ '42': arrow
66
+ '43': dove
67
+ '44': centaur
68
+ '45': horse
69
+ '46': hands
70
+ '47': skull
71
+ '48': orange
72
+ '49': monk
73
+ '50': trumpet
74
+ '51': key of heaven
75
+ '52': fish
76
+ '53': cow
77
+ '54': angel
78
+ '55': devil
79
+ '56': book
80
+ '57': stole
81
+ '58': butterfly
82
+ '59': serpent
83
+ '60': judith
84
+ '61': mitre
85
+ '62': banner
86
+ '63': donkey
87
+ '64': shepherd
88
+ '65': boat
89
+ '66': god the father
90
+ '67': crozier
91
+ '68': jug
92
+ '69': lance
93
+ - name: pose
94
+ dtype:
95
+ class_label:
96
+ names:
97
+ '0': stand
98
+ '1': sit
99
+ '2': partial
100
+ '3': Unspecified
101
+ '4': squats
102
+ '5': lie
103
+ '6': bend
104
+ '7': fall
105
+ '8': walk
106
+ '9': push
107
+ '10': pray
108
+ '11': undefined
109
+ '12': kneel
110
+ '13': unrecognize
111
+ '14': unknown
112
+ '15': other
113
+ '16': ride
114
+ - name: diffult
115
+ dtype: int32
116
+ - name: xmin
117
+ dtype: float64
118
+ - name: ymin
119
+ dtype: float64
120
+ - name: xmax
121
+ dtype: float64
122
+ - name: ymax
123
+ dtype: float64
124
+ splits:
125
+ - name: train
126
+ num_bytes: 9046918
127
+ num_examples: 15156
128
+ download_size: 18160510195
129
+ dataset_size: 9046918
130
+ - config_name: coco
131
+ features:
132
+ - name: image
133
+ dtype: image
134
+ - name: source
135
+ dtype: string
136
+ - name: width
137
+ dtype: int16
138
+ - name: height
139
+ dtype: int16
140
+ - name: dept
141
+ dtype: int8
142
+ - name: segmented
143
+ dtype: int8
144
+ - name: objects
145
+ list:
146
+ - name: category_id
147
+ dtype:
148
+ class_label:
149
+ names:
150
+ '0': zebra
151
+ '1': tree
152
+ '2': nude
153
+ '3': crucifixion
154
+ '4': scroll
155
+ '5': head
156
+ '6': swan
157
+ '7': shield
158
+ '8': lily
159
+ '9': mouse
160
+ '10': knight
161
+ '11': dragon
162
+ '12': horn
163
+ '13': dog
164
+ '14': palm
165
+ '15': tiara
166
+ '16': helmet
167
+ '17': sheep
168
+ '18': deer
169
+ '19': person
170
+ '20': sword
171
+ '21': rooster
172
+ '22': bear
173
+ '23': halo
174
+ '24': lion
175
+ '25': monkey
176
+ '26': prayer
177
+ '27': crown of thorns
178
+ '28': elephant
179
+ '29': zucchetto
180
+ '30': unicorn
181
+ '31': holy shroud
182
+ '32': cat
183
+ '33': apple
184
+ '34': banana
185
+ '35': chalice
186
+ '36': bird
187
+ '37': eagle
188
+ '38': pegasus
189
+ '39': crown
190
+ '40': camauro
191
+ '41': saturno
192
+ '42': arrow
193
+ '43': dove
194
+ '44': centaur
195
+ '45': horse
196
+ '46': hands
197
+ '47': skull
198
+ '48': orange
199
+ '49': monk
200
+ '50': trumpet
201
+ '51': key of heaven
202
+ '52': fish
203
+ '53': cow
204
+ '54': angel
205
+ '55': devil
206
+ '56': book
207
+ '57': stole
208
+ '58': butterfly
209
+ '59': serpent
210
+ '60': judith
211
+ '61': mitre
212
+ '62': banner
213
+ '63': donkey
214
+ '64': shepherd
215
+ '65': boat
216
+ '66': god the father
217
+ '67': crozier
218
+ '68': jug
219
+ '69': lance
220
+ - name: image_id
221
+ dtype: string
222
+ - name: area
223
+ dtype: int64
224
+ - name: bbox
225
+ sequence: float32
226
+ length: 4
227
+ - name: segmentation
228
+ list:
229
+ list: float32
230
+ - name: iscrowd
231
+ dtype: bool
232
+ - name: image_id
233
+ dtype: string
234
+ splits:
235
+ - name: train
236
+ num_bytes: 8285204
237
+ num_examples: 15156
238
+ download_size: 18160510195
239
+ dataset_size: 8285204
240
+ ---
european_art.py ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """Script for reading 'You Actually Look Twice At it (YALTAi)' dataset."""
15
+
16
+
17
+ import contextlib
18
+ from typing import Dict
19
+ import requests
20
+ import datasets
21
+ from PIL import Image
22
+ from pathlib import Path
23
+ import xml.etree.ElementTree as ET
24
+ from xml.etree.ElementTree import Element
25
+ from typing import Any, List
26
+ from pathlib import PosixPath
27
+
28
+ _CITATION = """\
29
+ @dataset{clerice_thibault_2022_6827706,
30
+ author = {Clérice, Thibault},
31
+ title = {YALTAi: Tabular Dataset},
32
+ month = jul,
33
+ year = 2022,
34
+ publisher = {Zenodo},
35
+ version = {1.0.0},
36
+ doi = {10.5281/zenodo.6827706},
37
+ url = {https://doi.org/10.5281/zenodo.6827706}
38
+ }
39
+ """
40
+
41
+ _DESCRIPTION = """Yalt AI Tabular Dataset"""
42
+
43
+ _HOMEPAGE = "https://doi.org/10.5281/zenodo.6984525"
44
+
45
+ _LICENSE = "Creative Commons Attribution Non Commercial Share Alike 2.0 Generic"
46
+
47
+ ZENODO_API_URL = "https://zenodo.org/api/records/6984525"
48
+
49
+ _CATEGORIES = [
50
+ "zebra",
51
+ "tree",
52
+ "nude",
53
+ "crucifixion",
54
+ "scroll",
55
+ "head",
56
+ "swan",
57
+ "shield",
58
+ "lily",
59
+ "mouse",
60
+ "knight",
61
+ "dragon",
62
+ "horn",
63
+ "dog",
64
+ "palm",
65
+ "tiara",
66
+ "helmet",
67
+ "sheep",
68
+ "deer",
69
+ "person",
70
+ "sword",
71
+ "rooster",
72
+ "bear",
73
+ "halo",
74
+ "lion",
75
+ "monkey",
76
+ "prayer",
77
+ "crown of thorns",
78
+ "elephant",
79
+ "zucchetto",
80
+ "unicorn",
81
+ "holy shroud",
82
+ "cat",
83
+ "apple",
84
+ "banana",
85
+ "chalice",
86
+ "bird",
87
+ "eagle",
88
+ "pegasus",
89
+ "crown",
90
+ "camauro",
91
+ "saturno",
92
+ "arrow",
93
+ "dove",
94
+ "centaur",
95
+ "horse",
96
+ "hands",
97
+ "skull",
98
+ "orange",
99
+ "monk",
100
+ "trumpet",
101
+ "key of heaven",
102
+ "fish",
103
+ "cow",
104
+ "angel",
105
+ "devil",
106
+ "book",
107
+ "stole",
108
+ "butterfly",
109
+ "serpent",
110
+ "judith",
111
+ "mitre",
112
+ "banner",
113
+ "donkey",
114
+ "shepherd",
115
+ "boat",
116
+ "god the father",
117
+ "crozier",
118
+ "jug",
119
+ "lance",
120
+ ]
121
+
122
+ _POSES = [
123
+ "stand",
124
+ "sit",
125
+ "partial",
126
+ "Unspecified",
127
+ "squats",
128
+ "lie",
129
+ "bend",
130
+ "fall",
131
+ "walk",
132
+ "push",
133
+ "pray",
134
+ "undefined",
135
+ "kneel",
136
+ "unrecognize",
137
+ "unknown",
138
+ "other",
139
+ "ride",
140
+ ]
141
+
142
+
143
+ logger = datasets.utils.logging.get_logger(__name__)
144
+
145
+
146
+ def parse_annotation(annotations_object: Element) -> Dict[str, Any]:
147
+ with contextlib.suppress(ValueError):
148
+ name = annotations_object.find("name").text
149
+ pose = annotations_object.find("pose").text
150
+ diffult = int(annotations_object.find("difficult").text)
151
+ bndbox = annotations_object.find("bndbox")
152
+ xmin = float(bndbox.find("xmin").text)
153
+ ymin = float(bndbox.find("ymin").text)
154
+ xmax = float(bndbox.find("xmax").text)
155
+ ymax = float(bndbox.find("ymax").text)
156
+ return {
157
+ "name": name,
158
+ "pose": pose,
159
+ "diffult": diffult,
160
+ "xmin": xmin,
161
+ "ymin": ymin,
162
+ "xmax": xmax,
163
+ "ymax": ymax,
164
+ }
165
+
166
+
167
+ def create_annotations_dict(xmls: List[PosixPath]) -> Dict[str, Any]:
168
+ annotations = {}
169
+ for xml in xmls:
170
+ tree = ET.parse(xml)
171
+ root = tree.getroot()
172
+ filename = root.find("filename").text
173
+ source = root.find("source/database").text
174
+ size = root.find("size")
175
+ width = int(size.find("width").text)
176
+ height = int(size.find("height").text)
177
+ depth = int(size.find("depth").text)
178
+ segmented = root.find("segmented")
179
+ segmented = int(segmented.text) if segmented else None
180
+ annotation_objects = root.findall("object")
181
+ annotation_objects = [
182
+ parse_annotation(annotation) for annotation in annotation_objects
183
+ ]
184
+ annotation_objects = [
185
+ annotation for annotation in annotation_objects if annotation is not None
186
+ ]
187
+ annotations[filename] = {
188
+ "source": source,
189
+ "width": width,
190
+ "height": height,
191
+ "dept": depth,
192
+ "segmented": segmented,
193
+ "objects": annotation_objects,
194
+ }
195
+ return annotations
196
+
197
+
198
+ def get_coco_annotation_from_obj(
199
+ image_id, label, xmin, ymin, xmax, ymax
200
+ ): # adapted from https://github.com/yukkyo/voc2coco/blob/abd05bbfa0740a04bb483862eccea2032bc80e24/voc2coco.py#L60
201
+ category_id = label
202
+ assert xmax > xmin and ymax > ymin, logger.warn(
203
+ f"Box size error !: (xmin, ymin, xmax, ymax): {xmin, ymin, xmax, ymax}"
204
+ )
205
+ o_width = xmax - xmin
206
+ o_height = ymax - ymin
207
+ ann = {
208
+ "image_id": image_id,
209
+ "area": o_width * o_height,
210
+ "iscrowd": 0,
211
+ "bbox": [xmin, ymin, o_width, o_height],
212
+ "category_id": category_id,
213
+ # "ignore": 0,
214
+ "segmentation": [],
215
+ }
216
+ return ann
217
+
218
+
219
+ common_features = features = datasets.Features(
220
+ {
221
+ # "image_id": datasets.Value("int64"),
222
+ "image": datasets.Image(),
223
+ "source": datasets.Value("string"),
224
+ "width": datasets.Value("int16"),
225
+ "height": datasets.Value("int16"),
226
+ "dept": datasets.Value("int8"),
227
+ "segmented": datasets.Value("int8"),
228
+ }
229
+ )
230
+
231
+
232
+ class DeartDatasetConfig(datasets.BuilderConfig):
233
+ """BuilderConfig for YaltAiTabularDataset."""
234
+
235
+ def __init__(self, name, **kwargs):
236
+ """BuilderConfig for YaltAiTabularDataset."""
237
+ super(DeartDatasetConfig, self).__init__(
238
+ version=datasets.Version("1.0.0"), name=name, description=None, **kwargs
239
+ )
240
+
241
+
242
+ class DeartDataset(datasets.GeneratorBasedBuilder):
243
+ """Object Detection for historic manuscripts"""
244
+
245
+ BUILDER_CONFIGS = [
246
+ DeartDatasetConfig("raw"),
247
+ DeartDatasetConfig("coco"),
248
+ ]
249
+
250
+ def _info(self):
251
+ if self.config.name == "coco":
252
+ features = common_features
253
+ features["image_id"] = datasets.Value("string")
254
+ object_dict = {
255
+ "category_id": datasets.ClassLabel(names=_CATEGORIES),
256
+ "image_id": datasets.Value("string"),
257
+ "area": datasets.Value("int64"),
258
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
259
+ "segmentation": [[datasets.Value("float32")]],
260
+ "iscrowd": datasets.Value("bool"),
261
+ }
262
+ features["objects"] = [object_dict]
263
+ if self.config.name == "raw":
264
+ features = common_features
265
+
266
+ object_dict = {
267
+ "name": datasets.ClassLabel(names=_CATEGORIES),
268
+ "pose": datasets.ClassLabel(names=_POSES),
269
+ "diffult": datasets.Value("int32"),
270
+ "xmin": datasets.Value("float64"),
271
+ "ymin": datasets.Value("float64"),
272
+ "xmax": datasets.Value("float64"),
273
+ "ymax": datasets.Value("float64"),
274
+ }
275
+ features["objects"] = [object_dict]
276
+ return datasets.DatasetInfo(
277
+ features=features,
278
+ supervised_keys=None,
279
+ description=_DESCRIPTION,
280
+ homepage=_HOMEPAGE,
281
+ license=_LICENSE,
282
+ citation=_CITATION,
283
+ )
284
+
285
+ def _split_generators(self, dl_manager):
286
+ zenodo_record = requests.get(ZENODO_API_URL).json()
287
+ urls = sorted(
288
+ [
289
+ file["links"]["self"]
290
+ for file in zenodo_record["files"]
291
+ if file["type"] == "zip"
292
+ ]
293
+ )
294
+ annotation_data = urls.pop(0)
295
+ annotation_data = dl_manager.download_and_extract(annotation_data)
296
+
297
+ image_data = dl_manager.download_and_extract(urls)
298
+ return [
299
+ datasets.SplitGenerator(
300
+ name=datasets.Split.TRAIN,
301
+ gen_kwargs={
302
+ "annotations_data": Path(annotation_data),
303
+ "image_data": image_data,
304
+ },
305
+ ),
306
+ ]
307
+
308
+ def _generate_examples(self, annotations_data, image_data):
309
+ xmls = list(annotations_data.rglob("*.xml"))
310
+ annotations_data = create_annotations_dict(xmls)
311
+ count = 0
312
+ for directory in image_data:
313
+ for file in Path(directory).glob("*.jpg"):
314
+ with Image.open(file) as image:
315
+ try:
316
+ if self.config.name == "raw":
317
+ example = annotations_data[file.name]
318
+ example["image"] = image
319
+ count += 1
320
+ yield count, example
321
+ if self.config.name == "coco":
322
+ updated_annotations = []
323
+ example = annotations_data[file.name]
324
+ annotations = example["objects"]
325
+ for annotation in annotations:
326
+ label = annotation["name"]
327
+ xmin, ymin = annotation["xmin"], annotation["ymin"]
328
+ xmax, ymax = annotation["xmax"], annotation["ymax"]
329
+ updated_annotations.append(
330
+ get_coco_annotation_from_obj(
331
+ count, label, xmin, ymin, xmax, ymax
332
+ ),
333
+ )
334
+ example["image"] = image
335
+ example["objects"] = updated_annotations
336
+ example["image_id"] = str(count)
337
+ count += 1
338
+ yield count, example
339
+ except Exception:
340
+ logger.warn(file.name)
341
+ continue