dnaveenr commited on
Commit
96d9c30
1 Parent(s): 62d7e56

Add RVL-CDIP dataset (#4050)

Browse files

* Initial dataset loading script.

* add generate_examples code.

* add manual download instructions and generate examples.

* format code.

* add Dataset Cards.

* update Dataset card.

* add dummy data.

* Update datasets/rvl_cdip/README.md

License as other for custom license.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Add leaderboard details.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Add data collection info.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Fix links for the license.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

Add bibtex tag.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* add dataset split info.

* add dataset curation info.

* add stream download support.

* update gdrive url and stream examples.

* add path feature.

* format code.

* update dataset download and metadata urls.

* update dummy_data.zip

* add dataset_infos.json file

* Update datasets/rvl_cdip/README.md

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/README.md

add tasks based on new taxonomy.

Co-authored-by: Mario Šaško <mario@huggingface.co>

* Update datasets/rvl_cdip/rvl_cdip.py

Co-authored-by: Mario Šaško <mario@huggingface.co>

* remove path from features, add file_path to yield.

* remove local extraction of file.

* Remove split param

* Format supported tasks section

* Add contribution notice

* Update download urls

* Update info

* Deleted unused file

* Minor changes in card

Co-authored-by: Mario Šaško <mario@huggingface.co>

Commit from https://github.com/huggingface/datasets/commit/4134e89a9ad279d3768bb1dc0caabb239759a412

Files changed (4) hide show
  1. README.md +192 -0
  2. dataset_infos.json +1 -0
  3. dummy/1.0.0/dummy_data.zip +3 -0
  4. rvl_cdip.py +148 -0
README.md ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - found
4
+ language_creators:
5
+ - found
6
+ languages:
7
+ - en
8
+ licenses:
9
+ - other
10
+ multilinguality:
11
+ - monolingual
12
+ size_categories:
13
+ - 100K<n<1M
14
+ source_datasets:
15
+ - extended|iit_cdip
16
+ task_categories:
17
+ - image-classification
18
+ task_ids:
19
+ - multi-class-image-classification
20
+ paperswithcode_id: rvl-cdip
21
+ pretty_name: RVL-CDIP
22
+ ---
23
+
24
+ # Dataset Card for RVL-CDIP
25
+
26
+ ## Table of Contents
27
+ - [Dataset Description](#dataset-description)
28
+ - [Dataset Summary](#dataset-summary)
29
+ - [Supported Tasks](#supported-tasks-and-leaderboards)
30
+ - [Languages](#languages)
31
+ - [Dataset Structure](#dataset-structure)
32
+ - [Data Instances](#data-instances)
33
+ - [Data Fields](#data-instances)
34
+ - [Data Splits](#data-instances)
35
+ - [Dataset Creation](#dataset-creation)
36
+ - [Curation Rationale](#curation-rationale)
37
+ - [Source Data](#source-data)
38
+ - [Annotations](#annotations)
39
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
40
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
41
+ - [Social Impact of Dataset](#social-impact-of-dataset)
42
+ - [Discussion of Biases](#discussion-of-biases)
43
+ - [Other Known Limitations](#other-known-limitations)
44
+ - [Additional Information](#additional-information)
45
+ - [Dataset Curators](#dataset-curators)
46
+ - [Licensing Information](#licensing-information)
47
+ - [Citation Information](#citation-information)
48
+
49
+ ## Dataset Description
50
+
51
+ - **Homepage:** [The RVL-CDIP Dataset](https://www.cs.cmu.edu/~aharley/rvl-cdip/)
52
+ - **Repository:**
53
+ - **Paper:** [Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval](https://arxiv.org/abs/1502.07058)
54
+ - **Leaderboard:** [RVL-CDIP leaderboard](https://paperswithcode.com/dataset/rvl-cdip)
55
+ - **Point of Contact:** [Adam W. Harley](mailto:aharley@cmu.edu)
56
+
57
+ ### Dataset Summary
58
+
59
+ The RVL-CDIP (Ryerson Vision Lab Complex Document Information Processing) dataset consists of 400,000 grayscale images in 16 classes, with 25,000 images per class. There are 320,000 training images, 40,000 validation images, and 40,000 test images. The images are sized so their largest dimension does not exceed 1000 pixels.
60
+
61
+ ### Supported Tasks and Leaderboards
62
+
63
+ - `image-classification`: The goal of this task is to classify a given document into one of 16 classes representing document types (letter, form, etc.). The leaderboard for this task is available [here](https://paperswithcode.com/sota/document-image-classification-on-rvl-cdip).
64
+
65
+ ### Languages
66
+
67
+ All the classes and documents use English as their primary language.
68
+
69
+ ## Dataset Structure
70
+
71
+ ### Data Instances
72
+
73
+ A sample from the training set is provided below :
74
+ ```
75
+ {
76
+ 'image': <PIL.TiffImagePlugin.TiffImageFile image mode=L size=754x1000 at 0x7F9A5E92CA90>,
77
+ 'label': 15
78
+ }
79
+ ```
80
+
81
+ ### Data Fields
82
+
83
+ - `image`: A `PIL.Image.Image` object containing a document.
84
+ - `label`: an `int` classification label.
85
+
86
+ <details>
87
+ <summary>Class Label Mappings</summary>
88
+
89
+ ```json
90
+ {
91
+ "0": "letter",
92
+ "1": "form",
93
+ "2": "email",
94
+ "3": "handwritten",
95
+ "4": "advertisement",
96
+ "5": "scientific report",
97
+ "6": "scientific publication",
98
+ "7": "specification",
99
+ "8": "file folder",
100
+ "9": "news article",
101
+ "10": "budget",
102
+ "11": "invoice",
103
+ "12": "presentation",
104
+ "13": "questionnaire",
105
+ "14": "resume",
106
+ "15": "memo"
107
+ }
108
+ ```
109
+
110
+ </details>
111
+
112
+ ### Data Splits
113
+
114
+ | |train|test|validation|
115
+ |----------|----:|----:|---------:|
116
+ |# of examples|320000|40000|40000|
117
+
118
+ The dataset was split in proportions similar to those of ImageNet.
119
+ - 320000 images were used for training,
120
+ - 40000 images for validation, and
121
+ - 40000 images for testing.
122
+
123
+ ## Dataset Creation
124
+
125
+ ### Curation Rationale
126
+
127
+ From the paper:
128
+ > This work makes available a new labelled subset of the IIT-CDIP collection, containing 400,000
129
+ document images across 16 categories, useful for training new CNNs for document analysis.
130
+
131
+ ### Source Data
132
+
133
+ #### Initial Data Collection and Normalization
134
+
135
+ The same as in the IIT-CDIP collection.
136
+
137
+ #### Who are the source language producers?
138
+
139
+ The same as in the IIT-CDIP collection.
140
+
141
+ ### Annotations
142
+
143
+ #### Annotation process
144
+
145
+ The same as in the IIT-CDIP collection.
146
+
147
+ #### Who are the annotators?
148
+
149
+ The same as in the IIT-CDIP collection.
150
+
151
+ ### Personal and Sensitive Information
152
+
153
+ [More Information Needed]
154
+
155
+ ## Considerations for Using the Data
156
+
157
+ ### Social Impact of Dataset
158
+
159
+ [More Information Needed]
160
+
161
+ ### Discussion of Biases
162
+
163
+ [More Information Needed]
164
+
165
+ ### Other Known Limitations
166
+
167
+ [More Information Needed]
168
+
169
+ ## Additional Information
170
+
171
+ ### Dataset Curators
172
+
173
+ The dataset was curated by the authors - Adam W. Harley, Alex Ufkes, and Konstantinos G. Derpanis.
174
+
175
+ ### Licensing Information
176
+
177
+ RVL-CDIP is a subset of IIT-CDIP, which came from the [Legacy Tobacco Document Library](https://www.industrydocuments.ucsf.edu/tobacco/), for which license information can be found [here](https://www.industrydocuments.ucsf.edu/help/copyright/).
178
+
179
+ ### Citation Information
180
+
181
+ ```bibtex
182
+ @inproceedings{harley2015icdar,
183
+ title = {Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval},
184
+ author = {Adam W Harley and Alex Ufkes and Konstantinos G Derpanis},
185
+ booktitle = {International Conference on Document Analysis and Recognition ({ICDAR})}},
186
+ year = {2015}
187
+ }
188
+ ```
189
+
190
+ ### Contributions
191
+
192
+ Thanks to [@dnaveenr](https://github.com/dnaveenr) for adding this dataset.
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"default": {"description": "The RVL-CDIP (Ryerson Vision Lab Complex Document Information Processing) dataset consists of 400,000 grayscale images in 16 classes, with 25,000 images per class. There are 320,000 training images, 40,000 validation images, and 40,000 test images.\n", "citation": "@inproceedings{harley2015icdar,\n title = {Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval},\n author = {Adam W Harley and Alex Ufkes and Konstantinos G Derpanis},\n booktitle = {International Conference on Document Analysis and Recognition ({ICDAR})}},\n year = {2015}\n}\n", "homepage": "https://www.cs.cmu.edu/~aharley/rvl-cdip/", "license": "https://www.industrydocuments.ucsf.edu/help/copyright/", "features": {"image": {"decode": true, "id": null, "_type": "Image"}, "label": {"num_classes": 16, "names": ["letter", "form", "email", "handwritten", "advertisement", "scientific report", "scientific publication", "specification", "file folder", "news article", "budget", "invoice", "presentation", "questionnaire", "resume", "memo"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": {"input": "image", "output": "label"}, "task_templates": [{"task": "image-classification", "image_column": "image", "label_column": "label"}], "builder_name": "rvl_cdip", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 38816373360, "num_examples": 320000, "dataset_name": "rvl_cdip"}, "test": {"name": "test", "num_bytes": 4863300853, "num_examples": 40000, "dataset_name": "rvl_cdip"}, "validation": {"name": "validation", "num_bytes": 4868685208, "num_examples": 40000, "dataset_name": "rvl_cdip"}}, "download_checksums": {"https://huggingface.co/datasets/rvl_cdip/resolve/main/data/rvl-cdip.tar.gz": {"num_bytes": 38762320458, "checksum": "3577e655813922098cd776422479017be37612ec17a65076b1b62199bf8b28a2"}, "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/train.txt": {"num_bytes": 13730846, "checksum": "8d25bf09a99d8691883dfebbc783046fb963437ce90b313ad0b81cab451fc17b"}, "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/test.txt": {"num_bytes": 1717144, "checksum": "97699c1c56425c4482632742381289b7bf855c23cd020253d7cb29df638ba1a3"}, "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/val.txt": {"num_bytes": 1716111, "checksum": "748483211bda619ab5fc3d395bd7dbfb6cac025753a13fc6abe500280e4e963a"}}, "download_size": 38779484559, "post_processing_size": null, "dataset_size": 48548359421, "size_in_bytes": 87327843980}}
dummy/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc0bda5d09612fa17c15b0e26ea26e0e5e0a54979d5e09e609f68b82b45e15fb
3
+ size 289949
rvl_cdip.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ """RVL-CDIP (Ryerson Vision Lab Complex Document Information Processing) dataset"""
16
+
17
+
18
+ import os
19
+
20
+ import datasets
21
+ from datasets.tasks import ImageClassification
22
+
23
+
24
+ _CITATION = """\
25
+ @inproceedings{harley2015icdar,
26
+ title = {Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval},
27
+ author = {Adam W Harley and Alex Ufkes and Konstantinos G Derpanis},
28
+ booktitle = {International Conference on Document Analysis and Recognition ({ICDAR})}},
29
+ year = {2015}
30
+ }
31
+ """
32
+
33
+
34
+ _DESCRIPTION = """\
35
+ The RVL-CDIP (Ryerson Vision Lab Complex Document Information Processing) dataset consists of 400,000 grayscale images in 16 classes, with 25,000 images per class. There are 320,000 training images, 40,000 validation images, and 40,000 test images.
36
+ """
37
+
38
+
39
+ _HOMEPAGE = "https://www.cs.cmu.edu/~aharley/rvl-cdip/"
40
+
41
+
42
+ _LICENSE = "https://www.industrydocuments.ucsf.edu/help/copyright/"
43
+
44
+
45
+ _URLS = {
46
+ "rvl-cdip": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/rvl-cdip.tar.gz",
47
+ }
48
+
49
+ _METADATA_URLS = {
50
+ "train": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/train.txt",
51
+ "test": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/test.txt",
52
+ "val": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/val.txt",
53
+ }
54
+
55
+ _CLASSES = [
56
+ "letter",
57
+ "form",
58
+ "email",
59
+ "handwritten",
60
+ "advertisement",
61
+ "scientific report",
62
+ "scientific publication",
63
+ "specification",
64
+ "file folder",
65
+ "news article",
66
+ "budget",
67
+ "invoice",
68
+ "presentation",
69
+ "questionnaire",
70
+ "resume",
71
+ "memo",
72
+ ]
73
+
74
+ _IMAGES_DIR = "images/"
75
+
76
+
77
+ class RvlCdip(datasets.GeneratorBasedBuilder):
78
+ """Ryerson Vision Lab Complex Document Information Processing dataset."""
79
+
80
+ VERSION = datasets.Version("1.0.0")
81
+
82
+ def _info(self):
83
+ return datasets.DatasetInfo(
84
+ description=_DESCRIPTION,
85
+ features=datasets.Features(
86
+ {
87
+ "image": datasets.Image(),
88
+ "label": datasets.ClassLabel(names=_CLASSES),
89
+ }
90
+ ),
91
+ supervised_keys=("image", "label"),
92
+ homepage=_HOMEPAGE,
93
+ citation=_CITATION,
94
+ license=_LICENSE,
95
+ task_templates=[ImageClassification(image_column="image", label_column="label")],
96
+ )
97
+
98
+ def _split_generators(self, dl_manager):
99
+ archive_path = dl_manager.download(_URLS["rvl-cdip"])
100
+ labels_path = dl_manager.download(_METADATA_URLS)
101
+
102
+ return [
103
+ datasets.SplitGenerator(
104
+ name=datasets.Split.TRAIN,
105
+ gen_kwargs={
106
+ "archive_iterator": dl_manager.iter_archive(archive_path),
107
+ "labels_filepath": labels_path["train"],
108
+ },
109
+ ),
110
+ datasets.SplitGenerator(
111
+ name=datasets.Split.TEST,
112
+ gen_kwargs={
113
+ "archive_iterator": dl_manager.iter_archive(archive_path),
114
+ "labels_filepath": labels_path["test"],
115
+ },
116
+ ),
117
+ datasets.SplitGenerator(
118
+ name=datasets.Split.VALIDATION,
119
+ gen_kwargs={
120
+ "archive_iterator": dl_manager.iter_archive(archive_path),
121
+ "labels_filepath": labels_path["val"],
122
+ },
123
+ ),
124
+ ]
125
+
126
+ @staticmethod
127
+ def _get_image_to_class_map(data):
128
+ image_to_class_id = {}
129
+ for item in data:
130
+ image_path, class_id = item.split(" ")
131
+ image_path = os.path.join(_IMAGES_DIR, image_path)
132
+ image_to_class_id[image_path] = int(class_id)
133
+
134
+ return image_to_class_id
135
+
136
+ def _generate_examples(self, archive_iterator, labels_filepath):
137
+
138
+ with open(labels_filepath, encoding="utf-8") as f:
139
+ data = f.read().splitlines()
140
+
141
+ image_to_class_id = self._get_image_to_class_map(data)
142
+
143
+ for file_path, file_obj in archive_iterator:
144
+ if file_path.startswith(_IMAGES_DIR):
145
+ if file_path in image_to_class_id:
146
+ class_id = image_to_class_id[file_path]
147
+ label = _CLASSES[class_id]
148
+ yield file_path, {"image": {"path": file_path, "bytes": file_obj.read()}, "label": label}