Compare commits

..

2 commits

Author SHA1 Message Date
Ruben van de Ven
a7c6aaacd3 Notebook updates 2024-12-10 15:43:30 +01:00
Ruben van de Ven
d6d3092e43 Blacklist tools 2024-12-10 15:43:06 +01:00
4 changed files with 105 additions and 73 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -290,49 +290,49 @@ class Track:
t.predictions, t.predictions,
t.fps/step_size) t.fps/step_size)
def get_binned(self, bin_size=.5, remove_overlap=True): # def get_binned(self, bin_size=.5, remove_overlap=True):
""" # """
For an experiment: what if we predict using only concrete positions, by mapping # 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 # dx,dy to a grid. Thus prediction can be for 8 moves, or rather headings
see ~/notes/attachments example svg # see ~/notes/attachments example svg
""" # """
new_history: List[Detection] = [] # new_history: List[Detection] = []
for i, (det0, det1) in enumerate(zip(self.history[:-1], self.history[1:]): # for i, (det0, det1) in enumerate(zip(self.history[:-1], self.history[1:]):
if i == 0: # if i == 0:
new_history.append(det0) # new_history.append(det0)
continue # continue
if abs(det1.x - new_history[-1].x) < bin_size or abs(det1.y - new_history[-1].y) < bin_size: # if abs(det1.x - new_history[-1].x) < bin_size or abs(det1.y - new_history[-1].y) < bin_size:
continue # 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 # # 1. Interpolate exact point between det0 and det1 that this happens
if abs(det1.x - new_history[-1].x) >= bin_size: # if abs(det1.x - new_history[-1].x) >= bin_size:
if det1.x - new_history[-1].x >= bin_size: # if det1.x - new_history[-1].x >= bin_size:
# det1 left of last # # det1 left of last
x = new_history[-1].x + bin_size # x = new_history[-1].x + bin_size
f = inv_lerp(det0.x, det1.x, x) # f = inv_lerp(det0.x, det1.x, x)
elif new_history[-1].x - det1.x >= bin_size: # elif new_history[-1].x - det1.x >= bin_size:
# det1 left of last # # det1 left of last
x = new_history[-1].x - bin_size # x = new_history[-1].x - bin_size
f = inv_lerp(det0.x, det1.x, x) # f = inv_lerp(det0.x, det1.x, x)
y = lerp(det0.y, det1.y, f) # y = lerp(det0.y, det1.y, f)
if abs(det1.y - new_history[-1].y) >= bin_size: # if abs(det1.y - new_history[-1].y) >= bin_size:
if det1.y - new_history[-1].y >= bin_size: # if det1.y - new_history[-1].y >= bin_size:
# det1 left of last # # det1 left of last
y = new_history[-1].y + bin_size # y = new_history[-1].y + bin_size
f = inv_lerp(det0.y, det1.y, x) # f = inv_lerp(det0.y, det1.y, x)
elif new_history[-1].y - det1.y >= bin_size: # elif new_history[-1].y - det1.y >= bin_size:
# det1 left of last # # det1 left of last
y = new_history[-1].y - bin_size # y = new_history[-1].y - bin_size
f = inv_lerp(det0.y, det1.y, x) # f = inv_lerp(det0.y, det1.y, x)
x = lerp(det0.x, det1.x, f) # x = lerp(det0.x, det1.x, f)
# 2. Find closest point on rectangle (rectangle's four corners, or 4 midpoints) # # 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]] # 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] # # todo Offsets to points:[ history for in points]
def to_trajectron_node(self, camera: Camera, env: Environment) -> Node: def to_trajectron_node(self, camera: Camera, env: Environment) -> Node:

View file

@ -11,7 +11,7 @@ import pandas as pd
import trap.tracker import trap.tracker
from trap.config import parser from trap.config import parser
from trap.frame_emitter import Camera, Detection, DetectionState, video_src_from_config, Frame 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 from collections import defaultdict
import logging import logging
@ -297,6 +297,9 @@ def blacklist_tracks():
path: Path = config.save_for_training path: Path = config.save_for_training
reader = TrackReader(path, config.camera.fps, exclude_whitelisted = True) 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" # blacklist_file = path / "blacklist.jsonl"
# whitelist_file = path / "whitelist.jsonl" # for skipping # whitelist_file = path / "whitelist.jsonl" # for skipping
# tracks_file = path / "tracks.json" # tracks_file = path / "tracks.json"
@ -311,7 +314,7 @@ def blacklist_tracks():
# whitelist = [] # whitelist = []
smoother = Smoother() smoother = Smoother()
try: try:
for track in reader: for track in tqdm.tqdm(tracks):
if len(track.history) < 5: if len(track.history) < 5:
continue continue