HugoLaurencon commited on
Commit
cb3a558
·
1 Parent(s): b026879

add IIIT-5K dataset

Browse files
Files changed (1) hide show
  1. IIIT-5K.py +106 -0
IIIT-5K.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
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
+
16
+ # Lint as: python3
17
+ """IIIT5K dataset."""
18
+
19
+
20
+ import scipy.io
21
+
22
+ import datasets
23
+
24
+ import os
25
+ from pathlib import Path
26
+
27
+
28
+ _CITATION = """\
29
+ @InProceedings{MishraBMVC12,
30
+ author = "Mishra, A. and Alahari, K. and Jawahar, C.~V.",
31
+ title = "Scene Text Recognition using Higher Order Language Priors",
32
+ booktitle= "BMVC",
33
+ year = "2012"
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ The IIIT 5K-Word dataset is harvested from Google image search.
39
+ Query words like billboards, signboard, house numbers, house name plates, movie posters were used to collect images.
40
+ The dataset contains 5000 cropped word images from Scene Texts and born-digital images.
41
+ The dataset is divided into train and test parts.
42
+ This dataset can be used for large lexicon cropped word recognition.
43
+ We also provide a lexicon of more than 0.5 million dictionary words with this dataset.
44
+ """
45
+
46
+ _HOMEPAGE = "http://cvit.iiit.ac.in/projects/SceneTextUnderstanding/IIIT5K.html"
47
+
48
+ _DL_URL = "http://cvit.iiit.ac.in/projects/SceneTextUnderstanding/IIIT5K-Word_V3.0.tar.gz"
49
+
50
+
51
+ class IIIT5K(datasets.GeneratorBasedBuilder):
52
+ """IIIT-5K dataset."""
53
+
54
+ def _info(self):
55
+ features = datasets.Features(
56
+ {
57
+ "image": datasets.Image(),
58
+ "label": datasets.Value("string"),
59
+ "small_lexicon": datasets.Sequence(datasets.Value("string")),
60
+ "medium_lexicon": datasets.Sequence(datasets.Value("string")),
61
+ }
62
+ )
63
+
64
+ return datasets.DatasetInfo(
65
+ description=_DESCRIPTION,
66
+ features=features,
67
+ homepage=_HOMEPAGE,
68
+ citation=_CITATION,
69
+ )
70
+
71
+ def _split_generators(self, dl_manager):
72
+ archive_path = dl_manager.download_and_extract(_DL_URL)
73
+ return [
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.TRAIN,
76
+ gen_kwargs={
77
+ "split": "train",
78
+ "archive_path": Path(archive_path) / "IIIT5K",
79
+ "info_path": Path(archive_path) / "IIIT5K/traindata.mat",
80
+ },
81
+ ),
82
+ datasets.SplitGenerator(
83
+ name=datasets.Split.TEST,
84
+ gen_kwargs={
85
+ "split": "test",
86
+ "archive_path": Path(archive_path) / "IIIT5K",
87
+ "info_path": Path(archive_path) / "IIIT5K/testdata.mat",
88
+ },
89
+ ),
90
+ ]
91
+
92
+ def _generate_examples(self, split, archive_path, info_path):
93
+ info = scipy.io.loadmat(info_path)
94
+ info = info[split+"data"][0]
95
+
96
+ for idx, info_ex in enumerate(info):
97
+ path_image = os.path.join(archive_path, str(info_ex[0][0]))
98
+ label = str(info_ex[1][0])
99
+ small_lexicon = [str(lab[0]) for lab in info_ex[2][0]]
100
+ medium_lexicon = [str(lab[0]) for lab in info_ex[3][0]]
101
+ yield idx, {
102
+ "image": path_image,
103
+ "label": label,
104
+ "small_lexicon": small_lexicon,
105
+ "medium_lexicon": medium_lexicon,
106
+ }