Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
dbolya
GitHub Repository: dbolya/tide
Path: blob/master/tidecv/errors/main_errors.py
110 views
1
from collections import defaultdict
2
import numpy as np
3
4
from .error import Error, BestGTMatch
5
6
class ClassError(Error):
7
8
description = "Error caused when a prediction would have been marked positive " \
9
+ "if it had the correct class."
10
short_name = "Cls"
11
12
def __init__(self, pred:dict, gt:dict, ex):
13
self.pred = pred
14
self.gt = gt
15
16
self.match = BestGTMatch(pred, gt) if not self.gt['used'] else None
17
18
def fix(self):
19
if self.match is None:
20
return None
21
return self.gt['class'], self.match.fix()
22
23
24
class BoxError(Error):
25
26
description = "Error caused when a prediction would have been marked positive if it was localized better."
27
short_name = "Loc"
28
29
def __init__(self, pred:dict, gt:dict, ex):
30
self.pred = pred
31
self.gt = gt
32
33
self.match = BestGTMatch(pred, gt) if not self.gt['used'] else None
34
35
def fix(self):
36
if self.match is None:
37
return None
38
return self.pred['class'], self.match.fix()
39
40
41
class DuplicateError(Error):
42
43
description = "Error caused when a prediction would have been marked positive " \
44
+ "if the GT wasn't already in use by another detection."
45
short_name = "Dupe"
46
47
def __init__(self, pred:dict, suppressor: dict):
48
self.pred = pred
49
self.suppressor = suppressor
50
51
def fix(self):
52
return None
53
54
class BackgroundError(Error):
55
56
description = "Error caused when this detection should have been classified as background (IoU < 0.1)."
57
short_name = "Bkg"
58
59
def __init__(self, pred:dict):
60
self.pred = pred
61
62
def fix(self):
63
return None
64
65
66
class OtherError(Error):
67
68
description = "This detection didn't fall into any of the other error categories."
69
short_name = "Both"
70
71
def __init__(self, pred:dict):
72
self.pred = pred
73
74
def fix(self):
75
return None
76
77
78
class MissedError(Error):
79
80
description = "Represents GT missed by the model. Doesn't include GT corrected elsewhere in the model."
81
short_name = "Miss"
82
83
def __init__(self, gt:dict):
84
self.gt = gt
85
86
def fix(self):
87
return self.gt['class'], -1
88
89
90
# These are special errors so no inheritence
91
92
class FalsePositiveError:
93
94
description = "Represents the potential AP gained by having perfect precision" \
95
+ " (e.g., by scoring all false positives as conf=0) without affecting recall."
96
short_name = "FalsePos"
97
98
@staticmethod
99
def fix(score:float, correct:bool, info:dict) -> tuple:
100
if correct:
101
return 1, True, info
102
else:
103
return 0, False, info
104
105
106
class FalseNegativeError:
107
108
description = "Represents the potentially AP gained by having perfect recall" \
109
+ " without affecting precision."
110
short_name = "FalseNeg"
111
112