xuepengqiang
2020-05-26 bb5cb224c9abe4216aaa49a8287b06d9f05dab60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
3
yé»]cã@sVddlmZddlZddlmZddlmZdZddd„Z    dd    d
„Z
ed fd d „Z dS)é)Úabsolute_importN)Úlinear_assignmenté)Ú kalman_filtergjø@cCsN|dkrtjt|ƒƒ}|dkr,tjt|ƒƒ}t|ƒdksDt|ƒdkrNg||fS|||||ƒ}|d|||k<t|ƒ}ggg}}    }
x2t|ƒD]&\} } | |dd…dfkrŽ|
j| ƒqŽWx2t|ƒD]&\} }| |dd…dfkrÂ|    j|ƒqÂWxV|D]N\} } || }|| } || | f|kr2|    j|ƒ|
j| ƒqò|j|| fƒqòW||    |
fS)ažSolve linear assignment problem.
 
    Parameters
    ----------
    distance_metric : Callable[List[Track], List[Detection], List[int], List[int]) -> ndarray
        The distance metric is given a list of tracks and detections as well as
        a list of N track indices and M detection indices. The metric should
        return the NxM dimensional cost matrix, where element (i, j) is the
        association cost between the i-th track in the given track indices and
        the j-th detection in the given detection_indices.
    max_distance : float
        Gating threshold. Associations with cost larger than this value are
        disregarded.
    tracks : List[track.Track]
        A list of predicted tracks at the current time step.
    detections : List[detection.Detection]
        A list of detections at the current time step.
    track_indices : List[int]
        List of track indices that maps rows in `cost_matrix` to tracks in
        `tracks` (see description above).
    detection_indices : List[int]
        List of detection indices that maps columns in `cost_matrix` to
        detections in `detections` (see description above).
 
    Returns
    -------
    (List[(int, int)], List[int], List[int])
        Returns a tuple with the following three entries:
        * A list of matched track and detection indices.
        * A list of unmatched track indices.
        * A list of unmatched detection indices.
 
    Nrgñh㈵øä>r)ÚnpÚarangeÚlenrÚ    enumerateÚappend)Údistance_metricÚ max_distanceÚtracksÚ
detectionsÚ track_indicesÚdetection_indicesÚ cost_matrixÚindicesÚmatchesÚunmatched_tracksÚunmatched_detectionsÚcolÚ detection_idxÚrowÚ    track_idx©rúRD:\project\07_tracking_Re-id\04_s_yolo_tracking\lib\deep_sort\linear_assignment.pyÚmin_cost_matching s2$
 
 rc sÂ|dkrtttˆƒƒƒ}|dkr0ttt|ƒƒƒ}|}g}x`t|ƒD]T‰t|ƒdkrTP‡‡fdd„|Dƒ}    t|    ƒdkrvqBt||ˆ||    |ƒ\}
} }||
7}qBWtt|ƒtdd„|Dƒƒƒ} || |fS)a<Run matching cascade.
 
    Parameters
    ----------
    distance_metric : Callable[List[Track], List[Detection], List[int], List[int]) -> ndarray
        The distance metric is given a list of tracks and detections as well as
        a list of N track indices and M detection indices. The metric should
        return the NxM dimensional cost matrix, where element (i, j) is the
        association cost between the i-th track in the given track indices and
        the j-th detection in the given detection indices.
    max_distance : float
        Gating threshold. Associations with cost larger than this value are
        disregarded.
    cascade_depth: int
        The cascade depth, should be se to the maximum track age.
    tracks : List[track.Track]
        A list of predicted tracks at the current time step.
    detections : List[detection.Detection]
        A list of detections at the current time step.
    track_indices : Optional[List[int]]
        List of track indices that maps rows in `cost_matrix` to tracks in
        `tracks` (see description above). Defaults to all tracks.
    detection_indices : Optional[List[int]]
        List of detection indices that maps columns in `cost_matrix` to
        detections in `detections` (see description above). Defaults to all
        detections.
 
    Returns
    -------
    (List[(int, int)], List[int], List[int])
        Returns a tuple with the following three entries:
        * A list of matched track and detection indices.
        * A list of unmatched track indices.
        * A list of unmatched detection indices.
 
    Nrcs"g|]}ˆ|jdˆkr|‘qS)r)Útime_since_update)Ú.0Úk)Úlevelr rrú
<listcomp>sz$matching_cascade.<locals>.<listcomp>css|]\}}|VqdS)Nr)rrÚ_rrrú    <genexpr>Œsz#matching_cascade.<locals>.<genexpr>)ÚlistÚrangerrÚset) r r Z cascade_depthr rrrrrZtrack_indices_lZ    matches_lr"rr)r r rÚmatching_cascadeNs$'   r'Fcst|rdnd}tj|}    tj‡fdd„|Dƒƒ}
x@t|ƒD]4\} } || } |j| j| j|
|ƒ}||| ||    kf<q8W|S)abInvalidate infeasible entries in cost matrix based on the state
    distributions obtained by Kalman filtering.
 
    Parameters
    ----------
    kf : The Kalman filter.
    cost_matrix : ndarray
        The NxM dimensional cost matrix, where N is the number of track indices
        and M is the number of detection indices, such that entry (i, j) is the
        association cost between `tracks[track_indices[i]]` and
        `detections[detection_indices[j]]`.
    tracks : List[track.Track]
        A list of predicted tracks at the current time step.
    detections : List[detection.Detection]
        A list of detections at the current time step.
    track_indices : List[int]
        List of track indices that maps rows in `cost_matrix` to tracks in
        `tracks` (see description above).
    detection_indices : List[int]
        List of detection indices that maps columns in `cost_matrix` to
        detections in `detections` (see description above).
    gated_cost : Optional[float]
        Entries in the cost matrix corresponding to infeasible associations are
        set this value. Defaults to a very large value.
    only_position : Optional[bool]
        If True, only the x, y position of the state distribution is considered
        during gating. Defaults to False.
 
    Returns
    -------
    ndarray
        Returns the modified cost matrix.
 
    éécsg|]}ˆ|jƒ‘qSr)Úto_xyah)rÚi)rrrr!¸sz$gate_cost_matrix.<locals>.<listcomp>)rÚ    chi2inv95rÚasarrayr    Úgating_distanceÚmeanÚ
covariance)Úkfrr rrrZ
gated_costÚ only_positionZ
gating_dimZgating_thresholdÚ measurementsrrÚtrackr.r)rrÚgate_cost_matrixs% 
r5)NN)NN) Ú
__future__rÚnumpyrZ sklearn.utils.linear_assignment_rÚrZ
INFTY_COSTrr'r5rrrrÚ<module>s   
C
B