Skip to content

Commit e21f8e9

Browse files
committed
2 parents f1f6b2f + 611e0c2 commit e21f8e9

File tree

4 files changed

+334
-16
lines changed

4 files changed

+334
-16
lines changed

src/superannotate/lib/core/helpers.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def fill_annotation_ids(
119119

120120

121121
def convert_to_video_editor_json(data: dict, class_name_mapper: dict, reporter: Reporter):
122-
id_generator = class_id_generator()
123-
next(id_generator)
122+
id_generator = ClassIdGenerator()
124123

125124
def safe_time(timestamp):
126125
return "0" if str(timestamp) == "0.0" else timestamp
@@ -146,9 +145,12 @@ def convert_timestamp(timestamp):
146145
"attributes": [],
147146
"timeline": {},
148147
"type": meta["type"],
149-
"classId": class_name_mapper.get(class_name, {}).get("id", id_generator.send(class_name)),
150148
"locked": True,
151149
}
150+
if class_name:
151+
editor_instance["classId"] = class_name_mapper.get(class_name, {}).get("id", id_generator.send(class_name))
152+
else:
153+
editor_instance["classId"] = id_generator.send("unknown_class")
152154
if meta.get("pointLabels", None):
153155
editor_instance["pointLabels"] = meta["pointLabels"]
154156
active_attributes = set()
@@ -171,8 +173,9 @@ def convert_timestamp(timestamp):
171173
editor_instance["timeline"][timestamp]["points"] = timestamp_data[
172174
"points"
173175
]
174-
175-
if not class_name_mapper.get(meta.get("className"), None):
176+
if not class_name:
177+
continue
178+
elif not class_name_mapper.get(class_name):
176179
reporter.store_message("missing_classes", meta["className"])
177180
continue
178181

@@ -232,13 +235,13 @@ def default(self, obj):
232235
return json.JSONEncoder.default(self, obj)
233236

234237

235-
def class_id_generator():
236-
classes = defaultdict(int)
237-
class_id = -1
238-
while True:
239-
class_name = yield str(class_id)
240-
if class_name:
241-
if class_name not in classes:
242-
classes[class_name] = class_id
243-
else:
244-
class_id -= 1
238+
class ClassIdGenerator:
239+
def __init__(self):
240+
self.classes = defaultdict(int)
241+
self.idx = -1
242+
243+
def send(self, class_name: str):
244+
if class_name not in self.classes:
245+
self.classes[class_name] = self.idx
246+
self.idx -= 1
247+
return self.classes[class_name]

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _upload_annotation(
173173
return path, False
174174
return path, True
175175
except Exception as e:
176-
# raise e
176+
raise e
177177
return path, False
178178

179179
def get_bucket_to_upload(self, ids: List[int]):
@@ -341,6 +341,10 @@ def set_annotation_json(self):
341341
self._annotation_json = json.load(self.get_s3_file(self.from_s3, self._annotation_path))
342342
if self._project.project_type == constances.ProjectType.PIXEL.value:
343343
self._mask = self.get_s3_file(self.from_s3, self._annotation_path.replace(constances.PIXEL_ANNOTATION_POSTFIX, constances.ANNOTATION_MASK_POSTFIX))
344+
else:
345+
self._annotation_json = json.load(open(self._annotation_path))
346+
if self._project.project_type == constances.ProjectType.PIXEL.value:
347+
self._mask = open(self._annotation_path.replace(constances.PIXEL_ANNOTATION_POSTFIX, constances.ANNOTATION_MASK_POSTFIX))
344348

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

0 commit comments

Comments
 (0)