HugoLaurencon commited on
Commit
744dc75
·
1 Parent(s): 54606c1

IIIT5K dataset

Browse files
Files changed (1) hide show
  1. IIIT-5K.py +104 -0
IIIT-5K.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "archive_path": archive_path,
78
+ "info_path": Path(archive_path) / "traindata.mat",
79
+ },
80
+ ),
81
+ datasets.SplitGenerator(
82
+ name=datasets.Split.TEST,
83
+ gen_kwargs={
84
+ "archive_path": archive_path,
85
+ "info_path": Path(archive_path) / "testdata.mat",
86
+ },
87
+ ),
88
+ ]
89
+
90
+ def _generate_examples(self, archive_path, info_path):
91
+ info = scipy.io.loadmat(info_path)
92
+ info = info["testdata"][0]
93
+
94
+ for idx, info_ex in enumerate(info):
95
+ path_image = os.path.join(archive_path, str(info_ex[0][0]))
96
+ label = str(info_ex[1][0])
97
+ small_lexicon = [str(lab[0]) for lab in info_ex[2][0]]
98
+ medium_lexicon = [str(lab[0]) for lab in info_ex[2][0]]
99
+ yield idx, {
100
+ "image": path_image,
101
+ "label": label,
102
+ "small_lexicon": small_lexicon,
103
+ "medium_lexicon": medium_lexicon,
104
+ }