Reference for ultralytics/trackers/utils/matching.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/trackers/utils/matching.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!
ultralytics.trackers.utils.matching.linear_assignment(cost_matrix, thresh, use_lap=True)
Perform linear assignment using scipy or lap.lapjv.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cost_matrix |
ndarray
|
The matrix containing cost values for assignments. |
required |
thresh |
float
|
Threshold for considering an assignment valid. |
required |
use_lap |
bool
|
Whether to use lap.lapjv. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
tuple
|
Tuple containing matched indices, unmatched indices from 'a', and unmatched indices from 'b'. |
Source code in ultralytics/trackers/utils/matching.py
ultralytics.trackers.utils.matching.iou_distance(atracks, btracks)
Compute cost based on Intersection over Union (IoU) between tracks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
atracks |
list[STrack] | list[ndarray]
|
List of tracks 'a' or bounding boxes. |
required |
btracks |
list[STrack] | list[ndarray]
|
List of tracks 'b' or bounding boxes. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Cost matrix computed based on IoU. |
Source code in ultralytics/trackers/utils/matching.py
ultralytics.trackers.utils.matching.embedding_distance(tracks, detections, metric='cosine')
Compute distance between tracks and detections based on embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tracks |
list[STrack]
|
List of tracks. |
required |
detections |
list[BaseTrack]
|
List of detections. |
required |
metric |
str
|
Metric for distance computation. Defaults to 'cosine'. |
'cosine'
|
Returns:
Type | Description |
---|---|
ndarray
|
Cost matrix computed based on embeddings. |
Source code in ultralytics/trackers/utils/matching.py
ultralytics.trackers.utils.matching.fuse_score(cost_matrix, detections)
Fuses cost matrix with detection scores to produce a single similarity matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cost_matrix |
ndarray
|
The matrix containing cost values for assignments. |
required |
detections |
list[BaseTrack]
|
List of detections with scores. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Fused similarity matrix. |