MCPcopy Create free account
hub / github.com/MichaelHL-ai/OCR_EVALUATION / evaluate_method

Function evaluate_method

Algorithm_IoU.py:52–411  ·  view source on GitHub ↗

Method evaluate_method: evaluate method and returns the results Results. Dictionary with the following values: - method (required) Global method metrics. Ex: { 'Precision':0.8,'Recall':0.9 } - samples (optional) Per sample metrics. Ex: {'sample1' : { 'Precision':0.8,'Re

(gtFilePath, submFilePath, evaluationParams)

Source from the content-addressed store, hash-verified

50
51
52def evaluate_method(gtFilePath, submFilePath, evaluationParams):
53 """
54 Method evaluate_method: evaluate method and returns the results
55 Results. Dictionary with the following values:
56 - method (required) Global method metrics. Ex: { 'Precision':0.8,'Recall':0.9 }
57 - samples (optional) Per sample metrics. Ex: {'sample1' : { 'Precision':0.8,'Recall':0.9 } , 'sample2' : { 'Precision':0.8,'Recall':0.9 }
58 """
59 if evaluationParams['E2E']:
60 from hanziconv import HanziConv
61 import editdistance
62
63 def polygon_from_points(points):
64 """
65 Returns a Polygon object to use with the Polygon2 class from a list of 8 points: x1,y1,x2,y2,x3,y3,x4,y4
66 """
67 resBoxes = np.empty([1, 8], dtype='int32')
68 resBoxes[0, 0] = int(points[0])
69 resBoxes[0, 4] = int(points[1])
70 resBoxes[0, 1] = int(points[2])
71 resBoxes[0, 5] = int(points[3])
72 resBoxes[0, 2] = int(points[4])
73 resBoxes[0, 6] = int(points[5])
74 resBoxes[0, 3] = int(points[6])
75 resBoxes[0, 7] = int(points[7])
76 pointMat = resBoxes[0].reshape([2, 4]).T
77 return Polygon(pointMat)
78
79 def rectangle_to_polygon(rect):
80 resBoxes = np.empty([1, 8], dtype='int32')
81 resBoxes[0, 0] = int(rect.xmin)
82 resBoxes[0, 4] = int(rect.ymax)
83 resBoxes[0, 1] = int(rect.xmin)
84 resBoxes[0, 5] = int(rect.ymin)
85 resBoxes[0, 2] = int(rect.xmax)
86 resBoxes[0, 6] = int(rect.ymin)
87 resBoxes[0, 3] = int(rect.xmax)
88 resBoxes[0, 7] = int(rect.ymax)
89
90 pointMat = resBoxes[0].reshape([2, 4]).T
91
92 return Polygon(pointMat)
93
94 def rectangle_to_points(rect):
95 points = [int(rect.xmin), int(rect.ymax), int(rect.xmax), int(rect.ymax), int(rect.xmax), int(rect.ymin),
96 int(rect.xmin), int(rect.ymin)]
97 return points
98
99 def get_union(pD, pG):
100 areaA = pD.area
101 areaB = pG.area
102 return areaA + areaB - get_intersection(pD, pG)
103
104 def get_intersection_over_union(pD, pG):
105 try:
106 return get_intersection(pD, pG) / get_union(pD, pG)
107 except:
108 return 0
109

Callers

nothing calls this directly

Calls 6

rectangle_to_polygonFunction · 0.85
polygon_from_pointsFunction · 0.85
get_intersectionFunction · 0.85
text_distanceFunction · 0.85
compute_apFunction · 0.85

Tested by

no test coverage detected