-
Notifications
You must be signed in to change notification settings - Fork 4
/
core.py
71 lines (64 loc) · 1.74 KB
/
core.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
66
67
68
69
70
71
from typing import Union
class BoundingBox(object):
__slots__ = [
'image_id',
'x_min',
'y_min',
'x_max',
'y_max',
'category',
'confidence',
'x_center',
'y_center'
]
def __init__(
self,
image_id: Union[int, str],
x_min: float,
x_max: float,
y_min: float,
y_max: float,
category: int,
confidence: float = 1.0
):
if not (0.0 <= x_min <= x_max <= 1.0 and 0.0 <= y_min <= y_max <= 1.0):
x_min = max(min(x_min, 1.0), 0.0)
y_min = max(min(y_min, 1.0), 0.0)
x_max = max(min(x_max, 1.0), 0.0)
y_max = max(min(y_max, 1.0), 0.0)
self.image_id = image_id
self.x_min = x_min
self.y_min = y_min
self.x_max = x_max
self.y_max = y_max
self.category = category
self.confidence = confidence
self.x_center = (x_min + x_max) / 2
self.y_center = (y_min + y_max) / 2
def get_area(self):
return (self.x_max - self.x_min) * (self.y_max - self.y_min)
class VisualRelationship(object):
__slots__ = [
'image_id',
'index_1',
'index_2',
'box_1',
'box_2',
'category'
]
def __init__(
self,
image_id: int,
index_1: int,
index_2: int,
box_1: BoundingBox,
box_2: BoundingBox,
category: int
):
assert image_id == box_1.image_id == box_2.image_id
self.image_id = image_id
self.index_1 = index_1
self.index_2 = index_2
self.box_1 = box_1
self.box_2 = box_2
self.category = category