-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
38 lines (32 loc) · 957 Bytes
/
models.py
File metadata and controls
38 lines (32 loc) · 957 Bytes
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
from dataclasses import dataclass
from typing import List, Optional, Tuple
import numpy as np
@dataclass
class Annotation:
label: str
score: float
bbox: List[float]
mask: Optional[np.ndarray] = None
@dataclass
class ProcessedImage:
filename: str
image_b64: str
annotations: List[Annotation]
is_annotated: bool
image_size: Tuple[int, int] # (width, height)
def to_export_dict(self) -> dict:
"""Convert to a dict for export, keeping masks for downstream processing."""
return {
"filename": self.filename,
"is_annotated": self.is_annotated,
"image_size": self.image_size,
"annotations": [
{
"label": ann.label,
"score": ann.score,
"bbox": ann.bbox,
"mask": ann.mask,
}
for ann in self.annotations
],
}