-
Notifications
You must be signed in to change notification settings - Fork 542
/
test_ocr.py
69 lines (53 loc) · 1.64 KB
/
test_ocr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import getpass
import psycopg2
from sets import Set
# Error threshold
eps = 0.3
# Get the environment variables
DBNAME = os.environ['DBNAME']
PGUSER = os.environ['PGUSER']
PGPASSWORD = os.environ['PGPASSWORD']
PGHOST = os.environ['PGHOST']
PGPORT = os.environ['PGPORT']
# Stanfard status
std = dict([])
std_res = open('ocr.dat', 'r')
for row in std_res:
if (len(row) < 2): continue
dat = row.strip().split(' ')
std[str(dat[0])] = dat[1]
std_res.close()
# Connect database
conn = psycopg2.connect(database = DBNAME, user = PGUSER, password = PGPASSWORD, host = PGHOST, port = PGPORT)
cur = conn.cursor()
# Check table status
cur.execute("SELECT COUNT(*) FROM features")
for row in cur.fetchall(): num = row[0]
if (std["features"] != str(num)):
print "Error in Table features"
exit(0)
cur.execute("SELECT COUNT(*) FROM label1")
for row in cur.fetchall(): num = row[0]
if (std["label1"] != str(num)):
print "Error in Table label1"
exit(0)
cur.execute("SELECT COUNT(*) FROM label2")
for row in cur.fetchall(): num = row[0]
if (std["label2"] != str(num)):
print "Error in Table label2"
exit(0)
# Check result
cur.execute("SELECT wid, expectation FROM label1_val_inference")
rows = cur.fetchall()
for row in rows:
if (abs(float(std["label1_" + str(row[0])]) - float(row[1])) > eps):
print "Error result in label1_val_inference!"
exit(0)
cur.execute("SELECT wid, expectation FROM label2_val_inference")
rows = cur.fetchall()
for row in rows:
if (abs(float(std["label2_" + str(row[0])]) - float(row[1])) > eps):
print "Error result in label1_val_inference!"
exit(0)
print "Test passed!"