Skip to content

Commit 6cf7a1e

Browse files
committed
add the script of iiit5k
1 parent 38ca981 commit 6cf7a1e

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

tools/eval/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Supported datasets:
2020
- [WIDERFace](#widerface)
2121
- [LFW](#lfw)
2222
- [ICDAR](#icdar)
23+
- [IIIT5K](#iiit5k)
2324

2425
## ImageNet
2526

@@ -138,6 +139,7 @@ Run evaluation with the following command:
138139

139140
```shell
140141
python eval.py -m sface -d lfw -dr /path/to/lfw
142+
```
141143

142144
## ICDAR2003
143145

tools/eval/datasets/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .widerface import WIDERFace
33
from .lfw import LFW
44
from .icdar import ICDAR
5-
5+
from .iiit5k import IIIT5K
66

77
class Registery:
88
def __init__(self, name):
@@ -20,3 +20,4 @@ def register(self, item):
2020
DATASETS.register(WIDERFace)
2121
DATASETS.register(LFW)
2222
DATASETS.register(ICDAR)
23+
DATASETS.register(IIIT5K)

tools/eval/datasets/iiit5k.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import lmdb
2+
import os
3+
import numpy as np
4+
import cv2 as cv
5+
from tqdm import tqdm
6+
7+
class IIIT5K:
8+
def __init__(self, root):
9+
self.root = root
10+
self.acc = -1
11+
self.inputSize = [100, 32]
12+
13+
self.val_label = self.load_label(self.root)
14+
15+
@property
16+
def name(self):
17+
return self.__class__.__name__
18+
19+
def load_label(self, root):
20+
lmdb_file = root
21+
lmdb_env = lmdb.open(lmdb_file)
22+
lmdb_txn = lmdb_env.begin()
23+
lmdb_cursor = lmdb_txn.cursor()
24+
label = list()
25+
for key, value in lmdb_cursor:
26+
image_index = key.decode()
27+
if image_index.split('-')[0] == 'image':
28+
img = cv.imdecode(np.fromstring(value, np.uint8), 3)
29+
label_index = 'label-' + image_index.split('-')[1]
30+
value = lmdb_txn.get(label_index.encode()).decode().lower()
31+
label.append([img, value])
32+
else:
33+
break
34+
return label
35+
36+
def eval(self, model):
37+
right_num = 0
38+
pbar = tqdm(self.val_label)
39+
for img, value in pbar:
40+
pbar.set_description("Evaluating {} with {} val set".format(model.name, self.name))
41+
42+
43+
rbbox = np.array([0, img.shape[0], 0, 0, img.shape[1], 0, img.shape[1], img.shape[0]])
44+
pred = model.infer(img, rbbox).lower()
45+
if value == pred:
46+
right_num += 1
47+
48+
self.acc = right_num/(len(self.val_label) * 1.0)
49+
50+
51+
def get_result(self):
52+
return self.acc
53+
54+
def print_result(self):
55+
print("Accuracy: {:.2f}%".format(self.acc*100))

tools/eval/eval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
target_size=112),
9696
icdar=dict(
9797
name="ICDAR",
98-
topic="text_recognition")
98+
topic="text_recognition"),
9999
)
100100

101101
def main(args):

0 commit comments

Comments
 (0)