Skip to content

Commit

Permalink
Write predicted results to JSON files in batches during inference to …
Browse files Browse the repository at this point in the history
…enable real-time tracking visualization in the UI
  • Loading branch information
healthonrails committed Nov 14, 2024
1 parent 689c7f3 commit 104f618
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions annolid/tracker/cotracker/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,15 @@ def process_video(self,
pred_tracks, pred_visibility = self.process_step(
window_frames, is_first_step, grid_size, grid_query_frame)
if pred_tracks is not None:
logger.info(
f"Tracking frame {i}, {pred_tracks.shape}, {pred_visibility.shape}")
if i % 100 == 0:
logger.info(
f"Tracking frame {i}, {pred_tracks.shape}, {pred_visibility.shape}")
if is_first_step:
batch_size = self.model.step * 2
else:
batch_size = self.model.step
self.extract_frame_points(
pred_tracks, pred_visibility, batch_size, i)
is_first_step = False
window_frames.append(frame)
if len(window_frames) > self.model.step * 2:
Expand Down Expand Up @@ -288,9 +295,11 @@ def save_current_frame_tracked_points_to_json(self, frame_number, points):
def extract_frame_points(self, tracks: torch.Tensor,
visibility: torch.Tensor = None,
query_frame: int = 0,
start_frame: int = 0):
start_frame: int = 0
):
tracks = tracks[0].long().detach().cpu().numpy()
for t in range(query_frame, tracks.shape[0]):
batch_start = start_frame-query_frame
for t in range(batch_start, tracks.shape[0]):
_points = []
for i in range(tracks.shape[1]):
coord = (tracks[t, i, 0], tracks[t, i, 1])
Expand All @@ -300,7 +309,7 @@ def extract_frame_points(self, tracks: torch.Tensor,
visible = visibility[0, t, i].item()
_points.append((coord, visible))
self.save_current_frame_tracked_points_to_json(
t + start_frame, _points)
t, _points)
message = f"Saved all json file #{tracks.shape[0]}"
logger.info(message)
return message
Expand Down

0 comments on commit 104f618

Please sign in to comment.