Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
dbolya
GitHub Repository: dbolya/tide
Path: blob/master/tidecv/errors/qualifiers.py
110 views
1
# Defines qualifiers like "Extra small box"
2
3
4
5
def _area(x):
6
return x['bbox'][2] * x['bbox'][3]
7
8
def _ar(x):
9
return x['bbox'][2] / x['bbox'][3]
10
11
12
13
class Qualifier():
14
"""
15
Creates a qualifier with the given name.
16
17
test_func should be a callable object (e.g., lambda) that takes in as input an annotation
18
object (either a ground truth or prediction) and returns whether or not that object qualifies (i.e., a bool).
19
"""
20
21
def __init__(self, name:str, test_func:object):
22
self.test = test_func
23
self.name = name
24
25
# This is horrible, but I like it
26
def _make_error_func(self, error_type):
27
return (lambda err: isinstance(err, error_type) \
28
and (self.test(err.gt) if hasattr(err, 'gt') else self.test(err.pred))) \
29
if self.test is not None else (lambda err: isinstance(err, error_type))
30
31
32
33
34
AREA = [
35
Qualifier('Small' , lambda x: _area(x) <= 32 ** 2),
36
Qualifier('Medium', lambda x: 32 ** 2 < _area(x) <= 96 ** 2),
37
Qualifier('Large' , lambda x: 96 ** 2 < _area(x) ),
38
]
39
40
ASPECT_RATIO = [
41
Qualifier('Tall' , lambda x: _ar(x) <= 0.75),
42
Qualifier('Square', lambda x: 0.75 < _ar(x) <= 1.33),
43
Qualifier('Wide' , lambda x: 1.33 < _ar(x) ),
44
]
45
46
47
48
49