-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob_annotations.py
More file actions
90 lines (66 loc) · 2.15 KB
/
Copy pathjob_annotations.py
File metadata and controls
90 lines (66 loc) · 2.15 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import annotations
from typing import TYPE_CHECKING
from cvat_sdk.api_client import models
from pydantic import BaseModel
import next_cvat
if TYPE_CHECKING:
from .job import Job
class JobAnnotations(BaseModel, arbitrary_types_allowed=True):
job: Job
annotations: dict
def add_mask_(
self,
mask: next_cvat.Mask,
image_name: str,
group: int = 0,
) -> JobAnnotations:
label = self.job.task.project.label(name=mask.label)
frame = self.job.task.frame(image_name=image_name)
self.annotations["shapes"].append(
mask.request(
frame=frame.id,
label_id=label.id,
group=group,
)
)
return self
def add_polyline_(
self,
polyline: next_cvat.Polyline,
image_name: str,
group: int = 0,
) -> JobAnnotations:
label = self.job.task.project.label(name=polyline.label)
frame = self.job.task.frame(image_name=image_name)
self.annotations["shapes"].append(
polyline.request(frame=frame.id, label_id=label.id, group=group)
)
return self
def add_polygon_(
self,
polygon: next_cvat.Polygon,
image_name: str,
group: int = 0,
) -> JobAnnotations:
label = self.job.task.project.label(name=polygon.label)
frame = self.job.task.frame(image_name=image_name)
self.annotations["shapes"].append(
polygon.request(frame=frame.id, label_id=label.id, group=group)
)
return self
def add_tag_(
self,
tag: next_cvat.Tag,
image_name: str,
group: int = 0,
) -> JobAnnotations:
label = self.job.task.project.label(name=tag.label)
frame = self.job.task.frame(image_name=image_name)
self.annotations["tags"].append(
tag.request(frame=frame.id, label_id=label.id, group=group)
)
return self
def request(self) -> models.LabeledDataRequest:
request = models.LabeledDataRequest()
request.version = self.annotations["version"]
return request