2 from __future__
import absolute_import
4 from .
import kalman_filter
5 from .
import linear_assignment
6 from .
import iou_matching
7 from .track
import Track
12 This is the multi-target tracker. 16 metric : nn_matching.NearestNeighborDistanceMetric 17 A distance metric for measurement-to-track association. 19 Maximum number of missed misses before a track is deleted. 21 Number of consecutive detections before the track is confirmed. The 22 track state is set to `Deleted` if a miss occurs within the first 27 metric : nn_matching.NearestNeighborDistanceMetric 28 The distance metric used for measurement to track association. 30 Maximum number of missed misses before a track is deleted. 32 Number of frames that a track remains in initialization phase. 33 kf : kalman_filter.KalmanFilter 34 A Kalman filter to filter target trajectories in image space. 36 The list of active tracks at the current time step. 40 def __init__(self, metric, max_iou_distance=0.7, max_age=30, n_init=3):
51 """Propagate track state distributions one time step forward. 53 This function should be called once every time step, before `update`. 56 track.predict(self.
kf)
59 """Perform measurement update and track management. 63 detections : List[deep_sort.detection.Detection] 64 A list of detections at the current time step. 68 matches, unmatched_tracks, unmatched_detections = \
72 for track_idx, detection_idx
in matches:
74 self.
kf, detections[detection_idx])
75 for track_idx
in unmatched_tracks:
76 self.
tracks[track_idx].mark_missed()
77 for detection_idx
in unmatched_detections:
79 self.
tracks = [t
for t
in self.
tracks if not t.is_deleted()]
82 active_targets = [t.track_id
for t
in self.
tracks if t.is_confirmed()]
83 features, targets = [], []
85 if not track.is_confirmed():
87 features += track.features
88 targets += [track.track_id
for _
in track.features]
90 self.metric.partial_fit(
91 np.asarray(features), np.asarray(targets), active_targets)
95 def gated_metric(tracks, dets, track_indices, detection_indices):
96 features = np.array([dets[i].feature
for i
in detection_indices])
97 targets = np.array([tracks[i].track_id
for i
in track_indices])
98 cost_matrix = self.metric.distance(features, targets)
99 cost_matrix = linear_assignment.gate_cost_matrix(
100 self.
kf, cost_matrix, tracks, dets, track_indices,
107 i
for i, t
in enumerate(self.
tracks)
if t.is_confirmed()]
108 unconfirmed_tracks = [
109 i
for i, t
in enumerate(self.
tracks)
if not t.is_confirmed()]
112 matches_a, unmatched_tracks_a, unmatched_detections = \
113 linear_assignment.matching_cascade(
114 gated_metric, self.metric.matching_threshold, self.
max_age,
115 self.
tracks, detections, confirmed_tracks)
118 iou_track_candidates = unconfirmed_tracks + [
119 k
for k
in unmatched_tracks_a
if 120 self.
tracks[k].time_since_update == 1]
121 unmatched_tracks_a = [
122 k
for k
in unmatched_tracks_a
if 123 self.
tracks[k].time_since_update != 1]
124 matches_b, unmatched_tracks_b, unmatched_detections = \
125 linear_assignment.min_cost_matching(
127 detections, iou_track_candidates, unmatched_detections)
129 matches = matches_a + matches_b
130 unmatched_tracks = list(set(unmatched_tracks_a + unmatched_tracks_b))
131 return matches, unmatched_tracks, unmatched_detections
134 mean, covariance = self.kf.initiate(detection.to_xyah())
135 self.tracks.append(Track(
def __init__(self, metric, max_iou_distance=0.7, max_age=30, n_init=3)
def update(self, detections)
def _match(self, detections)
def _initiate_track(self, detection)