Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trackers/core/bytetrack/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_next_tracker_id(cls) -> int:
cls.count_id += 1
return next_id

def __init__(self, bbox: np.ndarray):
def __init__(self, bbox: np.ndarray) -> None:
# Initialize with a temporary ID of -1
# Will be assigned a real ID when the track is considered mature
self.tracker_id = -1
Expand Down
3 changes: 2 additions & 1 deletion trackers/eval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from trackers.eval.box import box_ioa, box_iou
from trackers.eval.clear import aggregate_clear_metrics, compute_clear_metrics
from trackers.eval.evaluate import evaluate_mot_sequence, evaluate_mot_sequences
from trackers.eval.hota import aggregate_hota_metrics, compute_hota_metrics
from trackers.eval.identity import aggregate_identity_metrics, compute_identity_metrics
from trackers.eval.results import (
Expand All @@ -19,7 +20,7 @@
)


def __getattr__(name: str):
def __getattr__(name: str) -> object:
"""Lazy imports for evaluate functions to avoid circular imports."""
if name in ("evaluate_mot_sequence", "evaluate_mot_sequences"):
from trackers.eval import evaluate as _evaluate
Expand Down
6 changes: 3 additions & 3 deletions trackers/io/mot.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _prepare_mot_sequence(
class _MOTOutput:
"""Context manager for MOT format file writing."""

def __init__(self, path: Path | None):
def __init__(self, path: Path | None) -> None:
self.path = path
self._file = None

Expand Down Expand Up @@ -333,12 +333,12 @@ def write(self, frame_idx: int, detections: sv.Detections) -> None:
f"{conf:.4f},-1,-1,-1\n"
)

def __enter__(self):
def __enter__(self) -> _MOTOutput:
if self.path is not None:
self.path.parent.mkdir(parents=True, exist_ok=True)
self._file = open(self.path, "w")
return self

def __exit__(self, *_):
def __exit__(self, *_) -> None:
if self._file is not None:
self._file.close()
8 changes: 4 additions & 4 deletions trackers/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _iter_image_folder_frames(
class _VideoOutput:
"""Context manager for lazy video file writing."""

def __init__(self, path: Path | None, *, fps: float = _DEFAULT_OUTPUT_FPS):
def __init__(self, path: Path | None, *, fps: float = _DEFAULT_OUTPUT_FPS) -> None:
self.path = path
self.fps = fps
self._writer: cv2.VideoWriter | None = None
Expand Down Expand Up @@ -137,7 +137,7 @@ def __exit__(self, *_: object) -> None:
class _DisplayWindow:
"""Context manager for OpenCV display window with resizable output."""

def __init__(self, window_name: str = "Tracking"):
def __init__(self, window_name: str = "Tracking") -> None:
self.window_name = window_name
self._quit_requested = False
cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO)
Expand All @@ -159,8 +159,8 @@ def quit_requested(self) -> bool:
"""Return True if user pressed quit key."""
return self._quit_requested

def __enter__(self):
def __enter__(self) -> _DisplayWindow:
return self

def __exit__(self, *_):
def __exit__(self, *_) -> None:
cv2.destroyWindow(self.window_name)
10 changes: 7 additions & 3 deletions trackers/scripts/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
from contextlib import nullcontext
from pathlib import Path
from typing import TYPE_CHECKING

import numpy as np
import supervision as sv
Expand All @@ -23,6 +24,9 @@
from trackers.scripts.progress import _classify_source, _TrackingProgress
from trackers.utils.device import _best_device

if TYPE_CHECKING:
from inference_models import AnyModel

# Defaults
DEFAULT_MODEL = "rfdetr-nano"
DEFAULT_TRACKER = "bytetrack"
Expand Down Expand Up @@ -462,7 +466,7 @@ def _init_model(
*,
device: str = DEFAULT_DEVICE,
api_key: str | None = None,
):
) -> AnyModel:
"""Load detection model via inference-models.

Args:
Expand Down Expand Up @@ -492,7 +496,7 @@ def _init_model(
)


def _run_model(model, frame: np.ndarray, confidence: float) -> sv.Detections:
def _run_model(model: AnyModel, frame: np.ndarray, confidence: float) -> sv.Detections:
"""Run model inference and return sv.Detections."""
predictions = model(frame)
if not predictions:
Expand Down Expand Up @@ -534,7 +538,7 @@ def _extract_tracker_params(
return params


def _init_tracker(tracker_id: str, **kwargs) -> BaseTracker:
def _init_tracker(tracker_id: str, **kwargs: object) -> BaseTracker:
"""Create tracker instance from registry.

Args:
Expand Down