davanstrien HF staff commited on
Commit
83f676b
·
verified ·
1 Parent(s): 3658222

Convert dataset to Parquet (#3)

Browse files

- Convert dataset to Parquet (a857834bdbc516db7107bba207687b9d003c45da)
- Add 'image-classification' config data files (eff8b50c544c301b74b1c0ffda6a6fb7c063e303)
- Add 'image-matching' config data files (b211993610e3bc6b7a00305d0ba0931879b6724f)
- Delete legacy dataset_infos.json (263d47096e5fdae8f1b3a057b2e36832bc7f9d53)
- Delete loading script (8bc1b3bfc842e742181048333ddd158269e5b8ae)
- Delete data file (1481eec5136854644430b285d361448a244cd89f)

README.md CHANGED
@@ -17,6 +17,85 @@ task_categories:
17
  - image-classification
18
  task_ids:
19
  - multi-class-image-classification
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  ---
21
 
22
  # Dataset Card for National Library of Scotland Chapbook Illustrations
 
17
  - image-classification
18
  task_ids:
19
  - multi-class-image-classification
20
+ configs:
21
+ - config_name: illustration-detection
22
+ data_files:
23
+ - split: train
24
+ path: illustration-detection/train-*
25
+ - config_name: image-classification
26
+ data_files:
27
+ - split: train
28
+ path: image-classification/train-*
29
+ - config_name: image-matching
30
+ data_files:
31
+ - split: train
32
+ path: image-matching/train-*
33
+ dataset_info:
34
+ - config_name: illustration-detection
35
+ features:
36
+ - name: image_id
37
+ dtype: int64
38
+ - name: image
39
+ dtype: image
40
+ - name: width
41
+ dtype: int32
42
+ - name: height
43
+ dtype: int32
44
+ - name: objects
45
+ list:
46
+ - name: category_id
47
+ dtype:
48
+ class_label:
49
+ names:
50
+ '0': early_printed_illustration
51
+ - name: image_id
52
+ dtype: string
53
+ - name: id
54
+ dtype: int64
55
+ - name: area
56
+ dtype: int64
57
+ - name: bbox
58
+ sequence: float32
59
+ length: 4
60
+ - name: segmentation
61
+ list:
62
+ list: float32
63
+ - name: iscrowd
64
+ dtype: bool
65
+ splits:
66
+ - name: train
67
+ num_bytes: 891349324.66
68
+ num_examples: 7258
69
+ download_size: 946686062
70
+ dataset_size: 891349324.66
71
+ - config_name: image-classification
72
+ features:
73
+ - name: image
74
+ dtype: image
75
+ - name: label
76
+ dtype:
77
+ class_label:
78
+ names:
79
+ '0': not-illustrated
80
+ '1': illustrated
81
+ splits:
82
+ - name: train
83
+ num_bytes: 890918774.66
84
+ num_examples: 7258
85
+ download_size: 946221148
86
+ dataset_size: 890918774.66
87
+ - config_name: image-matching
88
+ features:
89
+ - name: image
90
+ dtype: image
91
+ - name: group-label
92
+ dtype: int32
93
+ splits:
94
+ - name: train
95
+ num_bytes: 890890686.66
96
+ num_examples: 7258
97
+ download_size: 946222608
98
+ dataset_size: 890890686.66
99
  ---
100
 
101
  # Dataset Card for National Library of Scotland Chapbook Illustrations
dataset_infos.json DELETED
@@ -1 +0,0 @@
1
- {"illustration_detection": {"description": "TODO", "citation": "TODO", "homepage": "TODO", "license": "Public Domain Mark 1.0", "features": {"image_id": {"dtype": "int64", "id": null, "_type": "Value"}, "image": {"decode": true, "id": null, "_type": "Image"}, "width": {"dtype": "int32", "id": null, "_type": "Value"}, "height": {"dtype": "int32", "id": null, "_type": "Value"}, "objects": [{"category_id": {"num_classes": 1, "names": ["early_printed_illustration"], "id": null, "_type": "ClassLabel"}, "image_id": {"dtype": "string", "id": null, "_type": "Value"}, "id": {"dtype": "int64", "id": null, "_type": "Value"}, "area": {"dtype": "int64", "id": null, "_type": "Value"}, "bbox": {"feature": {"dtype": "float32", "id": null, "_type": "Value"}, "length": 4, "id": null, "_type": "Sequence"}, "segmentation": [[{"dtype": "float32", "id": null, "_type": "Value"}]], "iscrowd": {"dtype": "bool", "id": null, "_type": "Value"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "nls_chapbook_illustrations", "config_name": "illustration_detection", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1861271, "num_examples": 7258, "dataset_name": "nls_chapbook_illustrations"}}, "download_checksums": {"https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip": {"num_bytes": 6754994277, "checksum": "ead1ce3f59ad561025235656848024049bae635eadb7e191048bc990d32e85f8"}, "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json": {"num_bytes": 1860557, "checksum": "edfbdaa4123c40b8a90472e5ab7664b9e22c25cdfbf1a0925f5820e5cc4d4275"}}, "download_size": 6756854834, "post_processing_size": null, "dataset_size": 1861271, "size_in_bytes": 6758716105}, "image_classification": {"description": "TODO", "citation": "TODO", "homepage": "TODO", "license": "Public Domain Mark 1.0", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "label": {"num_classes": 2, "names": ["not-illustrated", "illustrated"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "nls_chapbook_illustrations", "config_name": "image_classification", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1430734, "num_examples": 7258, "dataset_name": "nls_chapbook_illustrations"}}, "download_checksums": {"https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip": {"num_bytes": 6754994277, "checksum": "ead1ce3f59ad561025235656848024049bae635eadb7e191048bc990d32e85f8"}, "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json": {"num_bytes": 1860557, "checksum": "edfbdaa4123c40b8a90472e5ab7664b9e22c25cdfbf1a0925f5820e5cc4d4275"}}, "download_size": 6756854834, "post_processing_size": null, "dataset_size": 1430734, "size_in_bytes": 6758285568}, "illustration-detection": {"description": "TODO", "citation": "TODO", "homepage": "TODO", "license": "Public Domain Mark 1.0", "features": {"image_id": {"dtype": "int64", "id": null, "_type": "Value"}, "image": {"decode": true, "id": null, "_type": "Image"}, "width": {"dtype": "int32", "id": null, "_type": "Value"}, "height": {"dtype": "int32", "id": null, "_type": "Value"}, "objects": [{"category_id": {"num_classes": 1, "names": ["early_printed_illustration"], "id": null, "_type": "ClassLabel"}, "image_id": {"dtype": "string", "id": null, "_type": "Value"}, "id": {"dtype": "int64", "id": null, "_type": "Value"}, "area": {"dtype": "int64", "id": null, "_type": "Value"}, "bbox": {"feature": {"dtype": "float32", "id": null, "_type": "Value"}, "length": 4, "id": null, "_type": "Sequence"}, "segmentation": [[{"dtype": "float32", "id": null, "_type": "Value"}]], "iscrowd": {"dtype": "bool", "id": null, "_type": "Value"}}]}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "nls_chapbook_illustrations", "config_name": "illustration-detection", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1861271, "num_examples": 7258, "dataset_name": "nls_chapbook_illustrations"}}, "download_checksums": {"https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip": {"num_bytes": 6754994277, "checksum": "ead1ce3f59ad561025235656848024049bae635eadb7e191048bc990d32e85f8"}, "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json": {"num_bytes": 1860557, "checksum": "edfbdaa4123c40b8a90472e5ab7664b9e22c25cdfbf1a0925f5820e5cc4d4275"}, "illustration-group-specifications[83].csv": {"num_bytes": 163406, "checksum": "f412e2e8bfafd2d204167d8155dd5c891c809f1bb2ac8e93d2cee7917532faf0"}}, "download_size": 6757018240, "post_processing_size": null, "dataset_size": 1861271, "size_in_bytes": 6758879511}, "image-classification": {"description": "TODO", "citation": "TODO", "homepage": "TODO", "license": "Public Domain Mark 1.0", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "label": {"num_classes": 2, "names": ["not-illustrated", "illustrated"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "nls_chapbook_illustrations", "config_name": "image-classification", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1430734, "num_examples": 7258, "dataset_name": "nls_chapbook_illustrations"}}, "download_checksums": {"https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip": {"num_bytes": 6754994277, "checksum": "ead1ce3f59ad561025235656848024049bae635eadb7e191048bc990d32e85f8"}, "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json": {"num_bytes": 1860557, "checksum": "edfbdaa4123c40b8a90472e5ab7664b9e22c25cdfbf1a0925f5820e5cc4d4275"}, "illustration-group-specifications[83].csv": {"num_bytes": 163406, "checksum": "f412e2e8bfafd2d204167d8155dd5c891c809f1bb2ac8e93d2cee7917532faf0"}}, "download_size": 6757018240, "post_processing_size": null, "dataset_size": 1430734, "size_in_bytes": 6758448974}, "image-matching": {"description": "TODO", "citation": "TODO", "homepage": "TODO", "license": "Public Domain Mark 1.0", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "group-label": {"dtype": "int32", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "nls_chapbook_illustrations", "config_name": "image-matching", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1402610, "num_examples": 7258, "dataset_name": "nls_chapbook_illustrations"}}, "download_checksums": {"https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip": {"num_bytes": 6754994277, "checksum": "ead1ce3f59ad561025235656848024049bae635eadb7e191048bc990d32e85f8"}, "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json": {"num_bytes": 1860557, "checksum": "edfbdaa4123c40b8a90472e5ab7664b9e22c25cdfbf1a0925f5820e5cc4d4275"}, "illustration-group-specifications[83].csv": {"num_bytes": 163406, "checksum": "f412e2e8bfafd2d204167d8155dd5c891c809f1bb2ac8e93d2cee7917532faf0"}}, "download_size": 6757018240, "post_processing_size": null, "dataset_size": 1402610, "size_in_bytes": 6758420850}}
 
 
illustration-detection/train-00000-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e726e55747ab197cb68962bfbafe4daf2ef9be7a07e86a6b1c6d588c683fd8b0
3
+ size 445545292
illustration-detection/train-00001-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6344c623ae044be7b23866377526886f2a5ae4bc428818abc912a41b71d67e2f
3
+ size 501140770
illustration-group-specifications[83].csv DELETED
The diff for this file is too large to render. See raw diff
 
image-classification/train-00000-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25a940acc3f404d414c03d4d83dfd6c45874b592d95f6a5ee3d7eb47e83ba088
3
+ size 445195571
image-classification/train-00001-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:784c154bf89fb14597e6eba35d78afb3adf66595a68bc6dfef33f7f01997e729
3
+ size 501025577
image-matching/train-00000-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:117ec6465d7b25054a255acdb18a1655422a81d39f1d39b43188f8fd670389b8
3
+ size 445201563
image-matching/train-00001-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:238e446f330726feb288d9894bf6ef1e8a08d750540f5a24676b9c492f7c07e1
3
+ size 501021045
nls_chapbook_illustrations.py DELETED
@@ -1,207 +0,0 @@
1
- # Copyright 2022 Daniel van Strien.
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
- """NLS Chapbook Illustrations"""
15
-
16
- import collections
17
- import json
18
- import os
19
- from typing import Any, Dict, List
20
- import pandas as pd
21
- import datasets
22
-
23
- _CITATION = """@inproceedings{10.1145/3476887.3476893,
24
- author = {Dutta, Abhishek and Bergel, Giles and Zisserman, Andrew},
25
- title = {Visual Analysis of Chapbooks Printed in Scotland},
26
- year = {2021},
27
- isbn = {9781450386906},
28
- publisher = {Association for Computing Machinery},
29
- address = {New York, NY, USA},
30
- url = {https://doi.org/10.1145/3476887.3476893},
31
- doi = {10.1145/3476887.3476893},
32
- abstract = {Chapbooks were short, cheap printed booklets produced in large quantities in Scotland, England, Ireland, North America and much of Europe between roughly the seventeenth and nineteenth centuries. A form of popular literature containing songs, stories, poems, games, riddles, religious writings and other content designed to appeal to a wide readership, they were frequently illustrated, particularly on their title-pages. This paper describes the visual analysis of such chapbook illustrations. We automatically extract all the illustrations contained in the National Library of Scotland Chapbooks Printed in Scotland dataset, and create a visual search engine to search this dataset using full or part-illustrations as queries. We also cluster these illustrations based on their visual content, and provide keyword-based search of the metadata associated with each publication. The visual search; clustering of illustrations based on visual content; and metadata search features enable researchers to forensically analyse the chapbooks dataset and to discover unnoticed relationships between its elements. We release all annotations and software tools described in this paper to enable reproduction of the results presented and to allow extension of the methodology described to datasets of a similar nature.},
33
- booktitle = {The 6th International Workshop on Historical Document Imaging and Processing},
34
- pages = {67–72},
35
- numpages = {6},
36
- keywords = {illustration detection, chapbooks, image search, visual grouping, printing, digital scholarship, illustration dataset},
37
- location = {Lausanne, Switzerland},
38
- series = {HIP '21}
39
- }
40
- """
41
-
42
-
43
- _DESCRIPTION = "This dataset comprises of images from chapbooks held by the National Library of Scotland and digitised and published as its Chapbooks Printed in Scotland dataset"
44
-
45
-
46
- _HOMEPAGE = "https://www.robots.ox.ac.uk/~vgg/research/chapbooks/"
47
-
48
-
49
- _LICENSE = "Public Domain Mark 1.0" # TODO confirm licence terms for annotations
50
-
51
-
52
- _IMAGES_URL = "https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip"
53
-
54
- # TODO update url if this is merged upstream
55
- _ANNOTATIONS_URL = "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json"
56
-
57
-
58
- class NationalLibraryScotlandChapBooksConfig(datasets.BuilderConfig):
59
- """BuilderConfig for National Library of Scotland Chapbooks dataset."""
60
-
61
- def __init__(self, name, **kwargs):
62
- super(NationalLibraryScotlandChapBooksConfig, self).__init__(
63
- version=datasets.Version("1.0.0"),
64
- name=name,
65
- description="NLS Chapbook Illustrations",
66
- **kwargs,
67
- )
68
-
69
-
70
- class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
71
- """National Library of Scotland Chapbooks dataset."""
72
-
73
- BUILDER_CONFIGS = [
74
- NationalLibraryScotlandChapBooksConfig("illustration-detection"),
75
- NationalLibraryScotlandChapBooksConfig("image-classification"),
76
- NationalLibraryScotlandChapBooksConfig("image-matching"),
77
- ]
78
-
79
- def _info(self):
80
- if self.config.name == "illustration-detection":
81
- features = datasets.Features(
82
- {
83
- "image_id": datasets.Value("int64"),
84
- "image": datasets.Image(),
85
- "width": datasets.Value("int32"),
86
- "height": datasets.Value("int32"),
87
- }
88
- )
89
- object_dict = {
90
- "category_id": datasets.ClassLabel(
91
- names=["early_printed_illustration"]
92
- ),
93
- "image_id": datasets.Value("string"),
94
- "id": datasets.Value("int64"),
95
- "area": datasets.Value("int64"),
96
- "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
97
- "segmentation": [[datasets.Value("float32")]],
98
- "iscrowd": datasets.Value("bool"),
99
- }
100
- features["objects"] = [object_dict]
101
- if self.config.name == "image-classification":
102
- features = datasets.Features(
103
- {
104
- "image": datasets.Image(),
105
- "label": datasets.ClassLabel(
106
- num_classes=2, names=["not-illustrated", "illustrated"]
107
- ),
108
- }
109
- )
110
- if self.config.name == "image-matching":
111
- features = datasets.Features(
112
- {
113
- "image": datasets.Image(),
114
- "group-label": datasets.Value("int32"),
115
- }
116
- )
117
- return datasets.DatasetInfo(
118
- description=_DESCRIPTION,
119
- features=features,
120
- homepage=_HOMEPAGE,
121
- license=_LICENSE,
122
- citation=_CITATION,
123
- )
124
-
125
- def _split_generators(self, dl_manager):
126
- images = dl_manager.download_and_extract(_IMAGES_URL)
127
- annotations = dl_manager.download(_ANNOTATIONS_URL)
128
- image_match_annotations = dl_manager.download(
129
- "illustration-group-specifications[83].csv"
130
- )
131
- return [
132
- datasets.SplitGenerator(
133
- name=datasets.Split.TRAIN,
134
- gen_kwargs={
135
- "annotations_file": os.path.join(annotations),
136
- "image_dir": os.path.join(images, "nls-data-chapbooks"),
137
- "image_match_annotations": image_match_annotations,
138
- },
139
- )
140
- ]
141
-
142
- def _get_image_id_to_annotations_mapping(
143
- self, annotations: List[Dict]
144
- ) -> Dict[int, List[Dict[Any, Any]]]:
145
- """
146
- A helper function to build a mapping from image ids to annotations.
147
- """
148
- image_id_to_annotations = collections.defaultdict(list)
149
- for annotation in annotations:
150
- image_id_to_annotations[annotation["image_id"]].append(annotation)
151
- return image_id_to_annotations
152
-
153
- def _generate_examples(self, annotations_file, image_dir, image_match_annotations):
154
- def _image_info_to_example(image_info, image_dir):
155
- image = image_info["file_name"]
156
- return {
157
- "image_id": image_info["id"],
158
- "image": os.path.join(image_dir, image),
159
- "width": image_info["width"],
160
- "height": image_info["height"],
161
- }
162
-
163
- with open(annotations_file, encoding="utf8") as f:
164
- annotation_data = json.load(f)
165
- images = annotation_data["images"]
166
- annotations = annotation_data["annotations"]
167
- image_id_to_annotations = self._get_image_id_to_annotations_mapping(
168
- annotations
169
- )
170
-
171
- if self.config.name == "illustration-detection":
172
- for idx, image_info in enumerate(images):
173
- example = _image_info_to_example(image_info, image_dir)
174
- annotations = image_id_to_annotations[image_info["id"]]
175
- objects = []
176
- for annotation in annotations:
177
- category_id = annotation["category_id"]
178
- if category_id == 1:
179
- annotation["category_id"] = 0
180
- objects.append(annotation)
181
- example["objects"] = objects
182
- yield (idx, example)
183
- if self.config.name == "image-classification":
184
- for idx, image_info in enumerate(images):
185
- annotations = image_id_to_annotations[image_info["id"]]
186
- label = 0 if len(annotations) < 1 else 1
187
- example = {
188
- "image": os.path.join(image_dir, image_info["file_name"]),
189
- "label": label,
190
- }
191
-
192
- yield (idx, example)
193
- if self.config.name == "image-matching":
194
- df = pd.read_csv(image_match_annotations, dtype={"file_id": "string"})
195
- df = df.drop_duplicates(subset=["filename"], keep=False)
196
- df = df.set_index("filename", drop=True)
197
- mapping = df.to_dict("index")
198
- for idx, image_info in enumerate(images):
199
- filename = image_info["file_name"]
200
- match = mapping.get(filename)
201
- if match:
202
- match = match["set_id"]
203
- example = {
204
- "image": os.path.join(image_dir, image_info["file_name"]),
205
- "group-label": match,
206
- }
207
- yield (idx, example)