From d6d3092e431399577670f7ec90c0172ca2c11bd4 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Tue, 10 Dec 2024 15:43:06 +0100 Subject: [PATCH] Blacklist tools --- trap/frame_emitter.py | 76 +++++++++++++++++++++---------------------- trap/tools.py | 7 ++-- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/trap/frame_emitter.py b/trap/frame_emitter.py index ca6ff0a..6b145ac 100644 --- a/trap/frame_emitter.py +++ b/trap/frame_emitter.py @@ -290,49 +290,49 @@ class Track: t.predictions, t.fps/step_size) - def get_binned(self, bin_size=.5, remove_overlap=True): - """ - For an experiment: what if we predict using only concrete positions, by mapping - dx,dy to a grid. Thus prediction can be for 8 moves, or rather headings - see ~/notes/attachments example svg - """ + # def get_binned(self, bin_size=.5, remove_overlap=True): + # """ + # For an experiment: what if we predict using only concrete positions, by mapping + # dx,dy to a grid. Thus prediction can be for 8 moves, or rather headings + # see ~/notes/attachments example svg + # """ - new_history: List[Detection] = [] - for i, (det0, det1) in enumerate(zip(self.history[:-1], self.history[1:]): - if i == 0: - new_history.append(det0) - continue - if abs(det1.x - new_history[-1].x) < bin_size or abs(det1.y - new_history[-1].y) < bin_size: - continue + # new_history: List[Detection] = [] + # for i, (det0, det1) in enumerate(zip(self.history[:-1], self.history[1:]): + # if i == 0: + # new_history.append(det0) + # continue + # if abs(det1.x - new_history[-1].x) < bin_size or abs(det1.y - new_history[-1].y) < bin_size: + # continue - # det1 falls outside of the box [-bin_size:+bin_size] around last detection + # # det1 falls outside of the box [-bin_size:+bin_size] around last detection - # 1. Interpolate exact point between det0 and det1 that this happens - if abs(det1.x - new_history[-1].x) >= bin_size: - if det1.x - new_history[-1].x >= bin_size: - # det1 left of last - x = new_history[-1].x + bin_size - f = inv_lerp(det0.x, det1.x, x) - elif new_history[-1].x - det1.x >= bin_size: - # det1 left of last - x = new_history[-1].x - bin_size - f = inv_lerp(det0.x, det1.x, x) - y = lerp(det0.y, det1.y, f) - if abs(det1.y - new_history[-1].y) >= bin_size: - if det1.y - new_history[-1].y >= bin_size: - # det1 left of last - y = new_history[-1].y + bin_size - f = inv_lerp(det0.y, det1.y, x) - elif new_history[-1].y - det1.y >= bin_size: - # det1 left of last - y = new_history[-1].y - bin_size - f = inv_lerp(det0.y, det1.y, x) - x = lerp(det0.x, det1.x, f) + # # 1. Interpolate exact point between det0 and det1 that this happens + # if abs(det1.x - new_history[-1].x) >= bin_size: + # if det1.x - new_history[-1].x >= bin_size: + # # det1 left of last + # x = new_history[-1].x + bin_size + # f = inv_lerp(det0.x, det1.x, x) + # elif new_history[-1].x - det1.x >= bin_size: + # # det1 left of last + # x = new_history[-1].x - bin_size + # f = inv_lerp(det0.x, det1.x, x) + # y = lerp(det0.y, det1.y, f) + # if abs(det1.y - new_history[-1].y) >= bin_size: + # if det1.y - new_history[-1].y >= bin_size: + # # det1 left of last + # y = new_history[-1].y + bin_size + # f = inv_lerp(det0.y, det1.y, x) + # elif new_history[-1].y - det1.y >= bin_size: + # # det1 left of last + # y = new_history[-1].y - bin_size + # f = inv_lerp(det0.y, det1.y, x) + # x = lerp(det0.x, det1.x, f) - # 2. Find closest point on rectangle (rectangle's four corners, or 4 midpoints) - points = [[bin_size, 0], [bin_size, bin_size], [0, bin_size], [-bin_size, bin_size], [-bin_size, 0], [-bin_size, -bin_size], [0, -bin_size], [bin_size, -bin_size]] - # todo Offsets to points:[ history for in points] + # # 2. Find closest point on rectangle (rectangle's four corners, or 4 midpoints) + # points = [[bin_size, 0], [bin_size, bin_size], [0, bin_size], [-bin_size, bin_size], [-bin_size, 0], [-bin_size, -bin_size], [0, -bin_size], [bin_size, -bin_size]] + # # todo Offsets to points:[ history for in points] def to_trajectron_node(self, camera: Camera, env: Environment) -> Node: diff --git a/trap/tools.py b/trap/tools.py index 8c6b634..5039b4d 100644 --- a/trap/tools.py +++ b/trap/tools.py @@ -11,7 +11,7 @@ import pandas as pd import trap.tracker from trap.config import parser from trap.frame_emitter import Camera, Detection, DetectionState, video_src_from_config, Frame -from trap.tracker import DETECTOR_YOLOv8, Smoother, TrackReader, _yolov8_track, Track, TrainingDataWriter, Tracker, read_tracks_json +from trap.tracker import DETECTOR_YOLOv8, FinalDisplacementFilter, Smoother, TrackReader, _yolov8_track, Track, TrainingDataWriter, Tracker, read_tracks_json from collections import defaultdict import logging @@ -297,6 +297,9 @@ def blacklist_tracks(): path: Path = config.save_for_training reader = TrackReader(path, config.camera.fps, exclude_whitelisted = True) + tracks = [t for t in reader] + filter = FinalDisplacementFilter(2.0) + tracks = filter.apply(tracks, config.camera) # blacklist_file = path / "blacklist.jsonl" # whitelist_file = path / "whitelist.jsonl" # for skipping # tracks_file = path / "tracks.json" @@ -311,7 +314,7 @@ def blacklist_tracks(): # whitelist = [] smoother = Smoother() try: - for track in reader: + for track in tqdm.tqdm(tracks): if len(track.history) < 5: continue