-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEgoshare_5_TestPerf.py
55 lines (39 loc) · 1.56 KB
/
Egoshare_5_TestPerf.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
#!coding: utf-8
from Break_Egoshare_Captcha import *
MODEL_FOLDER = 'Egoshare/Models'
MODEL_FILES = ['simulation_based_C=1000_KERNEL=1.svm']
TEST_FOLDER = 'Egoshare/DBTest-Captcha_based'
try:
print MODEL_FILE
except:
pass
else:
MODEL_FILES = [MODEL_FILE]
set_files_errors = set([])
for MODEL_FILE in MODEL_FILES:
model = load_model(os.path.join(MODEL_FOLDER, MODEL_FILE))
nbs = 0
errors = 0
for folder, subfolders, files in os.walk(TEST_FOLDER):
if (folder[0] != "."):
loaded = False
for file in [file for file in files if 'bmp' in file]:
if not loaded:
print "Testing on ", folder
loaded = True
im = Image.open(os.path.join(folder, file))
im = im.point(lambda e : e/255)
char, max_score, scores = predict(model, im)
if char == folder[-1]:
#print "SUCCESS"
pass
else:
#print "FAILURE"
set_files_errors.add(file.split('number')[0])
#print "Error: ", char, "detected instead of", folder[-1]
nbs += 1
nb_errors = len(set_files_errors)
nb_captchas_tested = nbs/3
print "\tSuccess rate: ", (1 - (1.*nb_errors/nb_captchas_tested))*100, "%"
print
write(MODEL_FILE + '\t' + str((1 - (1.*nb_errors/nb_captchas_tested))*100) + "%")