-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverall_segmented_accuracy.py
65 lines (53 loc) · 1.79 KB
/
overall_segmented_accuracy.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
import os
import gettrace
import segment
import itertools
import inkml_to_pixels as itp
import pickle
relative_path2011 = 'ICFHR_package/CROHME2011_data/CROHME_training/CROHME_training/'
relative_path2012 = 'ICFHR_package/CROHME2012_data/trainData/trainData/'
relative_testpath2011 = 'ICFHR_package/CROHME2011_data/CROHME_testGT/CROHME_testGT/'
relative_testpath2012 = 'ICFHR_package/CROHME2012_data/testDataGT/'
def getSegmentationAccuracy(pathArray):
f = open('svm18px', "r")
svm = pickle.load(f)
j = 0
total = 0
total_correct = 0
off_by_one = 0
off_by_two = 0
for path in pathArray:
for f in os.listdir(path):
j+=1
if f[-5:] != "inkml": continue
# print f
traceList, symbolsList = gettrace.parseINKMLFile(path + f)
segmentIndices = segment.segmentSymbols(traceList)
correct = 0
for label, elem in symbolsList:
# Correctly classified
if elem in segmentIndices:
strokes = [traceList[i] for i in elem]
pixels = itp.inkml_to_pixels(strokes)
chain = list(itertools.chain(*pixels))
chain.append(len(strokes))
if svm.predict(chain)[0] == label:
correct +=1
if correct == len(symbolsList):
total_correct +=1
if correct + 1 >= len(symbolsList):
off_by_one +=1
if correct + 2 >= len(symbolsList):
off_by_two +=1
# cr.display(pixels)
print j
print total_correct
print off_by_one
print off_by_two
print float(total_correct)/836
print float(off_by_one)/836
print float(off_by_two)/836
if __name__ == "__main__":
# getSegmentationAccuracy([relative_path2011, relative_path2012])
getSegmentationAccuracy([relative_testpath2011, relative_testpath2012])
# getSegmentationAccuracy([relative_testpath2012])