sportslabkit.matching#
Overview#
A base class for matching functions. |
|
A base class for batch matching functions. |
|
A matching function that uses a combination of motion and visual |
|
A batch matching function that uses a simple distance metric. |
|
A matching function that uses a single metric. |
Classes#
- class sportslabkit.matching.BaseMatchingFunction[source]#
Bases:
abc.ABCA base class for matching functions.
A matching function takes a list of trackers and a list of detections and returns a list of matches. Subclasses should implement the
compute_cost_matrix()method.Overview
Methods# compute_cost_matrix(trackers, detections)abc Calculate the matching cost between trackers and detections.
match_cost_matrix(cost_matrix)Match trackers and detections based on a cost matrix.
Members
- abstract compute_cost_matrix(trackers: collections.abc.Sequence[sportslabkit.Tracklet], detections: collections.abc.Sequence[sportslabkit.types.detection.Detection]) numpy.ndarray#
Calculate the matching cost between trackers and detections.
- Parameters:
trackers – A list of trackers.
detections – A list of detections.
- Returns:
A 2D numpy array of matching costs between trackers and detections.
- match_cost_matrix(cost_matrix: numpy.ndarray) numpy.ndarray#
Match trackers and detections based on a cost matrix.
While this method implements a hungarian algorithm, it is can be overriden by subclasses that implement different matching strategies. :param cost_matrix: A 2D numpy array of matching costs between trackers and detections.
- Returns:
A 2D numpy array of shape (n, 2) containing indices of matching pairs of trackers and detections.
- class sportslabkit.matching.BaseBatchMatchingFunction[source]#
A base class for batch matching functions.
A batch matching function takes a list of trackers and a list of detections and returns a list of matches.
Overview
Methods# compute_cost_matrices(trackers, list_of_detections)abc Calculate the cost matrix between trackers and detections.
Members
- abstract compute_cost_matrices(trackers: list[sportslabkit.Tracklet], list_of_detections: list[list[sportslabkit.types.detection.Detection]]) list[numpy.ndarray]#
Calculate the cost matrix between trackers and detections.
- Parameters:
trackers – A list of trackers.
list_of_detections – A list containing a list of detections for each frame.
- Returns:
A list of 2D numpy arrays where the element at [i, j] in the kth array is the cost between tracker i and detection j in frame k.
- class sportslabkit.matching.MotionVisualMatchingFunction(motion_metric: sportslabkit.metrics.BaseCostMatrixMetric = IoUCMM(), beta: float = 0.5, motion_metric_gate: float = np.inf, visual_metric: sportslabkit.metrics.BaseCostMatrixMetric = CosineCMM(), visual_metric_gate: float = np.inf)[source]#
Bases:
sportslabkit.matching.base.BaseMatchingFunctionA matching function that uses a combination of motion and visual metrics.
- Parameters:
motion_metric – A motion metric. Defaults to IoUCMM.
beta – The weight of the motion metric. The weight of the visual metric is calculated as 1 - beta. Defaults to 0.5.
motion_metric_gate – The gate of the motion metric, i.e. if the motion metric is larger than this value, the cost will be set to infinity. Defaults to np.inf.
visual_metric – A visual metric. Defaults to CosineCMM.
visual_metric_gate – The gate of the visual metric, i.e. if the visual metric is larger than this value, the cost will be set to infinity. Defaults to np.inf.
Note
To implement your own matching function, you can inherit from BaseMatchingFunction and override the
compute_cost_matrix()method.Overview
Attributes# -
Methods# compute_cost_matrix(trackers, detections)Calculate the matching cost between trackers and detections.
Members
- hparam_search_space#
- compute_cost_matrix(trackers: collections.abc.Sequence[sportslabkit.Tracklet], detections: collections.abc.Sequence[sportslabkit.types.detection.Detection]) numpy.ndarray#
Calculate the matching cost between trackers and detections.
- Parameters:
trackers – A list of trackers.
detections – A list of detections.
- Returns:
A 2D numpy array of matching costs between trackers and detections.
- class sportslabkit.matching.SimpleBatchMatchingFunction[source]#
Bases:
sportslabkit.matching.base_batch.BaseBatchMatchingFunctionA batch matching function that uses a simple distance metric.
This class is a simple implementation of batch matching function where the cost is based on the Euclidean distance between the trackers and detections.
Overview
Methods# compute_cost_matrices(trackers, list_of_detections)Calculate the cost matrix between trackers and detections.
Members
- compute_cost_matrices(trackers: list[sportslabkit.Tracklet], list_of_detections: list[list[sportslabkit.types.detection.Detection]]) list[numpy.ndarray]#
Calculate the cost matrix between trackers and detections.
- Parameters:
trackers – A list of trackers.
list_of_detections – A list containing a list of detections for each frame.
- Returns:
A list of 2D numpy arrays where the element at [i, j] in the kth array is the cost between tracker i and detection j in frame 0, detection j-1 and detection j otherwise.
- class sportslabkit.matching.SimpleMatchingFunction(metric: sportslabkit.metrics.BaseCostMatrixMetric = IoUCMM(), gate: float = np.inf)[source]#
Bases:
sportslabkit.matching.base.BaseMatchingFunctionA matching function that uses a single metric.
- Parameters:
metric – A metric. Defaults to IoUCMM.
gate – The gate of the metric, i.e. if the metric is larger than this value, the cost will be set to infinity. Defaults to np.inf.
Note
To implement your own matching function, you can inherit from BaseMatchingFunction and override the
compute_cost_matrix()method.Overview
Methods# compute_cost_matrix(trackers, detections)Calculate the matching cost between trackers and detections.
Members
- compute_cost_matrix(trackers: collections.abc.Sequence[sportslabkit.Tracklet], detections: collections.abc.Sequence[sportslabkit.types.detection.Detection]) numpy.ndarray#
Calculate the matching cost between trackers and detections.
- Parameters:
trackers – A list of trackers.
detections – A list of detections.
- Returns:
A 2D numpy array of matching costs between trackers and detections.