deepsort
sleap_nn.tracking.mot.deepsort
¶
DeepSORT (Wojke et al., 2017) and StrongSORT (Du et al., 2023).
DeepSORT adds appearance to SORT: a matching cascade over confirmed and lost tracks by time since update, scored by the minimum cosine distance to each track's gallery of re-ID vectors and gated by Kalman (Mahalanobis) distance, followed by a geometric stage for tentative and just-lost tracks. StrongSORT replaces the gallery with an EMA feature, the cascade with one global assignment, blends motion into the cost, and scales the measurement noise by detection confidence (NSA Kalman). Original implementations from the published algorithms.
DeepSORT, per frame (after every live track is predicted to this step):
- Detections scoring at or below
track_low_thresholdare ignored entirely: never matched, never start a track (the reference'smin_confidenceprefilter). - Matching cascade over the confirmed tracks (
CONFIRMEDandLOST; the reference keeps missed confirmed tracks in the cascade, a matchedLOSTtrack becomesCONFIRMEDagain with the same id). Levelsl = 1 .. track_buffertake the tracks withtime_since_update == l(l = 1: matched at the previous step), most recently updated first, each level assigned to the detections the earlier levels left over. The cost of a pair is1 - max cosinebetween the detection's vector and the track's gallery (the EMA while the gallery is empty; a missing vector costs 1), pairs outside the Kalman gate costINFEASIBLE_COST, and the cost cap is1 - gatewheregateis the minimum cosine (appearance_threshold;"auto": the calibratedgallery_cos_gate). - Geometric stage over the tentative tracks plus the cascade's unmatched
tracks with
time_since_update == 1: cost1 - similarity(the tracker's geometric similarity, IoU by default), cap1 - min_match_similarity(0.7 in IoU distance, as published; DeepSORT's only geometric threshold). - Lifecycle (base class, DeepSORT settings): spawned tracks start with one hit,
are confirmed after
min_hitsmatches, die at their first miss while tentative, and are removed after more thantrack_bufferunmatched steps.
StrongSORT changes step 2 into one global assignment over every confirmed track
with cost lambda * (1 - EMA cosine) + (1 - lambda) * d^2 where d^2 is
the raw squared Mahalanobis distance; gated pairs have their appearance cost set
to INFEASIBLE_COST before the blend, and the cost cap is (1 - gate) +
0.05 (the published allowance for the motion term; no allowance when
mc_lambda == 1). Its gate is the calibrated ema_cos_gate under
"auto", since the EMA cosine is the statistic it thresholds. Its Kalman
filter is NSA (params.nsa): the base update passes the detection score as the
confidence that scales the measurement noise.
Adaptations to animal pose/mask detections (documented deviations):
- The Kalman gate uses the box CENTER only (2 dof, chi-square 0.95 = 5.9915): the aspect ratio and height of a keypoint/mask box change with body rotation and node dropout, which the 4-dof gate would reject.
- The appearance memory is quality-gated (see
:mod:
~sleap_nn.tracking.mot.appearance), always seeded with the spawn vector, and scored on its EMA while the gallery is empty. - A detection "has a vector" exactly when
FrameDetections.has_embeddingsays so (finite, non-zero, of the video's dimension): one rule for the appearance stage, the memories and the "no vectors" decision. A vector that fails it (e.g. all NaN from an embedder that failed on a blank crop) counts as missing, andprepare()warns with the count. - When appearance cannot decide -- the detections carry no usable vectors, or
appearance_threshold="auto"and the video's calibration says the embedding does not separate the animals (or there was noprepare()) -- the cascade is skipped and the geometric stage also takes every confirmed track withtime_since_update <= track_buffer(logged once at INFO). The tracker then degrades to geometric matching instead of losing every track at its first miss. The same holds per track for a confirmed track whose memory holds no vector (none of its detections carried one). - These trackers do not refuse vector-less input themselves (library loops and
the generic tracker contract keep working);
requires_vectorsis what letsapply_trackingand the CLI reject such input up front.
Classes:
| Name | Description |
|---|---|
DeepSORTTracker |
DeepSORT tracker (see :mod: |
StrongSORTTracker |
StrongSORT tracker (see :mod: |
DeepSORTTracker
¶
Bases: BaseMOTTracker
DeepSORT tracker (see :mod:sleap_nn.tracking.mot.deepsort).
Attributes:
| Name | Type | Description |
|---|---|---|
appearance_statistic |
str
|
Appearance statistic thresholded by the
appearance stage ( |
Source code in sleap_nn/tracking/mot/deepsort.py
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
StrongSORTTracker
¶
Bases: DeepSORTTracker
StrongSORT tracker (see :mod:sleap_nn.tracking.mot.deepsort).