system HF staff commited on
Commit
1a35c24
0 Parent(s):

Update files from the datasets library (from 1.18.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.18.0

.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - machine-generated
4
+ - expert-generated
5
+ language_creators:
6
+ - machine-generated
7
+ languages:
8
+ - en
9
+ licenses:
10
+ - other
11
+ multilinguality:
12
+ - monolingual
13
+ size_categories:
14
+ - 100K<n<1M
15
+ source_datasets:
16
+ - original
17
+ task_categories:
18
+ - other
19
+ task_ids:
20
+ - other-other-object-detection
21
+ - other-other-image-classification
22
+ paperswithcode_id: svhn
23
+ pretty_name: Street View House Numbers
24
+ ---
25
+
26
+ # Dataset Card for Street View House Numbers
27
+
28
+ ## Table of Contents
29
+ - [Table of Contents](#table-of-contents)
30
+ - [Dataset Description](#dataset-description)
31
+ - [Dataset Summary](#dataset-summary)
32
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
33
+ - [Languages](#languages)
34
+ - [Dataset Structure](#dataset-structure)
35
+ - [Data Instances](#data-instances)
36
+ - [Data Fields](#data-fields)
37
+ - [Data Splits](#data-splits)
38
+ - [Dataset Creation](#dataset-creation)
39
+ - [Curation Rationale](#curation-rationale)
40
+ - [Source Data](#source-data)
41
+ - [Annotations](#annotations)
42
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
43
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
44
+ - [Social Impact of Dataset](#social-impact-of-dataset)
45
+ - [Discussion of Biases](#discussion-of-biases)
46
+ - [Other Known Limitations](#other-known-limitations)
47
+ - [Additional Information](#additional-information)
48
+ - [Dataset Curators](#dataset-curators)
49
+ - [Licensing Information](#licensing-information)
50
+ - [Citation Information](#citation-information)
51
+ - [Contributions](#contributions)
52
+
53
+ ## Dataset Description
54
+
55
+ - **Homepage:** http://ufldl.stanford.edu/housenumbers
56
+ - **Repository:**
57
+ - **Paper:** [Reading Digits in Natural Images with Unsupervised Feature Learning](http://ufldl.stanford.edu/housenumbers/nips2011_housenumbers.pdf)
58
+ - **Leaderboard:** https://paperswithcode.com/sota/image-classification-on-svhn
59
+ - **Point of Contact:** streetviewhousenumbers@gmail.com
60
+
61
+ ### Dataset Summary
62
+
63
+ SVHN is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting. It can be seen as similar in flavor to MNIST (e.g., the images are of small cropped digits), but incorporates an order of magnitude more labeled data (over 600,000 digit images) and comes from a significantly harder, unsolved, real world problem (recognizing digits and numbers in natural scene images). SVHN is obtained from house numbers in Google Street View images. The dataset comes in two formats:
64
+ 1. Original images with character level bounding boxes.
65
+ 2. MNIST-like 32-by-32 images centered around a single character (many of the images do contain some distractors at the sides).
66
+
67
+ ### Supported Tasks and Leaderboards
68
+
69
+ - `object-classification`: The dataset can be used to train a model for digit detection.
70
+ - `image-classification`: The dataset can be used to train a model for Image Classification where the task is to predict a correct digit on the image. The leaderboard for this task is available at:
71
+ https://paperswithcode.com/sota/image-classification-on-svhn
72
+
73
+ ### Languages
74
+
75
+ English
76
+
77
+ ## Dataset Structure
78
+
79
+ ### Data Instances
80
+
81
+ #### full_numbers
82
+
83
+ The original, variable-resolution, color house-number images with character level bounding boxes.
84
+
85
+ ```
86
+ {
87
+ 'image': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=98x48 at 0x259E3F01780>,
88
+ 'digits': {
89
+ 'bbox': [
90
+ [36, 7, 13, 32],
91
+ [50, 7, 12, 32]
92
+ ],
93
+ 'label': [6, 9]
94
+ }
95
+ }
96
+ ```
97
+
98
+ #### cropped_digits
99
+
100
+ Character level ground truth in an MNIST-like format. All digits have been resized to a fixed resolution of 32-by-32 pixels. The original character bounding boxes are extended in the appropriate dimension to become square windows, so that resizing them to 32-by-32 pixels does not introduce aspect ratio distortions. Nevertheless this preprocessing introduces some distracting digits to the sides of the digit of interest.
101
+
102
+ ```
103
+ {
104
+ 'image': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=32x32 at 0x25A89494780>,
105
+ 'label': 1
106
+ }
107
+ ```
108
+
109
+ ### Data Fields
110
+
111
+ #### full_numbers
112
+
113
+ - `image`: A `PIL.Image.Image` object containing the image. Note that when accessing the image column: `dataset[0]["image"]` the image file is automatically decoded. Decoding of a large number of image files might take a significant amount of time. Thus it is important to first query the sample index before the `"image"` column, *i.e.* `dataset[0]["image"]` should **always** be preferred over `dataset["image"][0]`
114
+ - `digits`: a dictionary containing digits' bounding boxes and labels
115
+ - `bbox`: a list of bounding boxes (in the [coco](https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/#coco) format) corresponding to the digits present on the image
116
+ - `label`: a list of integers between 0 and 9 representing the digit.
117
+
118
+ #### cropped_digits
119
+
120
+ - `image`: A `PIL.Image.Image` object containing the image. Note that when accessing the image column: `dataset[0]["image"]` the image file is automatically decoded. Decoding of a large number of image files might take a significant amount of time. Thus it is important to first query the sample index before the `"image"` column, *i.e.* `dataset[0]["image"]` should **always** be preferred over `dataset["image"][0]`
121
+ - `digit`: an integer between 0 and 9 representing the digit.
122
+
123
+ ### Data Splits
124
+
125
+ #### full_numbers
126
+
127
+ The data is split into training, test and extra set. The training set contains 33402 images, test set 13068 and the extra set 202353 images.
128
+
129
+ #### cropped_digits
130
+
131
+ The data is split into training, test and extra set. The training set contains 73257 images, test set 26032 and the extra set 531131 images.
132
+
133
+ The extra set can be used as extra training data. The extra set was obtained in a similar manner to the training and test set, but with the increased detection threshold in order to generate this large amount of labeled data. The SVHN extra subset is thus somewhat biased toward less difficult detections, and is thus easier than SVHN train/SVHN test.
134
+
135
+ ## Dataset Creation
136
+
137
+ ### Curation Rationale
138
+
139
+ From the paper:
140
+ > As mentioned above, the venerable MNIST dataset has been a valuable goal post for researchers seeking to build better learning systems whose benchmark performance could be expected to translate into improved performance on realistic applications. However, computers have now reached essentially human levels of performance on this problem—a testament to progress in machine learning and computer vision. The Street View House Numbers (SVHN) digit database that we provide can be seen as similar in flavor to MNIST (e.g., the images are of small cropped characters), but the SVHN dataset incorporates an order of magnitude more labeled data and comes from a significantly harder, unsolved, real world problem. Here the gap between human performance and state of the art feature representations is significant. Going forward, we expect that this dataset may fulfill a similar role for modern feature learning algorithms: it provides a new and difficult benchmark where increased performance can be expected to translate into tangible gains on a realistic application.
141
+
142
+ ### Source Data
143
+
144
+ #### Initial Data Collection and Normalization
145
+
146
+ From the paper:
147
+ > The SVHN dataset was obtained from a large number of Street View images using a combination
148
+ of automated algorithms and the Amazon Mechanical Turk (AMT) framework, which was
149
+ used to localize and transcribe the single digits. We downloaded a very large set of images from
150
+ urban areas in various countries.
151
+
152
+ #### Who are the source language producers?
153
+
154
+ [More Information Needed]
155
+
156
+ ### Annotations
157
+
158
+ #### Annotation process
159
+
160
+ From the paper:
161
+ > From these randomly selected images, the house-number patches were extracted using a dedicated sliding window house-numbers detector using a low threshold on the detector’s confidence score in order to get a varied, unbiased dataset of house-number signs. These low precision detections were screened and transcribed by AMT workers.
162
+
163
+ #### Who are the annotators?
164
+
165
+ The AMT workers.
166
+
167
+ ### Personal and Sensitive Information
168
+
169
+ [More Information Needed]
170
+
171
+ ## Considerations for Using the Data
172
+
173
+ ### Social Impact of Dataset
174
+
175
+ [More Information Needed]
176
+
177
+ ### Discussion of Biases
178
+
179
+ [More Information Needed]
180
+
181
+ ### Other Known Limitations
182
+
183
+ [More Information Needed]
184
+
185
+ ## Additional Information
186
+
187
+ ### Dataset Curators
188
+
189
+ Yuval Netzer, Tao Wang, Adam Coates, Alessandro Bissacco, Bo Wu and Andrew Y. Ng
190
+
191
+ ### Licensing Information
192
+
193
+ Non-commerical use only.
194
+
195
+ ### Citation Information
196
+
197
+ ```
198
+ @article{netzer2011reading,
199
+ title={Reading digits in natural images with unsupervised feature learning},
200
+ author={Netzer, Yuval and Wang, Tao and Coates, Adam and Bissacco, Alessandro and Wu, Bo and Ng, Andrew Y},
201
+ year={2011}
202
+ }
203
+ ```
204
+
205
+ ### Contributions
206
+
207
+ Thanks to [@mariosasko](https://github.com/mariosasko) for adding this dataset.
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"full_numbers": {"description": "SVHN is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting.\nIt can be seen as similar in flavor to MNIST (e.g., the images are of small cropped digits), but incorporates an order of magnitude more labeled data (over 600,000 digit images)\nand comes from a significantly harder, unsolved, real world problem (recognizing digits and numbers in natural scene images). SVHN is obtained from house numbers in Google Street View images.\n", "citation": "@article{netzer2011reading,\n title={Reading digits in natural images with unsupervised feature learning},\n author={Netzer, Yuval and Wang, Tao and Coates, Adam and Bissacco, Alessandro and Wu, Bo and Ng, Andrew Y},\n year={2011}\n}\n", "homepage": "http://ufldl.stanford.edu/housenumbers/", "license": "Custom (non-commercial)", "features": {"image": {"id": null, "_type": "Image"}, "digits": {"feature": {"bbox": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": 4, "id": null, "_type": "Sequence"}, "label": {"num_classes": 10, "names": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "svhn", "config_name": "full_numbers", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 390404309, "num_examples": 33402, "dataset_name": "svhn"}, "test": {"name": "test", "num_bytes": 271503052, "num_examples": 13068, "dataset_name": "svhn"}, "extra": {"name": "extra", "num_bytes": 1868720340, "num_examples": 202353, "dataset_name": "svhn"}}, "download_checksums": {"http://ufldl.stanford.edu/housenumbers/train.tar.gz": {"num_bytes": 404141560, "checksum": "4b17bb33b6cd8f963493168f80143da956f28ec406cc12f8e5745a9f91a51898"}, "http://ufldl.stanford.edu/housenumbers/test.tar.gz": {"num_bytes": 276555967, "checksum": "57ac9ceb530e4aa85b55d991be8fc49c695b3d71c6f6a88afea86549efde7fb5"}, "http://ufldl.stanford.edu/housenumbers/extra.tar.gz": {"num_bytes": 1955489752, "checksum": "e857e27d1e65bd1e7d3959b094061777f6506bbc39889a0df3bba6a729d60f9c"}}, "download_size": 2636187279, "post_processing_size": null, "dataset_size": 2530627701, "size_in_bytes": 5166814980}, "cropped_digits": {"description": "SVHN is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting.\nIt can be seen as similar in flavor to MNIST (e.g., the images are of small cropped digits), but incorporates an order of magnitude more labeled data (over 600,000 digit images)\nand comes from a significantly harder, unsolved, real world problem (recognizing digits and numbers in natural scene images). SVHN is obtained from house numbers in Google Street View images.\n", "citation": "@article{netzer2011reading,\n title={Reading digits in natural images with unsupervised feature learning},\n author={Netzer, Yuval and Wang, Tao and Coates, Adam and Bissacco, Alessandro and Wu, Bo and Ng, Andrew Y},\n year={2011}\n}\n", "homepage": "http://ufldl.stanford.edu/housenumbers/", "license": "Custom (non-commercial)", "features": {"image": {"id": null, "_type": "Image"}, "label": {"num_classes": 10, "names": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": [{"task": "image-classification", "image_column": "image", "label_column": "label", "labels": null}], "builder_name": "svhn", "config_name": "cropped_digits", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 128364360, "num_examples": 73257, "dataset_name": "svhn"}, "test": {"name": "test", "num_bytes": 44464040, "num_examples": 26032, "dataset_name": "svhn"}, "extra": {"name": "extra", "num_bytes": 967853504, "num_examples": 531131, "dataset_name": "svhn"}}, "download_checksums": {"http://ufldl.stanford.edu/housenumbers/train_32x32.mat": {"num_bytes": 182040794, "checksum": "435e94d69a87fde4fd4d7f3dd208dfc32cb6ae8af2240d066de1df7508d083b8"}, "http://ufldl.stanford.edu/housenumbers/test_32x32.mat": {"num_bytes": 64275384, "checksum": "cdce80dfb2a2c4c6160906d0bd7c68ec5a99d7ca4831afa54f09182025b6a75b"}, "http://ufldl.stanford.edu/housenumbers/extra_32x32.mat": {"num_bytes": 1329278602, "checksum": "a133a4beb38a00fcdda90c9489e0c04f900b660ce8a316a5e854838379a71eb3"}}, "download_size": 1575594780, "post_processing_size": null, "dataset_size": 1140681904, "size_in_bytes": 2716276684}}
dummy/cropped_digits/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ba446e08a6dd641c111d74aa5b0c1b5c63465fc825b6ce33fc7616991c1a279
3
+ size 18454
dummy/full_numbers/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:684361aa6634b5c222a3cb29e3ccb7af6085daf0f7de38e1c7b5efed8c0c7324
3
+ size 5716
svhn.py ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Street View House Numbers (SVHN) dataset."""
16
+
17
+ import io
18
+ import os
19
+
20
+ import h5py
21
+ import numpy as np
22
+ import scipy.io as sio
23
+
24
+ import datasets
25
+ from datasets.tasks import ImageClassification
26
+
27
+
28
+ logger = datasets.logging.get_logger(__name__)
29
+
30
+
31
+ _CITATION = """\
32
+ @article{netzer2011reading,
33
+ title={Reading digits in natural images with unsupervised feature learning},
34
+ author={Netzer, Yuval and Wang, Tao and Coates, Adam and Bissacco, Alessandro and Wu, Bo and Ng, Andrew Y},
35
+ year={2011}
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """\
40
+ SVHN is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting.
41
+ It can be seen as similar in flavor to MNIST (e.g., the images are of small cropped digits), but incorporates an order of magnitude more labeled data (over 600,000 digit images)
42
+ and comes from a significantly harder, unsolved, real world problem (recognizing digits and numbers in natural scene images). SVHN is obtained from house numbers in Google Street View images.
43
+ """
44
+
45
+ _HOMEPAGE = "http://ufldl.stanford.edu/housenumbers/"
46
+
47
+ _LICENSE = "Custom (non-commercial)"
48
+
49
+ _URLs = {
50
+ "full_numbers": [
51
+ "http://ufldl.stanford.edu/housenumbers/train.tar.gz",
52
+ "http://ufldl.stanford.edu/housenumbers/test.tar.gz",
53
+ "http://ufldl.stanford.edu/housenumbers/extra.tar.gz",
54
+ ],
55
+ "cropped_digits": [
56
+ "http://ufldl.stanford.edu/housenumbers/train_32x32.mat",
57
+ "http://ufldl.stanford.edu/housenumbers/test_32x32.mat",
58
+ "http://ufldl.stanford.edu/housenumbers/extra_32x32.mat",
59
+ ],
60
+ }
61
+
62
+ _DIGIT_LABELS = [str(num) for num in range(10)]
63
+
64
+
65
+ class SVHN(datasets.GeneratorBasedBuilder):
66
+ """Street View House Numbers (SVHN) dataset."""
67
+
68
+ VERSION = datasets.Version("1.0.0")
69
+
70
+ BUILDER_CONFIGS = [
71
+ datasets.BuilderConfig(
72
+ name="full_numbers",
73
+ version=VERSION,
74
+ description="Contains the original, variable-resolution, color house-number images with character level bounding boxes.",
75
+ ),
76
+ datasets.BuilderConfig(
77
+ name="cropped_digits",
78
+ version=VERSION,
79
+ description="Character level ground truth in an MNIST-like format. All digits have been resized to a fixed resolution of 32-by-32 pixels. The original character bounding boxes are extended in the appropriate dimension to become square windows, so that resizing them to 32-by-32 pixels does not introduce aspect ratio distortions. Nevertheless this preprocessing introduces some distracting digits to the sides of the digit of interest.",
80
+ ),
81
+ ]
82
+
83
+ def _info(self):
84
+ if self.config.name == "full_numbers":
85
+ features = datasets.Features(
86
+ {
87
+ "image": datasets.Image(),
88
+ "digits": datasets.Sequence(
89
+ {
90
+ "bbox": datasets.Sequence(datasets.Value("int32"), length=4),
91
+ "label": datasets.ClassLabel(num_classes=10),
92
+ }
93
+ ),
94
+ }
95
+ )
96
+ else:
97
+ features = datasets.Features(
98
+ {
99
+ "image": datasets.Image(),
100
+ "label": datasets.ClassLabel(num_classes=10),
101
+ }
102
+ )
103
+ return datasets.DatasetInfo(
104
+ description=_DESCRIPTION,
105
+ features=features,
106
+ supervised_keys=None,
107
+ homepage=_HOMEPAGE,
108
+ license=_LICENSE,
109
+ citation=_CITATION,
110
+ task_templates=[ImageClassification(image_column="image", label_column="label")]
111
+ if self.config.name == "cropped_digits"
112
+ else None,
113
+ )
114
+
115
+ def _split_generators(self, dl_manager):
116
+ if self.config.name == "full_numbers":
117
+ train_archive, test_archive, extra_archive = dl_manager.download(_URLs[self.config.name])
118
+ for path, f in dl_manager.iter_archive(train_archive):
119
+ if path.endswith("digitStruct.mat"):
120
+ train_annot_data = f.read()
121
+ break
122
+ for path, f in dl_manager.iter_archive(test_archive):
123
+ if path.endswith("digitStruct.mat"):
124
+ test_annot_data = f.read()
125
+ break
126
+ for path, f in dl_manager.iter_archive(extra_archive):
127
+ if path.endswith("digitStruct.mat"):
128
+ extra_annot_data = f.read()
129
+ break
130
+ train_archive = dl_manager.iter_archive(train_archive)
131
+ test_archive = dl_manager.iter_archive(test_archive)
132
+ extra_archive = dl_manager.iter_archive(extra_archive)
133
+ train_filepath, test_filepath, extra_filepath = None, None, None
134
+ else:
135
+ train_annot_data, test_annot_data, extra_annot_data = None, None, None
136
+ train_archive, test_archive, extra_archive = None, None, None
137
+ train_filepath, test_filepath, extra_filepath = dl_manager.download(_URLs[self.config.name])
138
+ return [
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.TRAIN,
141
+ gen_kwargs={
142
+ "annot_data": train_annot_data,
143
+ "files": train_archive,
144
+ "filepath": train_filepath,
145
+ },
146
+ ),
147
+ datasets.SplitGenerator(
148
+ name=datasets.Split.TEST,
149
+ gen_kwargs={
150
+ "annot_data": test_annot_data,
151
+ "files": test_archive,
152
+ "filepath": test_filepath,
153
+ },
154
+ ),
155
+ datasets.SplitGenerator(
156
+ name="extra",
157
+ gen_kwargs={
158
+ "annot_data": extra_annot_data,
159
+ "files": extra_archive,
160
+ "filepath": extra_filepath,
161
+ },
162
+ ),
163
+ ]
164
+
165
+ def _generate_examples(self, annot_data, files, filepath):
166
+ if self.config.name == "full_numbers":
167
+
168
+ def _get_digits(bboxes, h5_file):
169
+ def key_to_values(key, bbox):
170
+ if bbox[key].shape[0] == 1:
171
+ return [int(bbox[key][0][0])]
172
+ else:
173
+ return [int(h5_file[bbox[key][i][0]][()].item()) for i in range(bbox[key].shape[0])]
174
+
175
+ bbox = h5_file[bboxes[0]]
176
+ assert bbox.keys() == {"height", "left", "top", "width", "label"}
177
+ bbox_columns = [key_to_values(key, bbox) for key in ["left", "top", "width", "height", "label"]]
178
+ return [
179
+ {"bbox": [left, top, width, height], "label": label % 10}
180
+ for left, top, width, height, label in zip(*bbox_columns)
181
+ ]
182
+
183
+ with h5py.File(io.BytesIO(annot_data), "r") as h5_file:
184
+ for path, f in files:
185
+ root, ext = os.path.splitext(path)
186
+ if ext != ".png":
187
+ continue
188
+ img_idx = int(os.path.basename(root)) - 1
189
+ yield img_idx, {
190
+ "image": {"path": path, "bytes": f.read()},
191
+ "digits": _get_digits(h5_file["digitStruct/bbox"][img_idx], h5_file),
192
+ }
193
+ else:
194
+ data = sio.loadmat(filepath)
195
+ for i, (image_array, label) in enumerate(zip(np.rollaxis(data["X"], -1), data["y"])):
196
+ yield i, {
197
+ "image": image_array,
198
+ "label": label.item() % 10,
199
+ }