Skip to content

Commit c432235

Browse files
authored
Merge branch 'roboflow:main' into feat/mot_datasets
2 parents 3034cb5 + b0e00ce commit c432235

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
additional_dependencies: ["bandit[toml]"]
3131

3232
- repo: https://github.com/astral-sh/ruff-pre-commit
33-
rev: v0.11.6
33+
rev: v0.11.7
3434
hooks:
3535
- id: ruff
3636
args: [--fix, --exit-non-zero-on-fix]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<img width="200" src="https://raw.githubusercontent.com/roboflow/trackers/refs/heads/main/docs/assets/logo-trackers-violet.svg" alt="trackers logo">
44

55
[![version](https://badge.fury.io/py/trackers.svg)](https://badge.fury.io/py/trackers)
6+
[![downloads](https://img.shields.io/pypi/dm/trackers)](https://pypistats.org/packages/trackers)
67
[![license](https://img.shields.io/badge/license-Apache%202.0-blue)](https://github.com/roboflow/trackers/blob/main/LICENSE.md)
78
[![python-version](https://img.shields.io/pypi/pyversions/trackers)](https://badge.fury.io/py/trackers)
89

trackers/core/sort/tracker.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import supervision as sv
3+
from scipy.optimize import linear_sum_assignment
34

45
from trackers.core.base import BaseTracker
56
from trackers.core.sort.kalman_box_tracker import SORTKalmanBoxTracker
@@ -76,25 +77,17 @@ def _get_associated_indices(
7677
unmatched_trackers = set(range(len(self.trackers)))
7778
unmatched_detections = set(range(len(detection_boxes)))
7879

79-
if iou_matrix.size > 0:
80-
row_indices, col_indices = np.where(iou_matrix > self.minimum_iou_threshold)
81-
# Sort in descending order of IOU. Higher = better match.
82-
sorted_pairs = sorted(
83-
zip(row_indices, col_indices),
84-
key=lambda x: iou_matrix[x[0], x[1]],
85-
reverse=True,
86-
)
87-
# keep each unique row/col pair at most once
88-
used_rows = set()
89-
used_cols = set()
90-
for row, col in sorted_pairs:
91-
if (row not in used_rows) and (col not in used_cols):
92-
used_rows.add(row)
93-
used_cols.add(col)
80+
if len(self.trackers) > 0 and len(detection_boxes) > 0:
81+
# Find optimal assignment using scipy.optimize.linear_sum_assignment.
82+
# Note that it uses a a modified Jonker-Volgenant algorithm with no
83+
# initialization instead of the Hungarian algorithm as mentioned in the
84+
# SORT paper.
85+
row_indices, col_indices = linear_sum_assignment(iou_matrix, maximize=True)
86+
for row, col in zip(row_indices, col_indices):
87+
if iou_matrix[row, col] >= self.minimum_iou_threshold:
9488
matched_indices.append((row, col))
95-
96-
unmatched_trackers = unmatched_trackers - used_rows
97-
unmatched_detections = unmatched_detections - used_cols
89+
unmatched_trackers.remove(row)
90+
unmatched_detections.remove(col)
9891

9992
return matched_indices, unmatched_trackers, unmatched_detections
10093

0 commit comments

Comments
 (0)