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
3
€~Â]ã@sVddlmZddlZddlmZddlmZddlmZddlm    Z    Gdd    „d    ƒZ
dS)
é)Úabsolute_importNé)Ú kalman_filter)Úlinear_assignment)Ú iou_matching)ÚTrackc@s:eZdZdZddd„Zdd„Zd    d
„Zd d „Zd d„ZdS)ÚTrackeraà
    This is the multi-target tracker.
 
    Parameters
    ----------
    metric : nn_matching.NearestNeighborDistanceMetric
        A distance metric for measurement-to-track association.
    max_age : int
        Maximum number of missed misses before a track is deleted.
    n_init : int
        Number of consecutive detections before the track is confirmed. The
        track state is set to `Deleted` if a miss occurs within the first
        `n_init` frames.
 
    Attributes
    ----------
    metric : nn_matching.NearestNeighborDistanceMetric
        The distance metric used for measurement to track association.
    max_age : int
        Maximum number of missed misses before a track is deleted.
    n_init : int
        Number of frames that a track remains in initialization phase.
    kf : kalman_filter.KalmanFilter
        A Kalman filter to filter target trajectories in image space.
    tracks : List[Track]
        The list of active tracks at the current time step.
 
    çffffffæ?é,écCs2||_||_||_||_tjƒ|_g|_d|_dS)Nr)    ÚmetricÚmax_iou_distanceÚmax_ageÚn_initrZ KalmanFilterÚkfÚtracksÚ_next_id)Úselfr r rr©rúHD:\project\07_tracking_Re-id\04_s_yolo_tracking\lib\deep_sort\tracker.pyÚ__init__(s
zTracker.__init__cCs x|jD]}|j|jƒqWdS)z’Propagate track state distributions one time step forward.
 
        This function should be called once every time step, before `update`.
        N)rÚpredictr)rÚtrackrrrr3s zTracker.predictc
s|j|ƒ\}}}x(|D] \}}|j|j|j||ƒqWx|D]}|j|jƒq@Wx|D]}|j||ƒq\Wdd„|jDƒ|_dd„|jDƒ}gg}}    x@|jD]6‰ˆjƒs´q¦|ˆj7}|    ‡fdd„ˆjDƒ7}    gˆ_q¦W|jj    t
j |ƒt
j |    ƒ|ƒdS)zÕPerform measurement update and track management.
 
        Parameters
        ----------
        detections : List[deep_sort.detection.Detection]
            A list of detections at the current time step.
 
        cSsg|]}|jƒs|‘qSr)Z
is_deleted)Ú.0Útrrrú
<listcomp>Psz"Tracker.update.<locals>.<listcomp>cSsg|]}|jƒr|j‘qSr)Ú is_confirmedÚtrack_id)rrrrrrSscsg|]
}ˆj‘qSr)r)rÚ_)rrrrYsN) Ú_matchrÚupdaterZ mark_missedÚ_initiate_trackrÚfeaturesr Z partial_fitÚnpÚasarray)
rÚ
detectionsÚmatchesÚunmatched_tracksÚunmatched_detectionsZ    track_idxZ detection_idxZactive_targetsr"Útargetsr)rrr ;s& 
 
 
 
 
 
zTracker.updatec sÀ‡fdd„}dd„tˆjƒDƒ}dd„tˆjƒDƒ}tj|ˆjjˆjˆj||ƒ\}}}|‡fdd„|Dƒ}‡fdd„|Dƒ}tjtj    ˆj
ˆj|||ƒ\}    }
}||    } t t ||
ƒƒ} | | |fS)NcsXtj‡fdd„|Dƒƒ}tj‡fdd„|Dƒƒ}ˆjj||ƒ}tjˆj|ˆˆ||ƒ}|S)Ncsg|]}ˆ|j‘qSr)Úfeature)rÚi)Údetsrrrbsz8Tracker._match.<locals>.gated_metric.<locals>.<listcomp>csg|]}ˆ|j‘qSr)r)rr+)rrrrcs)r#Úarrayr ZdistancerZgate_cost_matrixr)rr,Z track_indicesZdetection_indicesr"r)Z cost_matrix)r)r,rrÚ gated_metricas z$Tracker._match.<locals>.gated_metriccSsg|]\}}|jƒr|‘qSr)r)rr+rrrrrmsz"Tracker._match.<locals>.<listcomp>cSsg|]\}}|jƒs|‘qSr)r)rr+rrrrroscs g|]}ˆj|jdkr|‘qS)r)rÚtime_since_update)rÚk)rrrr{scs g|]}ˆj|jdkr|‘qS)r)rr/)rr0)rrrr~s) Ú    enumeraterrZmatching_cascader Zmatching_thresholdrZmin_cost_matchingrZiou_costr ÚlistÚset) rr%r.Zconfirmed_tracksZunconfirmed_tracksZ    matches_aZunmatched_tracks_ar(Ziou_track_candidatesZ    matches_bZunmatched_tracks_br&r'r)rrr^s   zTracker._matchcCsH|jj|jƒƒ\}}|jjt|||j|j|j|j    ƒƒ|jd7_dS)Nr)
rZinitiateZto_xyahrÚappendrrrrr*)rZ    detectionÚmeanZ
covariancerrrr!‰s
 
zTracker._initiate_trackN)r    r
r )    Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrr rr!rrrrr
s 
#+r) Ú
__future__rÚnumpyr#ÚrrrrrrrrrrÚ<module>s