Skip to content

Commit

Permalink
Revert "Various tracker integration"
Browse files Browse the repository at this point in the history
This reverts commit 6acda53.
  • Loading branch information
bstandaert committed Jul 5, 2024
1 parent 6acda53 commit 3c24885
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 228 deletions.
2 changes: 1 addition & 1 deletion plugins/track/deep_oc_sort/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def linear_assignment(cost_matrix):
import lap

_, x, y = lap.lapjv(cost_matrix, extend_cost=True)
return np.array([[y[i], i] for i in x]) #
return np.array([[y[i], i] for i in x if i >= 0]) #
except ImportError:
from scipy.optimize import linear_sum_assignment

Expand Down
5 changes: 3 additions & 2 deletions tracklab/configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# to create the final config file. This item *must* be
# the first element in the file.
defaults:
- dataset: dancetrack
- dataset: soccernet_gs
- eval: trackeval
- engine: offline
- state: no_save
- visualization: save_videos
- modules/bbox_detector: yolov8
- modules/pose_topdown: hrnet_posetrack18
- modules/pose_bottomup: openpifpaf
- modules/reid: bpbreid
- modules/track: oc_sort
- _self_
Expand All @@ -21,6 +21,7 @@ defaults:
# Use 'pipeline: []' for an empty pipeline
pipeline:
- bbox_detector
- reid
- track

# Experiment name
Expand Down
2 changes: 1 addition & 1 deletion tracklab/configs/engine/video.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_target_: tracklab.engine.VideoOnlineTrackingEngine

filename: "/path/to/video.mp4"
filename: "/home/vjoosdeterb/Downloads/ilids/AVSS_AB_EVAL_divx.avi"
target_fps: 1
num_workers: ${num_cores}
callbacks:
Expand Down
3 changes: 1 addition & 2 deletions tracklab/configs/modules/bbox_detector/yolox.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
_target_: tracklab.wrappers.bbox_detector.mmdetection_api.MMDetection
config_name: yolox_x_8x8_300e_coco
path_to_checkpoint: ${model_dir}/mmdet/${.config_name}.pth
min_confidence: 0.4
batch_size: 2
min_confidence: 0.4
2 changes: 1 addition & 1 deletion tracklab/configs/modules/reid/bpbreid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _target_: tracklab.wrappers.BPBReId
defaults:
- dataset: default

batch_size: 32
batch_size: 64
job_id: "${oc.env:SLURM_JOBID,0}" # TODO
save_path: reid
use_keypoints_visibility_scores_for_reid: False
Expand Down
21 changes: 0 additions & 21 deletions tracklab/configs/modules/track/bot_sort.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions tracklab/configs/modules/track/byte_track.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions tracklab/configs/modules/track/deep_oc_sort.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions tracklab/configs/modules/track/strong_sort.yaml

This file was deleted.

1 change: 1 addition & 0 deletions tracklab/engine/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import torch
from lightning import Fabric

from tracklab.engine import TrackingEngine
from tracklab.engine.engine import merge_dataframes
from tracklab.pipeline import Pipeline

Expand Down
8 changes: 0 additions & 8 deletions tracklab/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ def in_bbox_coord(self, bbox_ltwh):
lambda x: keypoints_in_bbox_coord(x, bbox_ltwh)
)

def keypoints_bbox_xyc(self):
"""Converts from keypoints in image coordinates to keypoints in bbox coordinates"""
return self._obj.apply(
lambda r: keypoints_in_bbox_coord(r.keypoints_xyc, r.bbox_ltwh), axis=1)

@pd.api.extensions.register_series_accessor("keypoints")
class KeypointsSeriesAccessor:
Expand Down Expand Up @@ -124,7 +120,3 @@ def conf(self):

def in_bbox_coord(self, bbox_ltwh):
return keypoints_in_bbox_coord(self._obj.keypoints_xyc, bbox_ltwh)

def keypoints_bbox_xyc(self):
"""Converts from keypoints in image coordinates to keypoints in bbox coordinates"""
return keypoints_in_bbox_coord(self._obj.keypoints_xyc, self._obj.bbox_ltwh)
45 changes: 1 addition & 44 deletions tracklab/utils/cv2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import colorsys

import cv2
from functools import lru_cache

import matplotlib.cm as cm

from .coordinates import *


Expand Down Expand Up @@ -67,7 +62,7 @@ def cv2_load_image(file_path):
video_reader.set_filename(video_file)
image = video_reader[int(frame_id)]
else:
image = cv2.imread(file_path)
image = cv2.imread(str(file_path))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
return image

Expand Down Expand Up @@ -370,41 +365,3 @@ def draw_text(
lineType=lineType,
)
return text_size


def scale_lightness(rgb, scale_l=1.4):
# convert rgb to hls
h, l, s = colorsys.rgb_to_hls(*rgb)
# manipulate h, l, s values and return as rgb
return colorsys.hls_to_rgb(h, min(1, l * scale_l), s = s)

def colored_body_parts_overlay(img, masks, clip=True, interpolation=cv2.INTER_CUBIC, alpha=0.28, mask_threshold=0.0, weight_scale=1, rgb=False):
width, height = img.shape[1], img.shape[0]
white_bckg = np.ones_like(img) * 255
for i in range(masks.shape[0]):
mask = cv2.resize(masks[i], dsize=(width, height), interpolation=interpolation)
if clip:
mask = np.clip(mask, 0, 1)
else:
mask = np.interp(mask, (mask.min(), mask.max()), (0, 255)).astype(np.uint8)
weight = mask
mask_alpha = np.ones_like(weight)
mask_alpha[mask < mask_threshold] = 0
mask_alpha = np.expand_dims(mask_alpha, 2)
weight = np.expand_dims(weight, 2) / weight_scale
color_img = np.zeros_like(img)
color = scale_lightness(cm.gist_rainbow(i / (len(masks)-1))[0:-1])
color_img[:] = np.flip(np.array(color)*255).astype(np.uint8)
white_bckg = white_bckg * (1 - mask_alpha * weight) + color_img * mask_alpha * weight
heatmap = masks.sum(axis=0).clip(0, 1)
heatmap = cv2.resize(heatmap, dsize=(width, height), interpolation=interpolation)
mask_alpha = heatmap
mask_alpha[heatmap < mask_threshold] = 0
mask_alpha = np.repeat(np.expand_dims(mask_alpha, 2), 3, 2)
white_bckg = white_bckg.astype(img.dtype)
if rgb:
white_bckg = cv2.cvtColor(white_bckg, cv2.COLOR_BGR2RGB)
masked_img = (
img * (1 - mask_alpha * alpha) + white_bckg * mask_alpha * alpha
)
return masked_img
2 changes: 1 addition & 1 deletion tracklab/wrappers/datasets/external_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, dataset_path: str, video_path: str, *args, **kwargs):
video_metadata,
image_metadata,
None,
image_metadata,
image_metadata
)

super().__init__(dataset_path, dict(val=val_set), *args, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions tracklab/wrappers/reid/bpbreid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tracklab.utils.coordinates import rescale_keypoints

from tracklab.utils.cv2 import overlay_heatmap
import tracklab

from torchreid.data import ImageDataset
from torchreid.utils.imagetools import (
Expand Down
2 changes: 1 addition & 1 deletion tracklab/wrappers/track/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .byte_track_api import ByteTrack
from .oc_sort_api import OCSORT
from .deep_oc_sort_api import DeepOCSORT
from .bpbreid_strong_sort_api import BPBReIDStrongSORT
from .bpbreid_strong_sort_api import BPBReIDStrongSORT
35 changes: 12 additions & 23 deletions tracklab/wrappers/track/bot_sort_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import logging

from tracklab.utils.cv2 import cv2_load_image

log = logging.getLogger(__name__)


Expand All @@ -22,10 +20,9 @@ class BotSORT(ImageLevelModule):
]
output_columns = ["track_id", "track_bbox_ltwh", "track_bbox_conf"]

def __init__(self, cfg, device, **kwargs):
super().__init__(batch_size=1)
def __init__(self, cfg, device, batch_size):
super().__init__(cfg, device, batch_size)
self.cfg = cfg
self.device = device
self.reset()

def reset(self):
Expand All @@ -38,29 +35,21 @@ def reset(self):
)

@torch.no_grad()
def preprocess(self, image, detections: pd.DataFrame, metadata: pd.Series):
processed_detections = []
if len(detections) == 0:
return {"input": []}
for det_id, detection in detections.iterrows():
ltrb = detection.bbox.ltrb()
conf = detection.bbox.conf()
cls = detection.category_id
tracklab_id = int(detection.name)
processed_detections.append(
np.array([*ltrb, conf, cls, tracklab_id])
)
def preprocess(self, detection: pd.Series, metadata: pd.Series):
ltrb = detection.bbox.ltrb()
conf = detection.bbox.conf()
cls = detection.category_id
tracklab_id = detection.name
return {
"input": np.stack(processed_detections)
"input": np.array(
[ltrb[0], ltrb[1], ltrb[2], ltrb[3], conf, cls, tracklab_id]
),
}

@torch.no_grad()
def process(self, batch, detections: pd.DataFrame, metadatas: pd.DataFrame):
if len(detections) == 0:
return []
inputs = batch["input"][0] # Nx7 [l,t,r,b,conf,class,tracklab_id]
def process(self, batch, image, detections: pd.DataFrame):
inputs = batch["input"] # Nx7 [l,t,r,b,conf,class,tracklab_id]
inputs = inputs[inputs[:, 4] > self.cfg.min_confidence]
image = cv2_load_image(metadatas['file_path'].values[0])
results = self.model.update(inputs, image)
results = np.asarray(results) # N'x8 [l,t,r,b,track_id,class,conf,idx]
if results.size:
Expand Down
32 changes: 12 additions & 20 deletions tracklab/wrappers/track/byte_track_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,30 @@ class ByteTrack(ImageLevelModule):
]
output_columns = ["track_id", "track_bbox_ltwh", "track_bbox_conf"]

def __init__(self, cfg, device, **kwargs):
super().__init__(batch_size=1)
def __init__(self, cfg, device, batch_size):
super().__init__(cfg, device, batch_size)
self.cfg = cfg
self.device = device
self.reset()

def reset(self):
"""Reset the tracker state to start tracking in a new video."""
self.model = byte_tracker.BYTETracker(**self.cfg.hyperparams)

@torch.no_grad()
def preprocess(self, image, detections: pd.DataFrame, metadata: pd.Series):
processed_detections = []
if len(detections) == 0:
return {"input": []}
for det_id, detection in detections.iterrows():
ltrb = detection.bbox.ltrb()
conf = detection.bbox.conf()
cls = detection.category_id
tracklab_id = int(detection.name)
processed_detections.append(
np.array([*ltrb, conf, cls, tracklab_id])
)
def preprocess(self, detection: pd.Series, metadata: pd.Series):
ltrb = detection.bbox.ltrb()
conf = detection.bbox.conf()
cls = detection.category_id
tracklab_id = detection.name
return {
"input": np.stack(processed_detections)
"input": np.array(
[ltrb[0], ltrb[1], ltrb[2], ltrb[3], conf, cls, tracklab_id]
),
}

@torch.no_grad()
def process(self, batch, detections: pd.DataFrame, metadatas: pd.DataFrame):
if len(detections) == 0:
return []
inputs = batch["input"][0] # Nx7 [l,t,r,b,conf,class,tracklab_id]
def process(self, batch, image, detections: pd.DataFrame):
inputs = batch["input"] # Nx7 [l,t,r,b,conf,class,tracklab_id]
inputs = inputs[inputs[:, 4] > self.cfg.min_confidence]
results = self.model.update(inputs, None)
results = np.asarray(results) # N'x8 [l,t,r,b,track_id,class,conf,idx]
Expand Down
Loading

0 comments on commit 3c24885

Please sign in to comment.