Skip to content

Commit d64761e

Browse files
dshabinVaghinakDev
authored andcommitted
Update requirements.txt
1 parent 6e60624 commit d64761e

File tree

4 files changed

+101
-70
lines changed

4 files changed

+101
-70
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ mixpanel==4.8.3
1818
pydantic>=1.8.2
1919
setuptools~=57.4.0
2020
aiohttp==3.8.1
21-
21+
email-validator>=1.0.3
22+
nest-asyncio==1.5.4

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def execute(self):
547547
reporter=self.reporter
548548
)
549549
received_items_count = len(annotations)
550+
self.reporter.finish_progress()
550551
if items_count > received_items_count:
551552
self.reporter.log_warning(
552553
f"Could not find annotations for {items_count - received_items_count}/{items_count} items."

src/superannotate/lib/core/video_convertor.py

Lines changed: 94 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
from collections import defaultdict
23
from typing import Any
34
from typing import Dict
@@ -64,7 +65,7 @@ def interpolate_annotations(
6465
):
6566
for idx, frame_idx in enumerate(range(from_frame, to_frame), 1):
6667
keyframe = False
67-
if idx in (1, len(range(from_frame, to_frame))):
68+
if idx == 1:
6869
keyframe = True
6970
points = None
7071
if annotation_type == "bbox":
@@ -74,78 +75,104 @@ def interpolate_annotations(
7475
"x2": round(data["points"]["x2"] + steps["x2"] * idx, 2),
7576
"y2": round(data["points"]["y2"] + steps["y2"] * idx, 2),
7677
}
77-
frame = self.get_frame(frame_idx)
78-
frame.annotations.append(Annotation(
79-
type=annotation_type,
80-
className=class_name,
78+
self._add_annotation(
79+
frame_idx,
80+
annotation_type=annotation_type,
81+
class_name=class_name,
8182
points=points,
8283
attributes=data["attributes"],
8384
keyframe=keyframe
84-
))
85+
)
86+
87+
def _add_annotation(
88+
self,
89+
frame_no: int,
90+
annotation_type: str,
91+
class_name: str,
92+
points: list = None,
93+
attributes: list = None,
94+
keyframe: bool = False
95+
):
96+
frame = self.get_frame(frame_no)
97+
frame.annotations.append(Annotation(
98+
type=annotation_type,
99+
className=class_name,
100+
points=points,
101+
attributes=attributes,
102+
keyframe=keyframe
103+
))
85104

86105
def _process(self):
87106
for instance in self._annotation_data["instances"]:
88-
try:
89-
for parameter in instance["parameters"]:
90-
time_stamp_frame_map = []
91-
for timestamp in parameter["timestamps"]:
92-
time_stamp_frame_map.append((round(timestamp["timestamp"] / self.ratio) + 1, timestamp))
93-
for idx, (frame_no, timestamp_data) in enumerate(time_stamp_frame_map):
94-
annotation_type = instance["meta"]["type"]
95-
try:
96-
next_frame_no, next_timestamp = time_stamp_frame_map[idx + 1]
97-
if frame_no == next_frame_no:
98-
median = (timestamp_data["timestamp"] // self.ratio) + (self.ratio / 2)
99-
if abs(median - timestamp_data["timestamp"]) < abs(median - next_timestamp["timestamp"]):
100-
time_stamp_frame_map[idx + 1] = timestamp_data
101-
continue
102-
103-
frames_diff = next_frame_no - frame_no
104-
steps = None
105-
if annotation_type == "bbox":
106-
if not frames_diff:
107-
steps = {
108-
"y1": 0,
109-
"x2": 0,
110-
"x1": 0,
111-
"y2": 0
112-
}
113-
else:
114-
steps = {
115-
"y1": round(
116-
(next_timestamp["points"]["y1"] - timestamp_data["points"]["y1"]) / frames_diff,
117-
2),
118-
"x2": round(
119-
(next_timestamp["points"]["x2"] - timestamp_data["points"]["x2"]) / frames_diff,
120-
2),
121-
"x1": round(
122-
(next_timestamp["points"]["x1"] - timestamp_data["points"]["x1"]) / frames_diff,
123-
2),
124-
"y2": round(
125-
(next_timestamp["points"]["y2"] - timestamp_data["points"]["y2"]) / frames_diff,
126-
2),
127-
}
128-
self.interpolate_annotations(
129-
class_name=instance["meta"]["className"],
130-
from_frame=frame_no,
131-
to_frame=next_frame_no,
132-
data=timestamp_data,
133-
steps=steps,
134-
annotation_type=annotation_type
135-
)
136-
except IndexError:
137-
last_frame_no, last_timestamp = time_stamp_frame_map[-1]
138-
end = round(parameter["end"] / self.ratio)
139-
self.interpolate_annotations(
140-
annotation_type=annotation_type,
141-
class_name=instance["meta"]["className"],
142-
from_frame=last_frame_no,
143-
to_frame=end,
144-
data=last_timestamp,
145-
steps={"x1": 0, "y1": 0, "x2": 0, "y2": 0}
146-
)
147-
except Exception as e:
148-
pass
107+
for parameter in instance["parameters"]:
108+
time_stamp_frame_map = []
109+
for timestamp in parameter["timestamps"]:
110+
time_stamp_frame_map.append((int(math.ceil(timestamp["timestamp"] / self.ratio)), timestamp))
111+
skip_current = False
112+
for idx, (frame_no, timestamp_data) in enumerate(time_stamp_frame_map):
113+
annotation_type = instance["meta"]["type"]
114+
try:
115+
next_frame_no, next_timestamp = time_stamp_frame_map[idx + 1]
116+
if frame_no == next_frame_no:
117+
median = (timestamp_data["timestamp"] // self.ratio) + (self.ratio / 2)
118+
if abs(median - timestamp_data["timestamp"]) < abs(
119+
median - next_timestamp["timestamp"]) and not skip_current:
120+
time_stamp_frame_map[idx + 1] = (frame_no, timestamp_data)
121+
self._add_annotation(
122+
frame_no=frame_no,
123+
annotation_type=annotation_type,
124+
class_name=instance["meta"]["className"],
125+
points=timestamp_data.get("points"),
126+
attributes=timestamp_data.get("attributes"),
127+
keyframe=True
128+
)
129+
skip_current = True
130+
elif skip_current:
131+
frame_no += 1
132+
skip_current = False
133+
134+
frames_diff = next_frame_no - frame_no
135+
steps = None
136+
if annotation_type == "bbox":
137+
if not frames_diff:
138+
steps = {
139+
"y1": 0,
140+
"x2": 0,
141+
"x1": 0,
142+
"y2": 0
143+
}
144+
else:
145+
steps = {
146+
"y1": round(
147+
(next_timestamp["points"]["y1"] - timestamp_data["points"]["y1"]) / frames_diff,
148+
2),
149+
"x2": round(
150+
(next_timestamp["points"]["x2"] - timestamp_data["points"]["x2"]) / frames_diff,
151+
2),
152+
"x1": round(
153+
(next_timestamp["points"]["x1"] - timestamp_data["points"]["x1"]) / frames_diff,
154+
2),
155+
"y2": round(
156+
(next_timestamp["points"]["y2"] - timestamp_data["points"]["y2"]) / frames_diff,
157+
2),
158+
}
159+
self.interpolate_annotations(
160+
class_name=instance["meta"]["className"],
161+
from_frame=frame_no,
162+
to_frame=next_frame_no,
163+
data=timestamp_data,
164+
steps=steps,
165+
annotation_type=annotation_type
166+
)
167+
except IndexError:
168+
frame = self.get_frame(frame_no)
169+
frame.annotations.append(Annotation(
170+
type=annotation_type,
171+
className=instance["meta"]["className"],
172+
points=timestamp_data.get("points"),
173+
attributes=timestamp_data.get("attributes"),
174+
keyframe=True
175+
))
149176

150177
def __iter__(self):
151178
for frame_no in range(1, int(self.frames_count) + 1):

src/superannotate/lib/infrastructure/services.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,9 @@ def get_annotations(
10261026
items: List[str],
10271027
reporter: Reporter
10281028
) -> List[dict]:
1029-
get_limits_url = urljoin(self.assets_provider_url, self.URL_GET_ANNOTATIONS)
1029+
import nest_asyncio
1030+
nest_asyncio.apply()
1031+
10301032
query_params = {
10311033
"team_id": team_id,
10321034
"project_id": project_id,
@@ -1038,7 +1040,7 @@ def get_annotations(
10381040
loop = asyncio.new_event_loop()
10391041

10401042
return loop.run_until_complete(handler.get_data(
1041-
url=get_limits_url,
1043+
url=urljoin(self.assets_provider_url, self.URL_GET_ANNOTATIONS),
10421044
data=items,
10431045
params=query_params,
10441046
chunk_size=self.DEFAULT_CHUNK_SIZE,

0 commit comments

Comments
 (0)