Datasets:

davanstrien HF staff commited on
Commit
f588760
1 Parent(s): 9477285

add image matching config

Browse files
dataset_infos.json CHANGED
@@ -1 +1 @@
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"}}, "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}}
 
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-group-specifications[83].csv ADDED
The diff for this file is too large to render. See raw diff
 
nls_chapbook_illustrations.py CHANGED
@@ -11,22 +11,39 @@
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 Images"""
15
 
16
  import collections
17
  import json
18
  import os
19
  from typing import Any, Dict, List
20
-
21
  import datasets
22
 
23
- _CITATION = "TODO"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
- _DESCRIPTION = "TODO"
27
 
28
 
29
- _HOMEPAGE = "TODO"
30
 
31
 
32
  _LICENSE = "Public Domain Mark 1.0" # TODO confirm licence terms for annotations
@@ -37,8 +54,6 @@ _IMAGES_URL = "https://nlsfoundry.s3.amazonaws.com/data/nls-data-chapbooks.zip"
37
  # TODO update url if this is merged upstream
38
  _ANNOTATIONS_URL = "https://gitlab.com/davanstrien/nls-chapbooks-illustrations/-/raw/master/data/annotations/step5-manual-verification-image-0-47329_train_coco.json"
39
 
40
- logger = datasets.utils.logging.get_logger(__name__)
41
-
42
 
43
  class NationalLibraryScotlandChapBooksConfig(datasets.BuilderConfig):
44
  """BuilderConfig for National Library of Scotland Chapbooks dataset."""
@@ -47,7 +62,7 @@ class NationalLibraryScotlandChapBooksConfig(datasets.BuilderConfig):
47
  super(NationalLibraryScotlandChapBooksConfig, self).__init__(
48
  version=datasets.Version("1.0.0"),
49
  name=name,
50
- description="TODO",
51
  **kwargs,
52
  )
53
 
@@ -58,6 +73,7 @@ class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
58
  BUILDER_CONFIGS = [
59
  NationalLibraryScotlandChapBooksConfig("illustration-detection"),
60
  NationalLibraryScotlandChapBooksConfig("image-classification"),
 
61
  ]
62
 
63
  def _info(self):
@@ -91,6 +107,13 @@ class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
91
  ),
92
  }
93
  )
 
 
 
 
 
 
 
94
  return datasets.DatasetInfo(
95
  description=_DESCRIPTION,
96
  features=features,
@@ -102,12 +125,16 @@ class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
102
  def _split_generators(self, dl_manager):
103
  images = dl_manager.download_and_extract(_IMAGES_URL)
104
  annotations = dl_manager.download(_ANNOTATIONS_URL)
 
 
 
105
  return [
106
  datasets.SplitGenerator(
107
  name=datasets.Split.TRAIN,
108
  gen_kwargs={
109
  "annotations_file": os.path.join(annotations),
110
  "image_dir": os.path.join(images, "nls-data-chapbooks"),
 
111
  },
112
  )
113
  ]
@@ -123,7 +150,7 @@ class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
123
  image_id_to_annotations[annotation["image_id"]].append(annotation)
124
  return image_id_to_annotations
125
 
126
- def _generate_examples(self, annotations_file, image_dir):
127
  def _image_info_to_example(image_info, image_dir):
128
  image = image_info["file_name"]
129
  return {
@@ -137,34 +164,44 @@ class NationalLibraryScotlandChapBooks(datasets.GeneratorBasedBuilder):
137
  annotation_data = json.load(f)
138
  images = annotation_data["images"]
139
  annotations = annotation_data["annotations"]
140
-
141
  image_id_to_annotations = self._get_image_id_to_annotations_mapping(
142
  annotations
143
  )
 
144
  if self.config.name == "illustration-detection":
145
  for idx, image_info in enumerate(images):
146
- example = _image_info_to_example(
147
- image_info,
148
- image_dir,
149
- )
150
  annotations = image_id_to_annotations[image_info["id"]]
151
  objects = []
152
- for annot in annotations:
153
- category_id = annot["category_id"]
154
  if category_id == 1:
155
- annot["category_id"] = 0
156
- objects.append(annot)
157
  example["objects"] = objects
158
- yield idx, example
159
  if self.config.name == "image-classification":
160
  for idx, image_info in enumerate(images):
161
  annotations = image_id_to_annotations[image_info["id"]]
162
- if len(annotations) < 1:
163
- label = 0
164
- else:
165
- label = 1
166
  example = {
167
  "image": os.path.join(image_dir, image_info["file_name"]),
168
  "label": label,
169
  }
170
- yield idx, example
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
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."""
 
62
  super(NationalLibraryScotlandChapBooksConfig, self).__init__(
63
  version=datasets.Version("1.0.0"),
64
  name=name,
65
+ description="NLS Chapbook Illustrations",
66
  **kwargs,
67
  )
68
 
 
73
  BUILDER_CONFIGS = [
74
  NationalLibraryScotlandChapBooksConfig("illustration-detection"),
75
  NationalLibraryScotlandChapBooksConfig("image-classification"),
76
+ NationalLibraryScotlandChapBooksConfig("image-matching"),
77
  ]
78
 
79
  def _info(self):
 
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,
 
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
  ]
 
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 {
 
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)