Skip to content

Commit 8ad80c2

Browse files
authored
Merge pull request #300 from superannotateai/video-validations
Video validations
2 parents 8bc6819 + 8ec36da commit 8ad80c2

File tree

6 files changed

+331
-16
lines changed

6 files changed

+331
-16
lines changed

src/superannotate/lib/core/entities/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
def enum_error_handling(self) -> str:
16-
permitted = ', '.join(repr(v.value) for v in self.enum_values)
17-
return f'Invalid value, permitted: {permitted}'
16+
permitted = ", ".join(repr(v.value) for v in self.enum_values)
17+
return f"Invalid value, permitted: {permitted}"
1818

1919

2020
EnumMemberError.__str__ = enum_error_handling
@@ -23,7 +23,7 @@ def enum_error_handling(self) -> str:
2323
NotEmptyStr = constr(strict=True, min_length=1)
2424

2525

26-
DATE_REGEX = r'\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z'
26+
DATE_REGEX = r"\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z"
2727

2828

2929
class BaseModel(PyDanticBaseModel):
@@ -112,7 +112,9 @@ class UserAction(BaseModel):
112112
class TrackableModel(BaseModel):
113113
created_by: Optional[UserAction] = Field(None, alias="createdBy")
114114
updated_by: Optional[UserAction] = Field(None, alias="updatedBy")
115-
creation_type: Optional[CreationTypeEnum] = Field(CreationTypeEnum.PRE_ANNOTATION.value, alias="creationType")
115+
creation_type: Optional[CreationTypeEnum] = Field(
116+
CreationTypeEnum.PRE_ANNOTATION.value, alias="creationType"
117+
)
116118

117119
@validator("creation_type", always=True)
118120
def clean_creation_type(cls, _):

src/superannotate/lib/core/entities/vector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ class Cuboid(BaseVectorInstance):
100100

101101

102102
class AnnotationInstance(BaseModel):
103-
__root__: Union[Template, Cuboid, Point, PolyLine, Polygon, Bbox, Ellipse, RotatedBox]
103+
__root__: Union[
104+
Template, Cuboid, Point, PolyLine, Polygon, Bbox, Ellipse, RotatedBox
105+
]
104106

105107
@classmethod
106108
def __get_validators__(cls):
@@ -115,7 +117,9 @@ def return_action(cls, values):
115117
try:
116118
return ANNOTATION_TYPES[instance_type](**values)
117119
except KeyError:
118-
raise ValueError(f"invalid type, valid types is {', '.join(ANNOTATION_TYPES.keys())}")
120+
raise ValueError(
121+
f"invalid type, valid types is {', '.join(ANNOTATION_TYPES.keys())}"
122+
)
119123

120124

121125
class VectorAnnotation(BaseModel):

src/superannotate/lib/core/entities/video_export.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ class EventInstance(BaseModel):
8989
parameters: conlist(EventParameter, min_items=1)
9090

9191

92-
INSTANCES = {
93-
VideoType.BBOX.value: BboxInstance,
94-
VideoType.EVENT.value: EventInstance
95-
}
92+
INSTANCES = {VideoType.BBOX.value: BboxInstance, VideoType.EVENT.value: EventInstance}
9693

9794

9895
class VideoInstance(BaseModel):
@@ -107,13 +104,13 @@ def return_action(cls, values):
107104
try:
108105
instance_type = values["meta"]["type"]
109106
except KeyError:
110-
raise ValueError(
111-
"meta.type required"
112-
)
107+
raise ValueError("meta.type required")
113108
try:
114109
return INSTANCES[instance_type](**values)
115110
except KeyError:
116-
raise ValueError(f"invalid type, valid types is {', '.join(INSTANCES.keys())}")
111+
raise ValueError(
112+
f"invalid type, valid types is {', '.join(INSTANCES.keys())}"
113+
)
117114

118115

119116
class VideoAnnotation(BaseModel):

src/superannotate/lib/core/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,22 @@ def convert_timestamp(timestamp):
148148
"tags": data["tags"],
149149
"name": data["metadata"]["name"],
150150
"metadata": {
151-
"duration": convert_timestamp(data["metadata"]["duration"]),
152151
"name": data["metadata"]["name"],
153152
"width": data["metadata"].get("width"),
154153
"height": data["metadata"].get("height"),
155154
},
156155
}
156+
if data["metadata"].get("duration"):
157+
editor_data["metadata"]["duration"] = convert_timestamp(
158+
data["metadata"]["duration"]
159+
)
157160
for instance in data["instances"]:
158161
meta = instance["meta"]
159162
class_name = meta.get("className")
160163
editor_instance = {
161164
"attributes": [],
162165
"timeline": {},
163166
"type": meta["type"],
164-
# TODO check
165167
"locked": False,
166168
}
167169
if class_name:
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
{
2+
"metadata": {
3+
"name": "video.mp4"
4+
},
5+
"instances": [
6+
{
7+
"meta": {
8+
"type": "bbox",
9+
"classId": 859496,
10+
"className": "vid",
11+
"pointLabels": {
12+
"3": "point label bro"
13+
},
14+
"start": 0,
15+
"end": 30526667
16+
},
17+
"parameters": [
18+
{
19+
"start": 0,
20+
"end": 30526667,
21+
"timestamps": [
22+
{
23+
"points": {
24+
"x1": 223.32,
25+
"y1": 78.45,
26+
"x2": 312.31,
27+
"y2": 176.66
28+
},
29+
"timestamp": 0,
30+
"attributes": []
31+
},
32+
{
33+
"points": {
34+
"x1": 182.08,
35+
"y1": 33.18,
36+
"x2": 283.45,
37+
"y2": 131.39
38+
},
39+
"timestamp": 17271058,
40+
"attributes": [
41+
{
42+
"id": 1175876,
43+
"groupId": 338357,
44+
"name": "attr",
45+
"groupName": "attr g"
46+
}
47+
]
48+
},
49+
{
50+
"points": {
51+
"x1": 182.32,
52+
"y1": 36.33,
53+
"x2": 284.01,
54+
"y2": 134.54
55+
},
56+
"timestamp": 18271058,
57+
"attributes": [
58+
{
59+
"id": 1175876,
60+
"groupId": 338357,
61+
"name": "attr",
62+
"groupName": "attr g"
63+
}
64+
]
65+
},
66+
{
67+
"points": {
68+
"x1": 181.49,
69+
"y1": 45.09,
70+
"x2": 283.18,
71+
"y2": 143.3
72+
},
73+
"timestamp": 19271058,
74+
"attributes": [
75+
{
76+
"id": 1175876,
77+
"groupId": 338357,
78+
"name": "attr",
79+
"groupName": "attr g"
80+
}
81+
]
82+
},
83+
{
84+
"points": {
85+
"x1": 181.9,
86+
"y1": 48.35,
87+
"x2": 283.59,
88+
"y2": 146.56
89+
},
90+
"timestamp": 19725864,
91+
"attributes": [
92+
{
93+
"id": 1175876,
94+
"groupId": 338357,
95+
"name": "attr",
96+
"groupName": "attr g"
97+
}
98+
]
99+
},
100+
{
101+
"points": {
102+
"x1": 181.49,
103+
"y1": 52.46,
104+
"x2": 283.18,
105+
"y2": 150.67
106+
},
107+
"timestamp": 20271058,
108+
"attributes": [
109+
{
110+
"id": 1175876,
111+
"groupId": 338357,
112+
"name": "attr",
113+
"groupName": "attr g"
114+
}
115+
]
116+
},
117+
{
118+
"points": {
119+
"x1": 181.49,
120+
"y1": 63.7,
121+
"x2": 283.18,
122+
"y2": 161.91
123+
},
124+
"timestamp": 21271058,
125+
"attributes": [
126+
{
127+
"id": 1175876,
128+
"groupId": 338357,
129+
"name": "attr",
130+
"groupName": "attr g"
131+
}
132+
]
133+
},
134+
{
135+
"points": {
136+
"x1": 182.07,
137+
"y1": 72.76,
138+
"x2": 283.76,
139+
"y2": 170.97
140+
},
141+
"timestamp": 22271058,
142+
"attributes": [
143+
{
144+
"id": 1175876,
145+
"groupId": 338357,
146+
"name": "attr",
147+
"groupName": "attr g"
148+
}
149+
]
150+
},
151+
{
152+
"points": {
153+
"x1": 182.07,
154+
"y1": 81.51,
155+
"x2": 283.76,
156+
"y2": 179.72
157+
},
158+
"timestamp": 23271058,
159+
"attributes": [
160+
{
161+
"id": 1175876,
162+
"groupId": 338357,
163+
"name": "attr",
164+
"groupName": "attr g"
165+
}
166+
]
167+
},
168+
{
169+
"points": {
170+
"x1": 182.42,
171+
"y1": 97.19,
172+
"x2": 284.11,
173+
"y2": 195.4
174+
},
175+
"timestamp": 24271058,
176+
"attributes": [
177+
{
178+
"id": 1175876,
179+
"groupId": 338357,
180+
"name": "attr",
181+
"groupName": "attr g"
182+
}
183+
]
184+
},
185+
{
186+
"points": {
187+
"x1": 182.42,
188+
"y1": 97.19,
189+
"x2": 284.11,
190+
"y2": 195.4
191+
},
192+
"timestamp": 30526667,
193+
"attributes": [
194+
{
195+
"id": 1175876,
196+
"groupId": 338357,
197+
"name": "attr",
198+
"groupName": "attr g"
199+
}
200+
]
201+
}
202+
]
203+
}
204+
]
205+
},
206+
{
207+
"meta": {
208+
"type": "bbox",
209+
"classId": 859496,
210+
"className": "vid",
211+
"start": 29713736,
212+
"end": 30526667
213+
},
214+
"parameters": [
215+
{
216+
"start": 29713736,
217+
"end": 30526667,
218+
"timestamps": [
219+
{
220+
"points": {
221+
"x1": 132.82,
222+
"y1": 129.12,
223+
"x2": 175.16,
224+
"y2": 188
225+
},
226+
"timestamp": 29713736,
227+
"attributes": []
228+
},
229+
{
230+
"points": {
231+
"x1": 132.82,
232+
"y1": 129.12,
233+
"x2": 175.16,
234+
"y2": 188
235+
},
236+
"timestamp": 30526667,
237+
"attributes": []
238+
}
239+
]
240+
}
241+
]
242+
},
243+
{
244+
"meta": {
245+
"type": "event",
246+
"classId": 859496,
247+
"className": "vid",
248+
"start": 5528212,
249+
"end": 7083022
250+
},
251+
"parameters": [
252+
{
253+
"start": 5528212,
254+
"end": 7083022,
255+
"timestamps": [
256+
{
257+
"timestamp": 5528212,
258+
"attributes": []
259+
},
260+
{
261+
"timestamp": 6702957,
262+
"attributes": [
263+
{
264+
"id": 1175876,
265+
"groupId": 338357,
266+
"name": "attr",
267+
"groupName": "attr g"
268+
}
269+
]
270+
},
271+
{
272+
"timestamp": 7083022,
273+
"attributes": [
274+
{
275+
"id": 1175876,
276+
"groupId": 338357,
277+
"name": "attr",
278+
"groupName": "attr g"
279+
}
280+
]
281+
}
282+
]
283+
}
284+
]
285+
}
286+
],
287+
"tags": [
288+
"some tag"
289+
]
290+
}

0 commit comments

Comments
 (0)