jordyvl commited on
Commit
e9aab75
1 Parent(s): 6ee70ff

First commit - not yet sharing the data

Browse files
README.md CHANGED
@@ -1,3 +1,233 @@
1
  ---
2
- license: cc-by-nc-sa-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ annotations_creators:
3
+ - found
4
+ language_creators:
5
+ - found
6
+ language:
7
+ - en
8
+ license:
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
+ dataset_info:
23
+ features:
24
+ - name: image
25
+ dtype: image
26
+ - name: label
27
+ dtype:
28
+ class_label:
29
+ names:
30
+ '0': letter
31
+ '1': form
32
+ '2': email
33
+ '3': handwritten
34
+ '4': advertisement
35
+ '5': scientific report
36
+ '6': scientific publication
37
+ '7': specification
38
+ '8': file folder
39
+ '9': news article
40
+ '10': budget
41
+ '11': invoice
42
+ '12': presentation
43
+ '13': questionnaire
44
+ '14': resume
45
+ '15': memo
46
+ splits:
47
+ - name: train
48
+ num_bytes: 38816373360
49
+ num_examples: 320000
50
+ - name: test
51
+ num_bytes: 4863300853
52
+ num_examples: 40000
53
+ - name: validation
54
+ num_bytes: 4868685208
55
+ num_examples: 40000
56
+ download_size: 38779484559
57
+ dataset_size: 48548359421
58
  ---
59
+
60
+ # Dataset Card for RVL-CDIP
61
+
62
+ ## Extension
63
+
64
+ The data loader provides support for loading easyOCR files together with the images
65
+ It is not included under '../data', yet is available upon request via email <firstname@contract.fit>.
66
+
67
+ ## Table of Contents
68
+ - [Dataset Description](#dataset-description)
69
+ - [Dataset Summary](#dataset-summary)
70
+ - [Supported Tasks](#supported-tasks-and-leaderboards)
71
+ - [Languages](#languages)
72
+ - [Dataset Structure](#dataset-structure)
73
+ - [Data Instances](#data-instances)
74
+ - [Data Fields](#data-instances)
75
+ - [Data Splits](#data-instances)
76
+ - [Dataset Creation](#dataset-creation)
77
+ - [Curation Rationale](#curation-rationale)
78
+ - [Source Data](#source-data)
79
+ - [Annotations](#annotations)
80
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
81
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
82
+ - [Social Impact of Dataset](#social-impact-of-dataset)
83
+ - [Discussion of Biases](#discussion-of-biases)
84
+ - [Other Known Limitations](#other-known-limitations)
85
+ - [Additional Information](#additional-information)
86
+ - [Dataset Curators](#dataset-curators)
87
+ - [Licensing Information](#licensing-information)
88
+ - [Citation Information](#citation-information)
89
+
90
+ ## Dataset Description
91
+
92
+ - **Homepage:** [The RVL-CDIP Dataset](https://www.cs.cmu.edu/~aharley/rvl-cdip/)
93
+ - **Repository:**
94
+ - **Paper:** [Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval](https://arxiv.org/abs/1502.07058)
95
+ - **Leaderboard:** [RVL-CDIP leaderboard](https://paperswithcode.com/dataset/rvl-cdip)
96
+ - **Point of Contact:** [Adam W. Harley](mailto:aharley@cmu.edu)
97
+
98
+ ### Dataset Summary
99
+
100
+ 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.
101
+
102
+ ### Supported Tasks and Leaderboards
103
+
104
+ - `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).
105
+
106
+ ### Languages
107
+
108
+ All the classes and documents use English as their primary language.
109
+
110
+ ## Dataset Structure
111
+
112
+ ### Data Instances
113
+
114
+ A sample from the training set is provided below :
115
+ ```
116
+ {
117
+ 'image': <PIL.TiffImagePlugin.TiffImageFile image mode=L size=754x1000 at 0x7F9A5E92CA90>,
118
+ 'label': 15
119
+ }
120
+ ```
121
+
122
+ ### Data Fields
123
+
124
+ - `image`: A `PIL.Image.Image` object containing a document.
125
+ - `label`: an `int` classification label.
126
+
127
+ <details>
128
+ <summary>Class Label Mappings</summary>
129
+
130
+ ```json
131
+ {
132
+ "0": "letter",
133
+ "1": "form",
134
+ "2": "email",
135
+ "3": "handwritten",
136
+ "4": "advertisement",
137
+ "5": "scientific report",
138
+ "6": "scientific publication",
139
+ "7": "specification",
140
+ "8": "file folder",
141
+ "9": "news article",
142
+ "10": "budget",
143
+ "11": "invoice",
144
+ "12": "presentation",
145
+ "13": "questionnaire",
146
+ "14": "resume",
147
+ "15": "memo"
148
+ }
149
+ ```
150
+
151
+ </details>
152
+
153
+ ### Data Splits
154
+
155
+ | |train|test|validation|
156
+ |----------|----:|----:|---------:|
157
+ |# of examples|320000|40000|40000|
158
+
159
+ The dataset was split in proportions similar to those of ImageNet.
160
+ - 320000 images were used for training,
161
+ - 40000 images for validation, and
162
+ - 40000 images for testing.
163
+
164
+ ## Dataset Creation
165
+
166
+ ### Curation Rationale
167
+
168
+ From the paper:
169
+ > This work makes available a new labelled subset of the IIT-CDIP collection, containing 400,000
170
+ document images across 16 categories, useful for training new CNNs for document analysis.
171
+
172
+ ### Source Data
173
+
174
+ #### Initial Data Collection and Normalization
175
+
176
+ The same as in the IIT-CDIP collection.
177
+
178
+ #### Who are the source language producers?
179
+
180
+ The same as in the IIT-CDIP collection.
181
+
182
+ ### Annotations
183
+
184
+ #### Annotation process
185
+
186
+ The same as in the IIT-CDIP collection.
187
+
188
+ #### Who are the annotators?
189
+
190
+ The same as in the IIT-CDIP collection.
191
+
192
+ ### Personal and Sensitive Information
193
+
194
+ [More Information Needed]
195
+
196
+ ## Considerations for Using the Data
197
+
198
+ ### Social Impact of Dataset
199
+
200
+ [More Information Needed]
201
+
202
+ ### Discussion of Biases
203
+
204
+ [More Information Needed]
205
+
206
+ ### Other Known Limitations
207
+
208
+ [More Information Needed]
209
+
210
+ ## Additional Information
211
+
212
+ ### Dataset Curators
213
+
214
+ The dataset was curated by the authors - Adam W. Harley, Alex Ufkes, and Konstantinos G. Derpanis.
215
+
216
+ ### Licensing Information
217
+
218
+ 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/).
219
+
220
+ ### Citation Information
221
+
222
+ ```bibtex
223
+ @inproceedings{harley2015icdar,
224
+ title = {Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval},
225
+ author = {Adam W Harley and Alex Ufkes and Konstantinos G Derpanis},
226
+ booktitle = {International Conference on Document Analysis and Recognition ({ICDAR})}},
227
+ year = {2015}
228
+ }
229
+ ```
230
+
231
+ ### Contributions
232
+
233
+ Thanks to [@dnaveenr](https://github.com/dnaveenr) for adding this dataset.
data/rvl-cdip.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3577e655813922098cd776422479017be37612ec17a65076b1b62199bf8b28a2
3
+ size 38762320458
data/test.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97699c1c56425c4482632742381289b7bf855c23cd020253d7cb29df638ba1a3
3
+ size 1717144
data/train.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d25bf09a99d8691883dfebbc783046fb963437ce90b313ad0b81cab451fc17b
3
+ size 13730846
data/val.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:748483211bda619ab5fc3d395bd7dbfb6cac025753a13fc6abe500280e4e963a
3
+ size 1716111
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}}
rvl_cdip_easyOCR.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import numpy as np
20
+ from tqdm import tqdm
21
+ import datasets
22
+ from datasets.tasks import ImageClassification
23
+
24
+
25
+ _CITATION = """\
26
+ @inproceedings{harley2015icdar,
27
+ title = {Evaluation of Deep Convolutional Nets for Document Image Classification and Retrieval},
28
+ author = {Adam W Harley and Alex Ufkes and Konstantinos G Derpanis},
29
+ booktitle = {International Conference on Document Analysis and Recognition ({ICDAR})}},
30
+ year = {2015}
31
+ }
32
+ """
33
+
34
+
35
+ _DESCRIPTION = """\
36
+ 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.
37
+ """
38
+
39
+
40
+ _HOMEPAGE = "https://www.cs.cmu.edu/~aharley/rvl-cdip/"
41
+
42
+
43
+ _LICENSE = "https://www.industrydocuments.ucsf.edu/help/copyright/"
44
+
45
+
46
+ _URLS = {
47
+ "rvl-cdip": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/rvl-cdip.tar.gz",
48
+ }
49
+
50
+ _METADATA_URLS = {
51
+ "train": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/train.txt",
52
+ "test": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/test.txt",
53
+ "val": "https://huggingface.co/datasets/rvl_cdip/resolve/main/data/val.txt",
54
+ }
55
+
56
+ _CLASSES = [
57
+ "letter",
58
+ "form",
59
+ "email",
60
+ "handwritten",
61
+ "advertisement",
62
+ "scientific report",
63
+ "scientific publication",
64
+ "specification",
65
+ "file folder",
66
+ "news article",
67
+ "budget",
68
+ "invoice",
69
+ "presentation",
70
+ "questionnaire",
71
+ "resume",
72
+ "memo",
73
+ ]
74
+
75
+ _IMAGES_DIR = "images/"
76
+
77
+
78
+ class RvlCdip(datasets.GeneratorBasedBuilder):
79
+ """Ryerson Vision Lab Complex Document Information Processing dataset."""
80
+
81
+ VERSION = datasets.Version("1.0.0")
82
+
83
+ def _info(self):
84
+ return datasets.DatasetInfo(
85
+ description=_DESCRIPTION,
86
+ features=datasets.Features(
87
+ {
88
+ "id": datasets.Value("string"),
89
+ "image": datasets.Image(),
90
+ "label": datasets.ClassLabel(names=_CLASSES),
91
+ }
92
+ ),
93
+ supervised_keys=("image", "label"),
94
+ homepage=_HOMEPAGE,
95
+ citation=_CITATION,
96
+ license=_LICENSE,
97
+ task_templates=[
98
+ ImageClassification(image_column="image", label_column="label")
99
+ ],
100
+ )
101
+
102
+ def _split_generators(self, dl_manager):
103
+ if self.config.data_files:
104
+ archive_path = self.config.data_files["binary"][0]
105
+ else:
106
+ archive_path = dl_manager.download(
107
+ _URLS["rvl-cdip"]
108
+ ) # only download images if need be
109
+ labels_path = dl_manager.download(_METADATA_URLS)
110
+
111
+ return [
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.TRAIN,
114
+ gen_kwargs={
115
+ "archive_iterator": dl_manager.iter_archive(archive_path),
116
+ "labels_filepath": labels_path["train"],
117
+ "split": "train",
118
+ },
119
+ ),
120
+ datasets.SplitGenerator(
121
+ name=datasets.Split.TEST,
122
+ gen_kwargs={
123
+ "archive_iterator": dl_manager.iter_archive(archive_path),
124
+ "labels_filepath": labels_path["test"],
125
+ "split": "test",
126
+ },
127
+ ),
128
+ datasets.SplitGenerator(
129
+ name=datasets.Split.VALIDATION,
130
+ gen_kwargs={
131
+ "archive_iterator": dl_manager.iter_archive(archive_path),
132
+ "labels_filepath": labels_path["val"],
133
+ "split": "validation",
134
+ },
135
+ ),
136
+ ]
137
+
138
+ @staticmethod
139
+ def _get_image_to_class_map(data):
140
+ image_to_class_id = {}
141
+ for item in data:
142
+ image_path, class_id = item.split(" ")
143
+ image_path = os.path.join(_IMAGES_DIR, image_path)
144
+ image_to_class_id[image_path] = int(class_id)
145
+
146
+ return image_to_class_id
147
+
148
+ @staticmethod
149
+ def _get_image_to_OCR(OCR_dir, split):
150
+ def parse_easyOCR_box(box):
151
+ # {'x0': 39, 'y0': 39, 'x1': 498, 'y1': 82, 'width': 459, 'height': 43}
152
+ return (box["x0"], box["y0"], box["x1"], box["y1"])
153
+
154
+ if OCR_dir is None:
155
+ return {}
156
+ image_to_OCR = {}
157
+ data = np.load(
158
+ os.path.join(OCR_dir, f"Easy_{split[0].upper()+split[1:]}_Data.npy"),
159
+ allow_pickle=True,
160
+ )
161
+ for ex in tqdm(data, desc='Loading OCR data'):
162
+ w, h = ex["images"][0]["image_width"], ex["images"][0]["image_height"]
163
+ filename = ex["images"][0]["file_name"]
164
+ words = ex["word-level annotations"][0]["ocred_text"]
165
+ box_info = ex["word-level annotations"][0]["ocred_boxes"]
166
+ boxes = [parse_easyOCR_box(box) for box in box_info]
167
+ assert len(boxes) == len(words)
168
+ image_to_OCR[filename] = (words, boxes)
169
+ return image_to_OCR
170
+
171
+ @staticmethod
172
+ def _path_to_OCR(image_to_OCR, file_path):
173
+ # obtain text and boxes given file_path
174
+ text, boxes = None, None
175
+ if file_path in image_to_OCR:
176
+ text, boxes = image_to_OCR[file_path]
177
+ return text, boxes
178
+
179
+ def _generate_examples(self, archive_iterator, labels_filepath, split):
180
+ with open(labels_filepath, encoding="utf-8") as f:
181
+ data = f.read().splitlines()
182
+
183
+ image_to_OCR = self._get_image_to_OCR(self.config.data_dir, split)
184
+ image_to_class_id = self._get_image_to_class_map(data)
185
+
186
+ for file_path, file_obj in archive_iterator:
187
+ if file_path.startswith(_IMAGES_DIR):
188
+ if file_path in image_to_class_id:
189
+ class_id = image_to_class_id[file_path]
190
+ label = _CLASSES[class_id]
191
+ words, boxes = self._path_to_OCR(image_to_OCR, file_path)
192
+ a = dict(
193
+ id=file_path,
194
+ image={"path": file_path, "bytes": file_obj.read()},
195
+ label=label,
196
+ words=words,
197
+ boxes=boxes,
198
+ )
199
+ from pdb import set_trace; set_trace()
200
+ yield file_path, a
test_loader.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+
3
+ data = load_dataset(
4
+ "./rvl_cdip_easyOCR.py",
5
+ split="test",
6
+ #cache_dir="/mnt/lerna/data/HFcache",
7
+ data_files={ # this is the path to the images if it does not download it
8
+ "binary": __file__#"/mnt/lerna/data/HFcache/downloads/c8cc6f89129255a9adf3e97e319ebe2055cf97662135b3ad26c79e9432544db5",
9
+ },
10
+ data_dir="/home/jordy/Downloads/OCRedText", # this is the path to the OCR data
11
+ )
12
+